mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-10-14 23:47:46 +02:00
Added new config system
This commit is contained in:
parent
e3936cd282
commit
bf34312f30
@ -3,6 +3,7 @@ package com.dre.dungeonsxl;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -16,23 +17,32 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DConfig {
|
||||
public File file;
|
||||
public static DConfig mainConfig = new DConfig();
|
||||
|
||||
private File file;
|
||||
|
||||
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>();
|
||||
|
||||
public CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
|
||||
public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
|
||||
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
|
||||
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
|
||||
|
||||
public boolean isLobbyDisabled = false;
|
||||
public int timeToNextPlay = 0;
|
||||
public int timeToNextLoot = 0;
|
||||
private boolean isLobbyDisabled = false;
|
||||
private int timeToNextPlay = 0;
|
||||
private int timeToNextLoot = 0;
|
||||
|
||||
public int timeUntilKickOfflinePlayer = -1;
|
||||
private int timeUntilKickOfflinePlayer = -1;
|
||||
|
||||
//Spout
|
||||
public boolean spoutCraftOnly = false;
|
||||
public String spoutTexturepackURL;
|
||||
private boolean spoutCraftOnly = false;
|
||||
private String spoutTexturepackURL;
|
||||
|
||||
//MobTypes
|
||||
private Set<DMobType> mobTypes = new HashSet<DMobType>();
|
||||
|
||||
public DConfig(){
|
||||
|
||||
}
|
||||
|
||||
public DConfig(File file){
|
||||
this.file=file;
|
||||
@ -143,29 +153,45 @@ public class DConfig {
|
||||
/* Lobby */
|
||||
if(configFile.contains("isLobbyDisabled")){
|
||||
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
|
||||
} else {
|
||||
isLobbyDisabled = mainConfig.isLobbyDisabled;
|
||||
}
|
||||
|
||||
/* Times */
|
||||
if(configFile.contains("timeToNextPlay")){
|
||||
timeToNextPlay = configFile.getInt("timeToNextPlay");
|
||||
} else {
|
||||
timeToNextPlay = mainConfig.timeToNextPlay;
|
||||
}
|
||||
|
||||
if(configFile.contains("timeToNextLoot")){
|
||||
timeToNextLoot = configFile.getInt("timeToNextLoot");
|
||||
} else {
|
||||
timeToNextLoot = mainConfig.timeToNextLoot;
|
||||
}
|
||||
|
||||
if(configFile.contains("timeUntilKickOfflinePlayer")){
|
||||
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
|
||||
} else {
|
||||
timeUntilKickOfflinePlayer = mainConfig.timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/* Spout */
|
||||
if(configFile.contains("spout.spoutCraftOnly")){
|
||||
spoutCraftOnly = configFile.getBoolean("spout.spoutCraftOnly");
|
||||
} else {
|
||||
spoutCraftOnly = mainConfig.spoutCraftOnly;
|
||||
}
|
||||
|
||||
if(configFile.contains("spout.spoutTexturepackURL")){
|
||||
spoutTexturepackURL = configFile.getString("spout.spoutTexturepackURL");
|
||||
} else {
|
||||
spoutTexturepackURL = mainConfig.spoutTexturepackURL;
|
||||
}
|
||||
|
||||
/* Mobtypes */
|
||||
configSetionMessages = configFile.getConfigurationSection("mobTypes");
|
||||
this.mobTypes = DMobType.load(configSetionMessages);
|
||||
}
|
||||
|
||||
public void save(){
|
||||
@ -197,13 +223,25 @@ public class DConfig {
|
||||
}
|
||||
}
|
||||
|
||||
//Get
|
||||
//Getters and Setters
|
||||
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){
|
||||
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)){
|
||||
return dClass;
|
||||
}
|
||||
@ -211,7 +249,69 @@ public class DConfig {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMsg(int id){
|
||||
public String getMsg(int id, boolean returnMainConfig){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public class DGSign {
|
||||
if(file!=null){
|
||||
DConfig confReader=new DConfig(file);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.dre.dungeonsxl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -9,8 +8,6 @@ import java.util.Set;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
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.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -25,8 +22,6 @@ import com.dre.dungeonsxl.game.DMob;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
|
||||
public class DMobType {
|
||||
private static Set<DMobType> mobTypes = new HashSet<DMobType>();
|
||||
|
||||
private String name;
|
||||
private EntityType type;
|
||||
|
||||
@ -50,8 +45,6 @@ public class DMobType {
|
||||
|
||||
/* Methods */
|
||||
public DMobType(String name, EntityType type){
|
||||
mobTypes.add(this);
|
||||
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
}
|
||||
@ -107,15 +100,16 @@ public class DMobType {
|
||||
}
|
||||
|
||||
//Load Config
|
||||
public static void load(File file){
|
||||
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
public static Set<DMobType> load(ConfigurationSection configFile){
|
||||
Set<DMobType> set = new HashSet<DMobType>();
|
||||
if(configFile!=null){
|
||||
//Read Mobs
|
||||
for(String mobName:configFile.getKeys(false)){
|
||||
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
||||
|
||||
if (type!=null) {
|
||||
DMobType mobType=new DMobType(mobName, type);
|
||||
set.add(mobType);
|
||||
|
||||
//Load MaxHealth
|
||||
if(configFile.contains(mobName+".MaxHealth")){
|
||||
@ -223,19 +217,22 @@ public class DMobType {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Clear
|
||||
public static void clear(){
|
||||
mobTypes.clear();
|
||||
return set;
|
||||
}
|
||||
|
||||
//Get
|
||||
public static DMobType get(String name){
|
||||
for(DMobType mobType:DMobType.mobTypes){
|
||||
public static DMobType get(String name, Set<DMobType> mobTypes){
|
||||
for(DMobType mobType:mobTypes){
|
||||
if(mobType.name.equalsIgnoreCase(name)){
|
||||
return mobType;
|
||||
}
|
||||
}
|
||||
for(DMobType mobType:P.p.mainConfig.defaultDungeon.getMobTypes()){
|
||||
if(mobType.name.equalsIgnoreCase(name)){
|
||||
return mobType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class DPlayer {
|
||||
if(isEditing) this.player.setGameMode(GameMode.CREATIVE); else this.player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
if(!isEditing){
|
||||
if(GameWorld.get(world).config.isLobbyDisabled){
|
||||
if(GameWorld.get(world).config.isLobbyDisabled()){
|
||||
this.ready();
|
||||
}
|
||||
}
|
||||
@ -90,11 +90,11 @@ public class DPlayer {
|
||||
if(!isEditing){
|
||||
if(p.isSpoutEnabled){
|
||||
GameWorld gworld = GameWorld.get(world);
|
||||
if(gworld.config.spoutTexturepackURL!=null){
|
||||
if(gworld.config.getSpoutTexturepackURL()!=null){
|
||||
SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName());
|
||||
if(sPlayer!=null){
|
||||
sPlayer.sendNotification(ChatColor.GOLD+"DungeonsXL",ChatColor.RED+"Download texturepack!", Material.FIREBALL);
|
||||
sPlayer.setTexturePack(gworld.config.spoutTexturepackURL);
|
||||
sPlayer.setTexturePack(gworld.config.getSpoutTexturepackURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class DPortal {
|
||||
/* Check Spout */
|
||||
boolean spoutCheck = true;
|
||||
if(P.p.isSpoutEnabled){
|
||||
if(dgroup.getGworld().config.spoutCraftOnly){
|
||||
if(dgroup.getGworld().config.isSpoutCraftOnly()){
|
||||
if(!Spout.getServer().getPlayer(player.getName()).isSpoutCraftEnabled()){
|
||||
spoutCheck = false;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ public class EditWorld {
|
||||
}else{
|
||||
if(exist(eworldname)){
|
||||
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
|
||||
config.invitedPlayers.add(player.toLowerCase());
|
||||
config.addInvitedPlayer(player.toLowerCase());
|
||||
config.save();
|
||||
return true;
|
||||
}
|
||||
@ -241,7 +241,7 @@ public class EditWorld {
|
||||
}else{
|
||||
if(exist(eworldname)){
|
||||
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
|
||||
config.invitedPlayers.remove(player.toLowerCase());
|
||||
config.removeInvitedPlayers(player.toLowerCase());
|
||||
config.save();
|
||||
return true;
|
||||
}
|
||||
@ -259,7 +259,7 @@ public class EditWorld {
|
||||
}else{
|
||||
if(exist(eworldname)){
|
||||
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworldname, "config.yml"));
|
||||
return config.invitedPlayers.contains(player.toLowerCase());
|
||||
return config.getInvitedPlayers().contains(player.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ public class MainConfig {
|
||||
ConfigurationSection configSetion = configFile.getConfigurationSection("default");
|
||||
if(configSetion!=null){
|
||||
defaultDungeon = new DConfig(configSetion);
|
||||
DConfig.mainConfig = defaultDungeon;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,10 +66,13 @@ public class P extends JavaPlugin{
|
||||
//Commands
|
||||
getCommand("dungeonsxl").setExecutor(new CommandListener());
|
||||
|
||||
//Load Language
|
||||
language = new LanguageReader(new File(p.getDataFolder(), "languages/en.yml"));
|
||||
|
||||
//Load Config
|
||||
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"));
|
||||
|
||||
//Init Commands
|
||||
@ -130,7 +133,6 @@ public class P extends JavaPlugin{
|
||||
DGroup.dgroups.clear();
|
||||
DGSign.dgsigns.clear();
|
||||
DLootInventory.LootInventorys.clear();
|
||||
DMobType.clear();
|
||||
DPlayer.players.clear();
|
||||
DPortal.portals.clear();
|
||||
LeaveSign.lsigns.clear();
|
||||
@ -248,9 +250,6 @@ public class P extends JavaPlugin{
|
||||
DGSign.load(configFile);
|
||||
LeaveSign.load(configFile);
|
||||
|
||||
//Load mob types
|
||||
DMobType.load(new File(p.getDataFolder(), "mobs.yml"));
|
||||
|
||||
//Load saved players
|
||||
DSavePlayer.load();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class CMDMsg extends DCommand{
|
||||
DConfig confreader = new DConfig(new File(p.getDataFolder()+"/dungeons/"+eworld.dungeonname, "config.yml"));
|
||||
|
||||
if(args.length==2){
|
||||
String msg=confreader.msgs.get(id);
|
||||
String msg=confreader.getMsg(id, true);
|
||||
if(msg!=null){
|
||||
p.msg(player, ChatColor.WHITE+msg);
|
||||
}else{
|
||||
@ -51,14 +51,14 @@ public class CMDMsg extends DCommand{
|
||||
String[] splitMsg=msg.split("\"");
|
||||
if(splitMsg.length>1){
|
||||
msg=splitMsg[1];
|
||||
String old=confreader.msgs.get(id);
|
||||
String old=confreader.getMsg(id, false);
|
||||
if(old==null){
|
||||
p.msg(player, p.language.get("Cmd_Msg_Added",""+id));
|
||||
}else{
|
||||
p.msg(player, p.language.get("Cmd_Msg_Updated",""+id));
|
||||
}
|
||||
|
||||
confreader.msgs.put(id, msg);
|
||||
confreader.setMsg(msg, id);
|
||||
confreader.save();
|
||||
}else{
|
||||
p.msg(player, p.language.get("Error_MsgFormat"));
|
||||
|
@ -4,7 +4,6 @@ package com.dre.dungeonsxl.commands;
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.dre.dungeonsxl.DMobType;
|
||||
import com.dre.dungeonsxl.LanguageReader;
|
||||
import com.dre.dungeonsxl.MainConfig;
|
||||
|
||||
@ -33,10 +32,6 @@ public class CMDReload extends DCommand{
|
||||
//Load Language
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class GameWorld {
|
||||
sign.setLine(3, ChatColor.DARK_BLUE+"############");
|
||||
sign.update();
|
||||
} else if (lines[1].equalsIgnoreCase("classes")){
|
||||
if(!config.isLobbyDisabled){
|
||||
if(!config.isLobbyDisabled()){
|
||||
int[] direction=DGSign.getDirection(block.getData());
|
||||
int directionX=direction[0];
|
||||
int directionZ=direction[1];
|
||||
@ -188,7 +188,7 @@ public class GameWorld {
|
||||
}
|
||||
if(lines[1].equalsIgnoreCase("msg")){
|
||||
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){
|
||||
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),false));
|
||||
block.setTypeId(0);
|
||||
@ -197,7 +197,7 @@ public class GameWorld {
|
||||
}
|
||||
if(lines[1].equalsIgnoreCase("soundmsg")){
|
||||
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){
|
||||
messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),true));
|
||||
block.setTypeId(0);
|
||||
@ -296,7 +296,7 @@ public class GameWorld {
|
||||
if(dungeonFolder.isDirectory()){
|
||||
DConfig config=new DConfig(new File(p.getDataFolder()+"/dungeons/"+dungeon, "config.yml"));
|
||||
|
||||
if(config.timeToNextPlay!=0){
|
||||
if(config.getTimeToNextPlay()!=0){
|
||||
//read PlayerConfig
|
||||
File file=new File(p.getDataFolder()+"/dungeons/"+dungeon, "players.yml");
|
||||
|
||||
@ -312,7 +312,7 @@ public class GameWorld {
|
||||
|
||||
if(playerConfig.contains(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;
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ public class GameWorld {
|
||||
gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml"));
|
||||
|
||||
//Secure Objects
|
||||
gworld.secureObjects=gworld.config.secureObjects;
|
||||
gworld.secureObjects=gworld.config.getSecureObjects();
|
||||
|
||||
//World
|
||||
p.copyDirectory(file,new File("DXL_Game_"+gworld.id));
|
||||
|
@ -39,7 +39,8 @@ public class MobSpawner {
|
||||
|
||||
public void update(){
|
||||
World world=this.block.getWorld();
|
||||
|
||||
GameWorld gworld = GameWorld.get(world);
|
||||
if(gworld != null){
|
||||
for(Player player:world.getPlayers()){
|
||||
if(player.getWorld()==world){
|
||||
if(player.getLocation().distance(this.block.getLocation())<this.radius){
|
||||
@ -63,7 +64,7 @@ public class MobSpawner {
|
||||
}
|
||||
|
||||
//Check custom mobs
|
||||
DMobType mobType = DMobType.get(this.mob);
|
||||
DMobType mobType = DMobType.get(this.mob, gworld.config.getMobTypes());
|
||||
|
||||
if(mobType!=null){
|
||||
mobType.spawn(GameWorld.get(world), this.block.getLocation());
|
||||
@ -84,7 +85,7 @@ public class MobSpawner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Static
|
||||
|
@ -194,7 +194,7 @@ public class PlayerListener implements Listener{
|
||||
DPlayer dplayer=DPlayer.get(player);
|
||||
GameWorld gworld=GameWorld.get(dplayer.world);
|
||||
if(dplayer!=null){
|
||||
for(Material material:gworld.config.secureObjects){
|
||||
for(Material material:gworld.config.getSecureObjects()){
|
||||
if(material==event.getItemDrop().getItemStack().getType()){
|
||||
event.setCancelled(true);
|
||||
p.msg(player,p.language.get("Error_Drop"));
|
||||
@ -295,7 +295,7 @@ public class PlayerListener implements Listener{
|
||||
//Check GameWorld
|
||||
GameWorld gWorld = GameWorld.get(player.getWorld());
|
||||
if(gWorld != null){
|
||||
int timeUntilKickOfflinePlayer = gWorld.config.timeUntilKickOfflinePlayer;
|
||||
int timeUntilKickOfflinePlayer = gWorld.config.getTimeUntilKickOfflinePlayer();
|
||||
|
||||
if(timeUntilKickOfflinePlayer == 0){
|
||||
dPlayer.leave();
|
||||
|
Loading…
Reference in New Issue
Block a user