From 61aaec1ef66d5187bffa08dda111eb2925ac1105 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 25 Aug 2017 19:52:05 -0400 Subject: [PATCH] Started work on Dungeon code --- .../presents/dungeon/DungeonComponent.java | 16 ++++++ .../presents/dungeon/DungeonCreate.java | 49 +++++++++++++++++++ .../presents/dungeon/DungeonDelete.java | 39 +++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 src/main/java/buttondevteam/presents/dungeon/DungeonComponent.java create mode 100644 src/main/java/buttondevteam/presents/dungeon/DungeonCreate.java create mode 100644 src/main/java/buttondevteam/presents/dungeon/DungeonDelete.java diff --git a/src/main/java/buttondevteam/presents/dungeon/DungeonComponent.java b/src/main/java/buttondevteam/presents/dungeon/DungeonComponent.java new file mode 100644 index 0000000..e28e0a2 --- /dev/null +++ b/src/main/java/buttondevteam/presents/dungeon/DungeonComponent.java @@ -0,0 +1,16 @@ +package buttondevteam.presents.dungeon; + +import org.bukkit.plugin.java.JavaPlugin; + +import buttondevteam.presents.architecture.Component; + +public class DungeonComponent extends Component{ + + @Override + public void register(JavaPlugin plugin) { + this.registerCommand(plugin, new DungeonCreate()); + this.registerCommand(plugin, new DungeonDelete()); + + } + +} diff --git a/src/main/java/buttondevteam/presents/dungeon/DungeonCreate.java b/src/main/java/buttondevteam/presents/dungeon/DungeonCreate.java new file mode 100644 index 0000000..6972558 --- /dev/null +++ b/src/main/java/buttondevteam/presents/dungeon/DungeonCreate.java @@ -0,0 +1,49 @@ +package buttondevteam.presents.dungeon; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.presents.architecture.commands.ModCommand; + +@CommandClass(path="dungeon create") +public class DungeonCreate extends ModCommand{ + + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + + if(args.length < 1) return false; + + String dungeonName = args[0]; + FileConfiguration config = this.getPlugin().getConfig(); + + if (config.contains("dungeons." + dungeonName)){ + player.sendMessage("There already exists a dungeon named " + dungeonName); + player.sendMessage("Type /dungeon info [dungeonname] to get more information"); + } + else{ + config.set("dungeon." + dungeonName, true); + config.set("dungeon." + dungeonName + ".owner", player.getName()); + config.set("dungeon." + dungeonName + ".spawn", player.getLocation().toString()); + config.set("dungeon." + dungeonName + ".created", System.currentTimeMillis()); + this.getPlugin().saveConfig(); + + assert(dungeonName == + this.getPlugin() + .getConfig() + .getString("dungeon." + dungeonName)); + + player.sendMessage("New dungeon named " + dungeonName + " created."); + } + return true; + } + + + @Override + public String[] GetHelpText(String alias){ + return new String[] { + "/dungeon create [dungeonName]", + "instantiates a new dungeon, setting the dungeon spawn to the player location" + }; + } +} diff --git a/src/main/java/buttondevteam/presents/dungeon/DungeonDelete.java b/src/main/java/buttondevteam/presents/dungeon/DungeonDelete.java new file mode 100644 index 0000000..59bd447 --- /dev/null +++ b/src/main/java/buttondevteam/presents/dungeon/DungeonDelete.java @@ -0,0 +1,39 @@ +package buttondevteam.presents.dungeon; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.presents.architecture.commands.ModCommand; + +@CommandClass(path="dungeon delete") +public class DungeonDelete extends ModCommand{ + + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + + if (args.length < 1) return false; + + String dungeonName = args[0]; + FileConfiguration config = this.getPlugin().getConfig(); + + if(!config.contains("dungeon." + dungeonName)){ + player.sendMessage("This dungeon does not exist!"); + String output = "Valid dungeons are:"; + for(String key : config.getConfigurationSection("dungeon").getKeys(false)){ + output += key; + output += ", "; + } + player.sendMessage(output); + }else{ + for(String key : config.getConfigurationSection("dungeon." + dungeonName).getKeys(true)){ + config.set("dungeon." + dungeonName + "." + key, null); + } + player.sendMessage("Dungeon " + dungeonName + " deleted."); + } + + + return true; + } + +}