-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Grafe <[email protected]>
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: ManagerXL | ||
version: 0.1 | ||
main: com.dre.managerxl.P | ||
authors: [Frank Baumann, Tobias Schmitz, Joscha Schmitz] | ||
softdepend: [Vault] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.dre.managerxl; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
|
||
public class LanguageReader { | ||
private Map<String,String> entries = new TreeMap<String,String>(); | ||
private Map<String,String> defaults = new TreeMap<String,String>(); | ||
|
||
private File file; | ||
private boolean changed; | ||
|
||
public LanguageReader(File file){ | ||
this.setDefaults(); | ||
|
||
/* Load */ | ||
this.file = file; | ||
|
||
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file); | ||
|
||
Set<String> keySet = configFile.getKeys(false); | ||
for(String key:keySet){ | ||
entries.put(key, configFile.getString(key)); | ||
} | ||
|
||
/* Check */ | ||
this.check(); | ||
} | ||
|
||
private void setDefaults(){ | ||
/* Errors */ | ||
defaults.put("Error_NoPermissions","&4Du hast keine Erlaubnis dies zu tun!"); | ||
} | ||
|
||
private void check(){ | ||
for(String defaultEntry:defaults.keySet()){ | ||
if(!entries.containsKey(defaultEntry)){ | ||
entries.put(defaultEntry,defaults.get(defaultEntry)); | ||
changed = true; | ||
} | ||
} | ||
} | ||
|
||
public void save(){ | ||
if(changed){ | ||
/* Copy old File */ | ||
File source = new File(file.getPath()); | ||
String filePath = file.getPath(); | ||
File temp = new File(filePath.substring(0,filePath.length()-4)+"_old.yml"); | ||
|
||
if(temp.exists()) | ||
temp.delete(); | ||
|
||
source.renameTo(temp); | ||
|
||
/* Save */ | ||
FileConfiguration configFile = new YamlConfiguration(); | ||
|
||
for(String key:entries.keySet()){ | ||
configFile.set(key, entries.get(key)); | ||
} | ||
|
||
try { | ||
configFile.save(file); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public String get(String key, String... args){ | ||
String entry = entries.get(key); | ||
|
||
if(entry!=null){ | ||
int i=0; | ||
for(String arg:args){ | ||
i++; | ||
entry = entry.replace("&v"+i, arg); | ||
} | ||
} | ||
|
||
return entry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.dre.managerxl; | ||
|
||
import java.io.File; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class P extends JavaPlugin{ | ||
public static P p; | ||
|
||
|
||
|
||
//Language Reader | ||
private LanguageReader languageReader; | ||
public LanguageReader getLanguageReader(){ | ||
return languageReader; | ||
} | ||
|
||
|
||
@Override | ||
public void onEnable(){ | ||
p = this; | ||
|
||
//Load LanguageReader | ||
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/default.yml")); | ||
} | ||
|
||
@Override | ||
public void onDisable(){ | ||
|
||
} | ||
} |