Added new config system

This commit is contained in:
Grafe 2013-01-29 00:10:15 +01:00
parent e3936cd282
commit bf34312f30
13 changed files with 296 additions and 203 deletions

View File

@ -3,6 +3,7 @@ package com.dre.dungeonsxl;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -16,23 +17,32 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class DConfig { public class DConfig {
public File file; public static DConfig mainConfig = new DConfig();
private File file;
private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>(); private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>();
public Map<Integer,String> msgs = new HashMap<Integer,String>(); private Map<Integer,String> msgs = new HashMap<Integer,String>();
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
public CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>(); private boolean isLobbyDisabled = false;
public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>(); private int timeToNextPlay = 0;
private int timeToNextLoot = 0;
public boolean isLobbyDisabled = false; private int timeUntilKickOfflinePlayer = -1;
public int timeToNextPlay = 0;
public int timeToNextLoot = 0;
public int timeUntilKickOfflinePlayer = -1;
//Spout //Spout
public boolean spoutCraftOnly = false; private boolean spoutCraftOnly = false;
public String spoutTexturepackURL; private String spoutTexturepackURL;
//MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>();
public DConfig(){
}
public DConfig(File file){ public DConfig(File file){
this.file=file; this.file=file;
@ -143,29 +153,45 @@ public class DConfig {
/* Lobby */ /* Lobby */
if(configFile.contains("isLobbyDisabled")){ if(configFile.contains("isLobbyDisabled")){
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled"); isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
} else {
isLobbyDisabled = mainConfig.isLobbyDisabled;
} }
/* Times */ /* Times */
if(configFile.contains("timeToNextPlay")){ if(configFile.contains("timeToNextPlay")){
timeToNextPlay = configFile.getInt("timeToNextPlay"); timeToNextPlay = configFile.getInt("timeToNextPlay");
} else {
timeToNextPlay = mainConfig.timeToNextPlay;
} }
if(configFile.contains("timeToNextLoot")){ if(configFile.contains("timeToNextLoot")){
timeToNextLoot = configFile.getInt("timeToNextLoot"); timeToNextLoot = configFile.getInt("timeToNextLoot");
} else {
timeToNextLoot = mainConfig.timeToNextLoot;
} }
if(configFile.contains("timeUntilKickOfflinePlayer")){ if(configFile.contains("timeUntilKickOfflinePlayer")){
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer"); timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else {
timeUntilKickOfflinePlayer = mainConfig.timeUntilKickOfflinePlayer;
} }
/* Spout */ /* Spout */
if(configFile.contains("spout.spoutCraftOnly")){ if(configFile.contains("spout.spoutCraftOnly")){
spoutCraftOnly = configFile.getBoolean("spout.spoutCraftOnly"); spoutCraftOnly = configFile.getBoolean("spout.spoutCraftOnly");
} else {
spoutCraftOnly = mainConfig.spoutCraftOnly;
} }
if(configFile.contains("spout.spoutTexturepackURL")){ if(configFile.contains("spout.spoutTexturepackURL")){
spoutTexturepackURL = configFile.getString("spout.spoutTexturepackURL"); spoutTexturepackURL = configFile.getString("spout.spoutTexturepackURL");
} else {
spoutTexturepackURL = mainConfig.spoutTexturepackURL;
} }
/* Mobtypes */
configSetionMessages = configFile.getConfigurationSection("mobTypes");
this.mobTypes = DMobType.load(configSetionMessages);
} }
public void save(){ public void save(){
@ -197,13 +223,25 @@ public class DConfig {
} }
} }
//Get //Getters and Setters
public CopyOnWriteArrayList<DClass> getClasses(){ public CopyOnWriteArrayList<DClass> getClasses(){
return dClasses; if(this.dClasses != null){
if(!this.dClasses.isEmpty()){
return this.dClasses;
}
}
return mainConfig.dClasses;
} }
public DClass getClass(String name){ public DClass getClass(String name){
for(DClass dClass:dClasses){ for(DClass dClass:this.dClasses){
if(dClass.name.equals(name)){
return dClass;
}
}
for(DClass dClass:mainConfig.dClasses){
if(dClass.name.equals(name)){ if(dClass.name.equals(name)){
return dClass; return dClass;
} }
@ -211,7 +249,69 @@ public class DConfig {
return null; return null;
} }
public String getMsg(int id){ public String getMsg(int id, boolean returnMainConfig){
return this.msgs.get(id); String msg = this.msgs.get(id);
if(msg != null){
return this.msgs.get(id);
}
if(returnMainConfig){
return mainConfig.msgs.get(id);
}
return null;
}
public void setMsg(String msg, int id) {
this.msgs.put(id, msg);
}
public CopyOnWriteArrayList<String> getInvitedPlayers() {
CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>();
tmpInvitedPlayers.addAll(this.invitedPlayers);
tmpInvitedPlayers.addAll(mainConfig.invitedPlayers);
return tmpInvitedPlayers;
}
public void addInvitedPlayer(String player) {
this.invitedPlayers.add(player);
}
public void removeInvitedPlayers(String player) {
this.invitedPlayers.remove(player);
}
public CopyOnWriteArrayList<Material> getSecureObjects() {
CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>();
tmpSecureObjects.addAll(this.secureObjects);
tmpSecureObjects.addAll(mainConfig.secureObjects);
return tmpSecureObjects;
}
public boolean isLobbyDisabled() {
return isLobbyDisabled;
}
public int getTimeToNextPlay() {
return timeToNextPlay;
}
public int getTimeToNextLoot() {
return timeToNextLoot;
}
public int getTimeUntilKickOfflinePlayer() {
return timeUntilKickOfflinePlayer;
}
public boolean isSpoutCraftOnly() {
return spoutCraftOnly;
}
public String getSpoutTexturepackURL() {
return spoutTexturepackURL;
}
public Set<DMobType> getMobTypes() {
return mobTypes;
} }
} }

View File

@ -246,7 +246,7 @@ public class DGSign {
if(file!=null){ if(file!=null){
DConfig confReader=new DConfig(file); DConfig confReader=new DConfig(file);
if(confReader!=null){ if(confReader!=null){
P.p.msg(player, P.p.language.get("Error_Cooldown",""+confReader.timeToNextPlay)); P.p.msg(player, P.p.language.get("Error_Cooldown",""+confReader.getTimeToNextPlay()));
} }
} }
} }

View File

@ -1,6 +1,5 @@
package com.dre.dungeonsxl; package com.dre.dungeonsxl;
import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -9,8 +8,6 @@ import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -25,8 +22,6 @@ import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
public class DMobType { public class DMobType {
private static Set<DMobType> mobTypes = new HashSet<DMobType>();
private String name; private String name;
private EntityType type; private EntityType type;
@ -50,8 +45,6 @@ public class DMobType {
/* Methods */ /* Methods */
public DMobType(String name, EntityType type){ public DMobType(String name, EntityType type){
mobTypes.add(this);
this.name=name; this.name=name;
this.type=type; this.type=type;
} }
@ -107,135 +100,139 @@ public class DMobType {
} }
//Load Config //Load Config
public static void load(File file){ public static Set<DMobType> load(ConfigurationSection configFile){
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file); Set<DMobType> set = new HashSet<DMobType>();
if(configFile!=null){
//Read Mobs //Read Mobs
for(String mobName:configFile.getKeys(false)){ for(String mobName:configFile.getKeys(false)){
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type")); EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
if (type!=null) { if (type!=null) {
DMobType mobType=new DMobType(mobName, type); DMobType mobType=new DMobType(mobName, type);
set.add(mobType);
//Load MaxHealth
if(configFile.contains(mobName+".MaxHealth")){ //Load MaxHealth
mobType.maxHealth=configFile.getInt(mobName+".MaxHealth"); if(configFile.contains(mobName+".MaxHealth")){
} mobType.maxHealth=configFile.getInt(mobName+".MaxHealth");
}
//Load Items
if(configFile.contains(mobName+".ItemHelmet")){ //Load Items
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName+".ItemHelmet"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem(); if(configFile.contains(mobName+".ItemHelmet")){
} mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName+".ItemHelmet"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
}
if(configFile.contains(mobName+".ItemChestplate")){
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName+".ItemChestplate"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem(); if(configFile.contains(mobName+".ItemChestplate")){
} mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName+".ItemChestplate"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
}
if(configFile.contains(mobName+".ItemBoots")){
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName+".ItemBoots"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem(); if(configFile.contains(mobName+".ItemBoots")){
} mobType.ItemBoots = new ItemStack(configFile.getInt(mobName+".ItemBoots"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
}
if(configFile.contains(mobName+".ItemLeggings")){
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName+".ItemLeggings"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem(); if(configFile.contains(mobName+".ItemLeggings")){
} mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName+".ItemLeggings"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
}
if(configFile.contains(mobName+".ItemHand")){
mobType.ItemHand = new ItemStack(configFile.getInt(mobName+".ItemHand"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem(); if(configFile.contains(mobName+".ItemHand")){
} mobType.ItemHand = new ItemStack(configFile.getInt(mobName+".ItemHand"));//CraftItemStack.asNMSCopy(new ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
}
//Load different Mob options
if(configFile.contains(mobName+".isWitherSkeleton")){ //Load different Mob options
mobType.isWitherSkeleton = configFile.getBoolean(mobName+".isWitherSkeleton"); if(configFile.contains(mobName+".isWitherSkeleton")){
} mobType.isWitherSkeleton = configFile.getBoolean(mobName+".isWitherSkeleton");
}
if(configFile.contains(mobName+".ocelotType")){
mobType.ocelotType = configFile.getString(mobName+".ocelotType"); if(configFile.contains(mobName+".ocelotType")){
} mobType.ocelotType = configFile.getString(mobName+".ocelotType");
}
//Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName+".drops"); //Drops
if(configSetion!=null){ ConfigurationSection configSetion = configFile.getConfigurationSection(mobName+".drops");
Set<String> list=configSetion.getKeys(false); if(configSetion!=null){
for(String dropPath:list){ Set<String> list=configSetion.getKeys(false);
ItemStack item = null; for(String dropPath:list){
ItemMeta itemMeta = null; ItemStack item = null;
int chance = 100; ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath+".id")); /* Item Stack */
int amount = 1; Material mat = Material.getMaterial(configSetion.getInt(dropPath+".id"));
short data = 0; int amount = 1;
short data = 0;
if(configSetion.contains(dropPath+".amount")){
amount = configSetion.getInt(dropPath+".amount"); if(configSetion.contains(dropPath+".amount")){
} amount = configSetion.getInt(dropPath+".amount");
if(configSetion.contains(dropPath+".data")){ }
data = Short.parseShort(configSetion.getString(dropPath+".data")); if(configSetion.contains(dropPath+".data")){
} data = Short.parseShort(configSetion.getString(dropPath+".data"));
}
item = new ItemStack(mat,amount,data);
itemMeta = item.getItemMeta(); item = new ItemStack(mat,amount,data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath+".enchantments")) { /* Enchantments */
for(String enchantment:configSetion.getStringList(dropPath+".enchantments")){ if (configSetion.contains(dropPath+".enchantments")) {
String[] splittedEnchantment = enchantment.split(" "); for(String enchantment:configSetion.getStringList(dropPath+".enchantments")){
if(Enchantment.getByName(splittedEnchantment[0].toUpperCase())!=null){ String[] splittedEnchantment = enchantment.split(" ");
if (splittedEnchantment.length>1) { if(Enchantment.getByName(splittedEnchantment[0].toUpperCase())!=null){
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), P.p.parseInt(splittedEnchantment[1]), true); if (splittedEnchantment.length>1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), P.p.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else { } else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true); P.p.log(P.p.language.get("Log_Error_MobEnchantment",splittedEnchantment[0]));
} }
} else {
P.p.log(P.p.language.get("Log_Error_MobEnchantment",splittedEnchantment[0]));
} }
} }
/* Item Name */
if (configSetion.contains(dropPath+".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath+".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath+".lore")) {
String[] lore=configSetion.getString(dropPath+".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath+".chance")) {
chance = configSetion.getInt(dropPath+".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.drops.put(item, chance);
} }
/* Item Name */
if (configSetion.contains(dropPath+".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath+".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath+".lore")) {
String[] lore=configSetion.getString(dropPath+".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath+".chance")) {
chance = configSetion.getInt(dropPath+".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.drops.put(item, chance);
} }
//Spout Skin
if(configFile.contains(mobName+".spoutSkinURL")){
mobType.spoutSkinURL = configFile.getString(mobName+".spoutSkinURL");
}
} else {
P.p.log(P.p.language.get("Log_Error_MobType",configFile.getString(mobName+".Type")));
} }
//Spout Skin
if(configFile.contains(mobName+".spoutSkinURL")){
mobType.spoutSkinURL = configFile.getString(mobName+".spoutSkinURL");
}
} else {
P.p.log(P.p.language.get("Log_Error_MobType",configFile.getString(mobName+".Type")));
} }
} }
return set;
} }
//Clear
public static void clear(){
mobTypes.clear();
}
//Get //Get
public static DMobType get(String name){ public static DMobType get(String name, Set<DMobType> mobTypes){
for(DMobType mobType:DMobType.mobTypes){ for(DMobType mobType:mobTypes){
if(mobType.name.equalsIgnoreCase(name)){ if(mobType.name.equalsIgnoreCase(name)){
return mobType; return mobType;
} }
} }
for(DMobType mobType:P.p.mainConfig.defaultDungeon.getMobTypes()){
if(mobType.name.equalsIgnoreCase(name)){
return mobType;
}
}
return null; return null;
} }
} }

View File

@ -81,7 +81,7 @@ public class DPlayer {
if(isEditing) this.player.setGameMode(GameMode.CREATIVE); else this.player.setGameMode(GameMode.SURVIVAL); if(isEditing) this.player.setGameMode(GameMode.CREATIVE); else this.player.setGameMode(GameMode.SURVIVAL);
if(!isEditing){ if(!isEditing){
if(GameWorld.get(world).config.isLobbyDisabled){ if(GameWorld.get(world).config.isLobbyDisabled()){
this.ready(); this.ready();
} }
} }
@ -90,11 +90,11 @@ public class DPlayer {
if(!isEditing){ if(!isEditing){
if(p.isSpoutEnabled){ if(p.isSpoutEnabled){
GameWorld gworld = GameWorld.get(world); GameWorld gworld = GameWorld.get(world);
if(gworld.config.spoutTexturepackURL!=null){ if(gworld.config.getSpoutTexturepackURL()!=null){
SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName()); SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName());
if(sPlayer!=null){ if(sPlayer!=null){
sPlayer.sendNotification(ChatColor.GOLD+"DungeonsXL",ChatColor.RED+"Download texturepack!", Material.FIREBALL); sPlayer.sendNotification(ChatColor.GOLD+"DungeonsXL",ChatColor.RED+"Download texturepack!", Material.FIREBALL);
sPlayer.setTexturePack(gworld.config.spoutTexturepackURL); sPlayer.setTexturePack(gworld.config.getSpoutTexturepackURL());
} }
} }
} }

View File

@ -98,7 +98,7 @@ public class DPortal {
/* Check Spout */ /* Check Spout */
boolean spoutCheck = true; boolean spoutCheck = true;
if(P.p.isSpoutEnabled){ if(P.p.isSpoutEnabled){
if(dgroup.getGworld().config.spoutCraftOnly){ if(dgroup.getGworld().config.isSpoutCraftOnly()){
if(!Spout.getServer().getPlayer(player.getName()).isSpoutCraftEnabled()){ if(!Spout.getServer().getPlayer(player.getName()).isSpoutCraftEnabled()){
spoutCheck = false; spoutCheck = false;
} }

View File

@ -222,7 +222,7 @@ public class EditWorld {
}else{ }else{
if(exist(eworldname)){ if(exist(eworldname)){
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml")); DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
config.invitedPlayers.add(player.toLowerCase()); config.addInvitedPlayer(player.toLowerCase());
config.save(); config.save();
return true; return true;
} }
@ -241,7 +241,7 @@ public class EditWorld {
}else{ }else{
if(exist(eworldname)){ if(exist(eworldname)){
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml")); DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
config.invitedPlayers.remove(player.toLowerCase()); config.removeInvitedPlayers(player.toLowerCase());
config.save(); config.save();
return true; return true;
} }
@ -259,7 +259,7 @@ public class EditWorld {
}else{ }else{
if(exist(eworldname)){ if(exist(eworldname)){
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml")); DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
return config.invitedPlayers.contains(player.toLowerCase()); return config.getInvitedPlayers().contains(player.toLowerCase());
} }
} }

View File

@ -57,6 +57,7 @@ public class MainConfig {
ConfigurationSection configSetion = configFile.getConfigurationSection("default"); ConfigurationSection configSetion = configFile.getConfigurationSection("default");
if(configSetion!=null){ if(configSetion!=null){
defaultDungeon = new DConfig(configSetion); defaultDungeon = new DConfig(configSetion);
DConfig.mainConfig = defaultDungeon;
} }
} }

View File

@ -65,11 +65,14 @@ public class P extends JavaPlugin{
//Commands //Commands
getCommand("dungeonsxl").setExecutor(new CommandListener()); getCommand("dungeonsxl").setExecutor(new CommandListener());
//Load Language
language = new LanguageReader(new File(p.getDataFolder(), "languages/en.yml"));
//Load Config //Load Config
mainConfig=new MainConfig(new File(p.getDataFolder(), "config.yml")); mainConfig=new MainConfig(new File(p.getDataFolder(), "config.yml"));
//Load Language //Load Language 2
language = new LanguageReader(new File(p.getDataFolder(), "languages/"+mainConfig.language+".yml")); language = new LanguageReader(new File(p.getDataFolder(), "languages/"+mainConfig.language+".yml"));
//Init Commands //Init Commands
@ -130,7 +133,6 @@ public class P extends JavaPlugin{
DGroup.dgroups.clear(); DGroup.dgroups.clear();
DGSign.dgsigns.clear(); DGSign.dgsigns.clear();
DLootInventory.LootInventorys.clear(); DLootInventory.LootInventorys.clear();
DMobType.clear();
DPlayer.players.clear(); DPlayer.players.clear();
DPortal.portals.clear(); DPortal.portals.clear();
LeaveSign.lsigns.clear(); LeaveSign.lsigns.clear();
@ -248,9 +250,6 @@ public class P extends JavaPlugin{
DGSign.load(configFile); DGSign.load(configFile);
LeaveSign.load(configFile); LeaveSign.load(configFile);
//Load mob types
DMobType.load(new File(p.getDataFolder(), "mobs.yml"));
//Load saved players //Load saved players
DSavePlayer.load(); DSavePlayer.load();
} }

View File

@ -31,7 +31,7 @@ public class CMDMsg extends DCommand{
DConfig confreader = new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworld.dungeonname, "config.yml")); DConfig confreader = new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworld.dungeonname, "config.yml"));
if(args.length==2){ if(args.length==2){
String msg=confreader.msgs.get(id); String msg=confreader.getMsg(id, true);
if(msg!=null){ if(msg!=null){
p.msg(player, ChatColor.WHITE+msg); p.msg(player, ChatColor.WHITE+msg);
}else{ }else{
@ -51,14 +51,14 @@ public class CMDMsg extends DCommand{
String[] splitMsg=msg.split("\""); String[] splitMsg=msg.split("\"");
if(splitMsg.length>1){ if(splitMsg.length>1){
msg=splitMsg[1]; msg=splitMsg[1];
String old=confreader.msgs.get(id); String old=confreader.getMsg(id, false);
if(old==null){ if(old==null){
p.msg(player, p.language.get("Cmd_Msg_Added",""+id)); p.msg(player, p.language.get("Cmd_Msg_Added",""+id));
}else{ }else{
p.msg(player, p.language.get("Cmd_Msg_Updated",""+id)); p.msg(player, p.language.get("Cmd_Msg_Updated",""+id));
} }
confreader.msgs.put(id, msg); confreader.setMsg(msg, id);
confreader.save(); confreader.save();
}else{ }else{
p.msg(player, p.language.get("Error_MsgFormat")); p.msg(player, p.language.get("Error_MsgFormat"));

View File

@ -4,7 +4,6 @@ package com.dre.dungeonsxl.commands;
import java.io.File; import java.io.File;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.dre.dungeonsxl.DMobType;
import com.dre.dungeonsxl.LanguageReader; import com.dre.dungeonsxl.LanguageReader;
import com.dre.dungeonsxl.MainConfig; import com.dre.dungeonsxl.MainConfig;
@ -33,10 +32,6 @@ public class CMDReload extends DCommand{
//Load Language //Load Language
p.language = new LanguageReader(new File(p.getDataFolder(), "languages/"+p.mainConfig.language+".yml")); p.language = new LanguageReader(new File(p.getDataFolder(), "languages/"+p.mainConfig.language+".yml"));
//Mobtype
DMobType.clear();
DMobType.load(new File(p.getDataFolder(), "mobs.yml"));
p.msg(sender, p.language.get("Cmd_Reload_Done")); p.msg(sender, p.language.get("Cmd_Reload_Done"));
} }
} }

View File

@ -108,7 +108,7 @@ public class GameWorld {
sign.setLine(3, ChatColor.DARK_BLUE+"############"); sign.setLine(3, ChatColor.DARK_BLUE+"############");
sign.update(); sign.update();
} else if (lines[1].equalsIgnoreCase("classes")){ } else if (lines[1].equalsIgnoreCase("classes")){
if(!config.isLobbyDisabled){ if(!config.isLobbyDisabled()){
int[] direction=DGSign.getDirection(block.getData()); int[] direction=DGSign.getDirection(block.getData());
int directionX=direction[0]; int directionX=direction[0];
int directionZ=direction[1]; int directionZ=direction[1];
@ -188,7 +188,7 @@ public class GameWorld {
} }
if(lines[1].equalsIgnoreCase("msg")){ if(lines[1].equalsIgnoreCase("msg")){
if(lines[2]!=""&&lines[3]!=""){ if(lines[2]!=""&&lines[3]!=""){
String msg = config.getMsg(p.parseInt(lines[2])); String msg = config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){ if(msg!=null){
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),false)); messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),false));
block.setTypeId(0); block.setTypeId(0);
@ -197,7 +197,7 @@ public class GameWorld {
} }
if(lines[1].equalsIgnoreCase("soundmsg")){ if(lines[1].equalsIgnoreCase("soundmsg")){
if(lines[2]!=""&&lines[3]!=""){ if(lines[2]!=""&&lines[3]!=""){
String msg = config.getMsg(p.parseInt(lines[2])); String msg = config.getMsg(p.parseInt(lines[2]),true);
if(msg!=null){ if(msg!=null){
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),true)); messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),true));
block.setTypeId(0); block.setTypeId(0);
@ -296,7 +296,7 @@ public class GameWorld {
if(dungeonFolder.isDirectory()){ if(dungeonFolder.isDirectory()){
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+dungeon, "config.yml")); DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+dungeon, "config.yml"));
if(config.timeToNextPlay!=0){ if(config.getTimeToNextPlay()!=0){
//read PlayerConfig //read PlayerConfig
File file=new File(p.getDataFolder()+"/dungeons/"+dungeon, "players.yml"); File file=new File(p.getDataFolder()+"/dungeons/"+dungeon, "players.yml");
@ -312,7 +312,7 @@ public class GameWorld {
if(playerConfig.contains(player.getName())){ if(playerConfig.contains(player.getName())){
Long time=playerConfig.getLong(player.getName()); Long time=playerConfig.getLong(player.getName());
if(time+(config.timeToNextPlay*1000*60*60)>System.currentTimeMillis()){ if(time+(config.getTimeToNextPlay()*1000*60*60)>System.currentTimeMillis()){
return false; return false;
} }
} }
@ -347,7 +347,7 @@ public class GameWorld {
gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml")); gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml"));
//Secure Objects //Secure Objects
gworld.secureObjects=gworld.config.secureObjects; gworld.secureObjects=gworld.config.getSecureObjects();
//World //World
p.copyDirectory(file,new File("DXL_Game_"+gworld.id)); p.copyDirectory(file,new File("DXL_Game_"+gworld.id));

View File

@ -39,52 +39,53 @@ public class MobSpawner {
public void update(){ public void update(){
World world=this.block.getWorld(); World world=this.block.getWorld();
GameWorld gworld = GameWorld.get(world);
for(Player player:world.getPlayers()){ if(gworld != null){
if(player.getWorld()==world){ for(Player player:world.getPlayers()){
if(player.getLocation().distance(this.block.getLocation())<this.radius){ if(player.getWorld()==world){
if(this.interval<=0){ if(player.getLocation().distance(this.block.getLocation())<this.radius){
if(this.interval<=0){
//Check normal mobs
if(EntityType.fromName(this.mob)!=null){ //Check normal mobs
if(EntityType.fromName(this.mob).isAlive()){ if(EntityType.fromName(this.mob)!=null){
LivingEntity entity=(LivingEntity)world.spawnEntity(this.block.getLocation(), EntityType.fromName(this.mob)); if(EntityType.fromName(this.mob).isAlive()){
LivingEntity entity=(LivingEntity)world.spawnEntity(this.block.getLocation(), EntityType.fromName(this.mob));
//Add Bow to normal Skeletons
if(entity.getType() == EntityType.SKELETON){ //Add Bow to normal Skeletons
Skeleton skeleton = (Skeleton) entity; if(entity.getType() == EntityType.SKELETON){
if(skeleton.getSkeletonType()==SkeletonType.NORMAL){ Skeleton skeleton = (Skeleton) entity;
skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW)); if(skeleton.getSkeletonType()==SkeletonType.NORMAL){
skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW));
}
} }
new DMob(entity,this.live,GameWorld.get(world),null);
} }
new DMob(entity,this.live,GameWorld.get(world),null);
} }
}
//Check custom mobs
//Check custom mobs DMobType mobType = DMobType.get(this.mob, gworld.config.getMobTypes());
DMobType mobType = DMobType.get(this.mob);
if(mobType!=null){
if(mobType!=null){ mobType.spawn(GameWorld.get(world), this.block.getLocation());
mobType.spawn(GameWorld.get(world), this.block.getLocation());
}
//Set the amount
if(amount!=-1){
if(amount>1){
amount--;
}else{
mobspawners.remove(this);
} }
//Set the amount
if(amount!=-1){
if(amount>1){
amount--;
}else{
mobspawners.remove(this);
}
}
this.interval=this.maxinterval;
} }
this.interval=this.maxinterval; this.interval--;
return;
} }
this.interval--;
return;
} }
} }
} }
} }
//Static //Static

View File

@ -194,7 +194,7 @@ public class PlayerListener implements Listener{
DPlayer dplayer=DPlayer.get(player); DPlayer dplayer=DPlayer.get(player);
GameWorld gworld=GameWorld.get(dplayer.world); GameWorld gworld=GameWorld.get(dplayer.world);
if(dplayer!=null){ if(dplayer!=null){
for(Material material:gworld.config.secureObjects){ for(Material material:gworld.config.getSecureObjects()){
if(material==event.getItemDrop().getItemStack().getType()){ if(material==event.getItemDrop().getItemStack().getType()){
event.setCancelled(true); event.setCancelled(true);
p.msg(player,p.language.get("Error_Drop")); p.msg(player,p.language.get("Error_Drop"));
@ -295,7 +295,7 @@ public class PlayerListener implements Listener{
//Check GameWorld //Check GameWorld
GameWorld gWorld = GameWorld.get(player.getWorld()); GameWorld gWorld = GameWorld.get(player.getWorld());
if(gWorld != null){ if(gWorld != null){
int timeUntilKickOfflinePlayer = gWorld.config.timeUntilKickOfflinePlayer; int timeUntilKickOfflinePlayer = gWorld.config.getTimeUntilKickOfflinePlayer();
if(timeUntilKickOfflinePlayer == 0){ if(timeUntilKickOfflinePlayer == 0){
dPlayer.leave(); dPlayer.leave();