Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Grafe <[email protected]>
  • Loading branch information
Grafe committed Apr 1, 2013
1 parent c140208 commit c64775b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin.yml
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]
90 changes: 90 additions & 0 deletions src/com/dre/managerxl/LanguageReader.java
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;
}
}
31 changes: 31 additions & 0 deletions src/com/dre/managerxl/P.java
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(){

}
}

0 comments on commit c64775b

Please sign in to comment.