mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 21:48:43 +01:00
Added command whitelists
This commit is contained in:
parent
970e351c5f
commit
d7e4c09599
@ -262,19 +262,37 @@ public class EditWorld {
|
|||||||
|
|
||||||
// Invite
|
// Invite
|
||||||
public static boolean addInvitedPlayer(String editWorldName, UUID uuid) {
|
public static boolean addInvitedPlayer(String editWorldName, UUID uuid) {
|
||||||
if (exist(editWorldName)) {
|
if ( !exist(editWorldName)) {
|
||||||
WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"));
|
|
||||||
config.addInvitedPlayer(uuid.toString());
|
|
||||||
config.save();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
public static boolean removeInvitedPlayer(String editWorldName, UUID uuid, String name) {
|
||||||
if (exist(editWorldName)) {
|
if ( !exist(editWorldName)) {
|
||||||
WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml"));
|
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.removeInvitedPlayers(uuid.toString(), name.toLowerCase());
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
@ -293,15 +311,17 @@ public class EditWorld {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) {
|
public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) {
|
||||||
if ( !exist(editWorldName)) {
|
if ( !exist(editWorldName)) {
|
||||||
return false;
|
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
|
// 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())) {
|
if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -39,11 +39,11 @@ public class WorldConfig {
|
|||||||
private boolean keepInventoryOnFinish = false;
|
private boolean keepInventoryOnFinish = false;
|
||||||
private boolean keepInventoryOnDeath = true;
|
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 Map<Integer, String> msgs = new HashMap<Integer, String>();
|
||||||
|
|
||||||
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
|
private List<String> invitedPlayers = new ArrayList<String>();
|
||||||
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
|
private List<Material> secureObjects = new ArrayList<Material>();
|
||||||
|
|
||||||
private int initialLives = 3;
|
private int initialLives = 3;
|
||||||
|
|
||||||
@ -63,8 +63,9 @@ public class WorldConfig {
|
|||||||
// MobTypes
|
// MobTypes
|
||||||
private Set<DMobType> mobTypes = new HashSet<DMobType>();
|
private Set<DMobType> mobTypes = new HashSet<DMobType>();
|
||||||
|
|
||||||
public WorldConfig() {
|
private List<String> gameCommandWhitelist = new ArrayList<String>();
|
||||||
|
|
||||||
|
public WorldConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldConfig(File file) {
|
public WorldConfig(File file) {
|
||||||
@ -147,18 +148,21 @@ public class WorldConfig {
|
|||||||
|
|
||||||
/* Secure Objects */
|
/* Secure Objects */
|
||||||
if (configFile.contains("secureObjects")) {
|
if (configFile.contains("secureObjects")) {
|
||||||
List<Integer> secureObjectList = configFile.getIntegerList("secureObjects");
|
List<String> secureObjectList = configFile.getStringList("secureObjects");
|
||||||
for (int i : secureObjectList) {
|
for (String id : secureObjectList) {
|
||||||
secureObjects.add(Material.getMaterial(i));
|
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 */
|
/* Invited Players */
|
||||||
if (configFile.contains("invitedPlayers")) {
|
if (configFile.contains("invitedPlayers")) {
|
||||||
List<String> invitedPlayers = configFile.getStringList("invitedPlayers");
|
invitedPlayers = configFile.getStringList("invitedPlayers");
|
||||||
for (String i : invitedPlayers) {
|
|
||||||
invitedPlayers.add(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep Inventory */
|
/* Keep Inventory */
|
||||||
@ -272,6 +276,10 @@ public class WorldConfig {
|
|||||||
/* Mobtypes */
|
/* Mobtypes */
|
||||||
configSectionMessages = configFile.getConfigurationSection("mobTypes");
|
configSectionMessages = configFile.getConfigurationSection("mobTypes");
|
||||||
mobTypes = DMobType.load(configSectionMessages);
|
mobTypes = DMobType.load(configSectionMessages);
|
||||||
|
|
||||||
|
if (configFile.contains("gameCommandWhitelist")) {
|
||||||
|
gameCommandWhitelist = configFile.getStringList("gameCommandWhitelist");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -307,7 +315,7 @@ public class WorldConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
public CopyOnWriteArrayList<DClass> getClasses() {
|
public List<DClass> getClasses() {
|
||||||
if (dClasses != null) {
|
if (dClasses != null) {
|
||||||
if ( !dClasses.isEmpty()) {
|
if ( !dClasses.isEmpty()) {
|
||||||
return dClasses;
|
return dClasses;
|
||||||
@ -435,4 +443,11 @@ public class WorldConfig {
|
|||||||
return mobTypes;
|
return mobTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the gameCommandWhitelist
|
||||||
|
*/
|
||||||
|
public List<String> getGameCommandWhitelist() {
|
||||||
|
return gameCommandWhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -23,6 +25,8 @@ public class MainConfig {
|
|||||||
/* Default Dungeon Settings */
|
/* Default Dungeon Settings */
|
||||||
public WorldConfig defaultDungeon;
|
public WorldConfig defaultDungeon;
|
||||||
|
|
||||||
|
private List<String> editCommandWhitelist = new ArrayList<String>();
|
||||||
|
|
||||||
public MainConfig(File file) {
|
public MainConfig(File file) {
|
||||||
if ( !file.exists()) {
|
if ( !file.exists()) {
|
||||||
try {
|
try {
|
||||||
@ -36,6 +40,7 @@ public class MainConfig {
|
|||||||
configFile.set("tutorialStartGroup", "default");
|
configFile.set("tutorialStartGroup", "default");
|
||||||
configFile.set("tutorialEndGroup", "player");
|
configFile.set("tutorialEndGroup", "player");
|
||||||
configFile.set("tutorialEndGroup", "player");
|
configFile.set("tutorialEndGroup", "player");
|
||||||
|
configFile.createSection("editCommandWhitelist");
|
||||||
|
|
||||||
ConfigurationSection defaultDungeon = configFile.createSection("default");
|
ConfigurationSection defaultDungeon = configFile.createSection("default");
|
||||||
defaultDungeon.set("initialLives", 3);
|
defaultDungeon.set("initialLives", 3);
|
||||||
@ -80,6 +85,10 @@ public class MainConfig {
|
|||||||
tutorialEndGroup = configFile.getString("tutorial.endgroup");
|
tutorialEndGroup = configFile.getString("tutorial.endgroup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (configFile.contains("editCommandWhitelist")) {
|
||||||
|
editCommandWhitelist = configFile.getStringList("editCommandWhitelist");
|
||||||
|
}
|
||||||
|
|
||||||
/* Default Dungeon Config */
|
/* Default Dungeon Config */
|
||||||
ConfigurationSection configSection = configFile.getConfigurationSection("default");
|
ConfigurationSection configSection = configFile.getConfigurationSection("default");
|
||||||
if (configSection != null) {
|
if (configSection != null) {
|
||||||
@ -139,4 +148,11 @@ public class MainConfig {
|
|||||||
return tutorialEndGroup;
|
return tutorialEndGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the editCommandWhitelist
|
||||||
|
*/
|
||||||
|
public List<String> getEditCommandWhitelist() {
|
||||||
|
return editCommandWhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.dre2n.dungeonsxl.listener;
|
package io.github.dre2n.dungeonsxl.listener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
|
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
|
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
|
||||||
@ -510,14 +512,39 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dPlayer.isEditing() && event.getPlayer().hasPermission("dxl.cmdedit")) {
|
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;
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist());
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] splittedCmd = event.getMessage().split(" ");
|
} else if (gameWorld != null) {
|
||||||
if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) {
|
if (gameWorld.getConfig() != null) {
|
||||||
MessageUtil.sendMessage(event.getPlayer(), dMessages.getMessage(Messages.ERROR_CMD));
|
commandWhitelist.addAll(gameWorld.getConfig().getGameCommandWhitelist());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commandWhitelist.add("dungeonsxl");
|
||||||
|
commandWhitelist.add("dungeon");
|
||||||
|
commandWhitelist.add("dxl");
|
||||||
|
|
||||||
event.setCancelled(true);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user