Started work on Dungeon code

This commit is contained in:
alisolarflare 2017-08-25 19:52:05 -04:00
parent 8940793094
commit 61aaec1ef6
3 changed files with 104 additions and 0 deletions

View file

@ -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());
}
}

View file

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

View file

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