diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java index 2046f7f4..f8329ce2 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/EditWorld.java @@ -262,38 +262,53 @@ public class EditWorld { // Invite public static boolean addInvitedPlayer(String editWorldName, UUID uuid) { - if (exist(editWorldName)) { - WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml")); - config.addInvitedPlayer(uuid.toString()); - config.save(); - return true; + if ( !exist(editWorldName)) { + return false; } - return false; + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + try { + file.createNewFile(); + + } catch (IOException exception) { + exception.printStackTrace(); + return false; + } + } + WorldConfig config = new WorldConfig(file); + config.addInvitedPlayer(uuid.toString()); + config.save(); + + return true; } public static boolean removeInvitedPlayer(String editWorldName, UUID uuid, String name) { - if (exist(editWorldName)) { - WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml")); - config.removeInvitedPlayers(uuid.toString(), name.toLowerCase()); - config.save(); - - // Kick Player - EditWorld editWorld = EditWorld.getByName(editWorldName); - if (editWorld != null) { - DPlayer player = DPlayer.getByName(name); - - if (player != null) { - if (editWorld.world.getPlayers().contains(player.getPlayer())) { - player.leave(); - } - } - } - - return true; + if ( !exist(editWorldName)) { + return false; } - return false; + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + return false; + } + WorldConfig config = new WorldConfig(file); + config.removeInvitedPlayers(uuid.toString(), name.toLowerCase()); + config.save(); + + // Kick Player + EditWorld editWorld = EditWorld.getByName(editWorldName); + if (editWorld != null) { + DPlayer player = DPlayer.getByName(name); + + if (player != null) { + if (editWorld.world.getPlayers().contains(player.getPlayer())) { + player.leave(); + } + } + } + + return true; } public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) { @@ -301,7 +316,12 @@ public class EditWorld { return false; } - WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml")); + File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"); + if ( !file.exists()) { + return false; + } + + WorldConfig config = new WorldConfig(file); // get player from both a 0.9.1 and lower and 0.9.2 and higher file if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) { return true; diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java b/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java index 50fd5472..9d65e5cb 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/WorldConfig.java @@ -39,11 +39,11 @@ public class WorldConfig { private boolean keepInventoryOnFinish = false; private boolean keepInventoryOnDeath = true; - private CopyOnWriteArrayList dClasses = new CopyOnWriteArrayList(); + private List dClasses = new ArrayList(); private Map msgs = new HashMap(); - private CopyOnWriteArrayList invitedPlayers = new CopyOnWriteArrayList(); - private CopyOnWriteArrayList secureObjects = new CopyOnWriteArrayList(); + private List invitedPlayers = new ArrayList(); + private List secureObjects = new ArrayList(); private int initialLives = 3; @@ -63,8 +63,9 @@ public class WorldConfig { // MobTypes private Set mobTypes = new HashSet(); + private List gameCommandWhitelist = new ArrayList(); + public WorldConfig() { - } public WorldConfig(File file) { @@ -147,18 +148,21 @@ public class WorldConfig { /* Secure Objects */ if (configFile.contains("secureObjects")) { - List secureObjectList = configFile.getIntegerList("secureObjects"); - for (int i : secureObjectList) { - secureObjects.add(Material.getMaterial(i)); + List secureObjectList = configFile.getStringList("secureObjects"); + for (String id : secureObjectList) { + if (Material.getMaterial(NumberUtil.parseInt(id)) != null) { + secureObjects.add(Material.getMaterial(NumberUtil.parseInt(id))); + + } else if (Material.getMaterial(id) != null) { + secureObjects.add(Material.getMaterial(id)); + } } } /* Invited Players */ if (configFile.contains("invitedPlayers")) { - List invitedPlayers = configFile.getStringList("invitedPlayers"); - for (String i : invitedPlayers) { - invitedPlayers.add(i); - } + invitedPlayers = configFile.getStringList("invitedPlayers"); + } /* Keep Inventory */ @@ -272,6 +276,10 @@ public class WorldConfig { /* Mobtypes */ configSectionMessages = configFile.getConfigurationSection("mobTypes"); mobTypes = DMobType.load(configSectionMessages); + + if (configFile.contains("gameCommandWhitelist")) { + gameCommandWhitelist = configFile.getStringList("gameCommandWhitelist"); + } } @SuppressWarnings("deprecation") @@ -307,7 +315,7 @@ public class WorldConfig { } // Getters and Setters - public CopyOnWriteArrayList getClasses() { + public List getClasses() { if (dClasses != null) { if ( !dClasses.isEmpty()) { return dClasses; @@ -435,4 +443,11 @@ public class WorldConfig { return mobTypes; } + /** + * @return the gameCommandWhitelist + */ + public List getGameCommandWhitelist() { + return gameCommandWhitelist; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/file/MainConfig.java b/src/io/github/dre2n/dungeonsxl/file/MainConfig.java index 2b917343..f0f19e49 100644 --- a/src/io/github/dre2n/dungeonsxl/file/MainConfig.java +++ b/src/io/github/dre2n/dungeonsxl/file/MainConfig.java @@ -4,6 +4,8 @@ import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -23,6 +25,8 @@ public class MainConfig { /* Default Dungeon Settings */ public WorldConfig defaultDungeon; + private List editCommandWhitelist = new ArrayList(); + public MainConfig(File file) { if ( !file.exists()) { try { @@ -36,6 +40,7 @@ public class MainConfig { configFile.set("tutorialStartGroup", "default"); configFile.set("tutorialEndGroup", "player"); configFile.set("tutorialEndGroup", "player"); + configFile.createSection("editCommandWhitelist"); ConfigurationSection defaultDungeon = configFile.createSection("default"); defaultDungeon.set("initialLives", 3); @@ -80,6 +85,10 @@ public class MainConfig { tutorialEndGroup = configFile.getString("tutorial.endgroup"); } + if (configFile.contains("editCommandWhitelist")) { + editCommandWhitelist = configFile.getStringList("editCommandWhitelist"); + } + /* Default Dungeon Config */ ConfigurationSection configSection = configFile.getConfigurationSection("default"); if (configSection != null) { @@ -139,4 +148,11 @@ public class MainConfig { return tutorialEndGroup; } + /** + * @return the editCommandWhitelist + */ + public List getEditCommandWhitelist() { + return editCommandWhitelist; + } + } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 5149a940..c6a0c878 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -1,5 +1,7 @@ package io.github.dre2n.dungeonsxl.listener; +import java.util.ArrayList; + import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; @@ -510,14 +512,39 @@ public class PlayerListener implements Listener { return; } - if (dPlayer.isEditing() && event.getPlayer().hasPermission("dxl.cmdedit")) { - return; + String command = event.getMessage().toLowerCase(); + ArrayList commandWhitelist = new ArrayList(); + + GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld()); + + if (dPlayer.isEditing()) { + if (event.getPlayer().hasPermission("dxl.cmdedit")) { + return; + + } else { + commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist()); + } + + } else if (gameWorld != null) { + if (gameWorld.getConfig() != null) { + commandWhitelist.addAll(gameWorld.getConfig().getGameCommandWhitelist()); + } } - String[] splittedCmd = event.getMessage().split(" "); - if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) { + commandWhitelist.add("dungeonsxl"); + commandWhitelist.add("dungeon"); + commandWhitelist.add("dxl"); + + event.setCancelled(true); + + for (String whitelistEntry : commandWhitelist) { + if (command.equals('/' + whitelistEntry.toLowerCase()) || command.startsWith('/' + whitelistEntry.toLowerCase() + ' ')) { + event.setCancelled(false); + } + } + + if (event.isCancelled()) { MessageUtil.sendMessage(event.getPlayer(), dMessages.getMessage(Messages.ERROR_CMD)); - event.setCancelled(true); } }