Added command whitelists

This commit is contained in:
Daniel Saukel 2016-01-14 18:06:04 +01:00
parent 970e351c5f
commit d7e4c09599
4 changed files with 121 additions and 43 deletions

View File

@ -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;

View File

@ -39,11 +39,11 @@ public class WorldConfig {
private boolean keepInventoryOnFinish = false;
private boolean keepInventoryOnDeath = true;
private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>();
private List<DClass> dClasses = new ArrayList<DClass>();
private Map<Integer, String> msgs = new HashMap<Integer, String>();
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
private List<String> invitedPlayers = new ArrayList<String>();
private List<Material> secureObjects = new ArrayList<Material>();
private int initialLives = 3;
@ -63,8 +63,9 @@ public class WorldConfig {
// MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>();
private List<String> gameCommandWhitelist = new ArrayList<String>();
public WorldConfig() {
}
public WorldConfig(File file) {
@ -147,18 +148,21 @@ public class WorldConfig {
/* Secure Objects */
if (configFile.contains("secureObjects")) {
List<Integer> secureObjectList = configFile.getIntegerList("secureObjects");
for (int i : secureObjectList) {
secureObjects.add(Material.getMaterial(i));
List<String> 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<String> 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<DClass> getClasses() {
public List<DClass> getClasses() {
if (dClasses != null) {
if ( !dClasses.isEmpty()) {
return dClasses;
@ -435,4 +443,11 @@ public class WorldConfig {
return mobTypes;
}
/**
* @return the gameCommandWhitelist
*/
public List<String> getGameCommandWhitelist() {
return gameCommandWhitelist;
}
}

View File

@ -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<String> editCommandWhitelist = new ArrayList<String>();
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<String> getEditCommandWhitelist() {
return editCommandWhitelist;
}
}

View File

@ -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<String> commandWhitelist = new ArrayList<String>();
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);
}
}