Delete src/main/java/pers/xanadu/enderdragon/manager directory
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
package pers.xanadu.enderdragon.manager;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import pers.xanadu.enderdragon.config.Lang;
|
||||
import pers.xanadu.enderdragon.reward.Reward;
|
||||
import pers.xanadu.enderdragon.reward.Chance;
|
||||
import pers.xanadu.enderdragon.util.MyDragon;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static pers.xanadu.enderdragon.EnderDragon.*;
|
||||
|
||||
public class RewardManager {
|
||||
|
||||
public static void reload(){
|
||||
for(MyDragon dragon : DragonManager.dragons){
|
||||
dragon.datum.clear();
|
||||
File file = getRewardFile(dragon.unique_name);
|
||||
if(file == null) return;
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
String path = "list";
|
||||
List<String> list = data.getStringList(path);
|
||||
// if list == null ?
|
||||
for(String str : list){
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
try{
|
||||
yml.loadFromString(str);
|
||||
Reward reward = ItemManager.readAsReward(yml);
|
||||
dragon.datum.add(reward);
|
||||
}catch (InvalidConfigurationException e){
|
||||
Lang.error(Lang.plugin_item_read_error + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void addItem(String key,Reward reward){
|
||||
addItem(key,reward.getItem(),reward.getChance());
|
||||
}
|
||||
public static void addItem(String key, ItemStack item, Chance chance){
|
||||
MyDragon dragon = DragonManager.mp.get(key);
|
||||
if(dragon == null) return;
|
||||
File file = getRewardFile(dragon.unique_name);
|
||||
if(file == null) return;
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
String path = "list";
|
||||
List<String> list = data.getStringList(path);
|
||||
Reward reward = new Reward(item,chance);
|
||||
list.add(reward.toString());
|
||||
data.set(path,list);
|
||||
try {
|
||||
data.save(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
dragon.datum.add(reward);
|
||||
}
|
||||
public static void clearItem(String key){
|
||||
MyDragon dragon = DragonManager.mp.get(key);
|
||||
if(dragon == null) return;
|
||||
File file = getRewardFile(dragon.unique_name);
|
||||
if(file == null) return;
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
String path = "list";
|
||||
data.set(path,"");
|
||||
try {
|
||||
data.save(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
dragon.datum.clear();
|
||||
}
|
||||
public static boolean removeItem(String key,int idx){
|
||||
MyDragon dragon = DragonManager.mp.get(key);
|
||||
if(dragon == null) return false;
|
||||
File file = getRewardFile(dragon.unique_name);
|
||||
if(file == null) return false;
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
String path = "list";
|
||||
List<String> list = data.getStringList(path);
|
||||
try{
|
||||
list.remove(idx);
|
||||
data.set(path,list);
|
||||
data.save(file);
|
||||
dragon.datum.remove(idx);
|
||||
return true;
|
||||
}catch (IndexOutOfBoundsException e){
|
||||
Lang.error("Index out of bound!");
|
||||
}catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static File getRewardFile(String key){
|
||||
String file_path = "reward/" + key + ".yml";
|
||||
File file = new File(plugin.getDataFolder(),file_path);
|
||||
if(!file.exists()) {
|
||||
try{
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
yml.set("version","2.1.0");
|
||||
yml.set("list","");
|
||||
yml.save(file);
|
||||
}catch (IOException e){
|
||||
Lang.error("Not Found "+file_path+" ,skipped it.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new File(plugin.getDataFolder(),file_path);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user