2012-05-10 16:32:25 +02:00
|
|
|
package com.Acrobot.ChestShop.Utils;
|
|
|
|
|
|
|
|
import com.Acrobot.ChestShop.Permission;
|
2012-11-23 21:03:02 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2012-05-10 16:32:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-11-23 21:03:02 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class uName {
|
2012-11-23 21:03:02 +01:00
|
|
|
public static YamlConfiguration config;
|
|
|
|
public static File file;
|
2012-05-10 16:32:25 +02:00
|
|
|
|
|
|
|
public static String getName(String shortName) {
|
|
|
|
return config.getString(shortName, shortName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveName(String name) {
|
|
|
|
if (name.length() <= 15) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.set(stripName(name), name);
|
2012-11-23 21:03:02 +01:00
|
|
|
reload();
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String stripName(String name) {
|
|
|
|
return (name.length() > 15 ? name.substring(0, 15) : name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String shortenName(Player player) {
|
|
|
|
return stripName(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean canUseName(Player player, String name) {
|
|
|
|
return shortenName(player).equals(name) || Permission.otherName(player, name);
|
|
|
|
}
|
2012-11-23 21:03:02 +01:00
|
|
|
|
|
|
|
public static void load() {
|
|
|
|
config = YamlConfiguration.loadConfiguration(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void reload() {
|
|
|
|
try {
|
|
|
|
config.save(file);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
load();
|
|
|
|
}
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|