From d839fd9dd163a8a4a81efcb44af9acedfc381b26 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 22 Dec 2016 19:58:43 -0500 Subject: [PATCH] Started work on Dungeons --- .../components/dungeons/DungeonComponent.java | 20 +++++++++ .../components/dungeons/commands/Enter.java | 23 ++++++++++ .../components/dungeons/commands/Exit.java | 23 ++++++++++ .../components/dungeons/dungeons/Dungeon.java | 30 +++++++++++++ .../dungeons/dungeons/GenericDungeonA1.java | 45 +++++++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 src/buttondevteam/alipresents/components/dungeons/DungeonComponent.java create mode 100644 src/buttondevteam/alipresents/components/dungeons/commands/Enter.java create mode 100644 src/buttondevteam/alipresents/components/dungeons/commands/Exit.java create mode 100644 src/buttondevteam/alipresents/components/dungeons/dungeons/Dungeon.java create mode 100644 src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java diff --git a/src/buttondevteam/alipresents/components/dungeons/DungeonComponent.java b/src/buttondevteam/alipresents/components/dungeons/DungeonComponent.java new file mode 100644 index 0000000..439f60c --- /dev/null +++ b/src/buttondevteam/alipresents/components/dungeons/DungeonComponent.java @@ -0,0 +1,20 @@ +package buttondevteam.alipresents.components.dungeons; + +import org.bukkit.plugin.java.JavaPlugin; + +import buttondevteam.alipresents.architecture.Component; +import buttondevteam.alipresents.components.dungeons.commands.Enter; +import buttondevteam.alipresents.components.dungeons.commands.Exit; +import buttondevteam.alipresents.components.dungeons.dungeons.GenericDungeonA1; + +public class DungeonComponent extends Component { + public GenericDungeonA1 dungeonA1; + @Override + public void register(JavaPlugin plugin) { + dungeonA1 = new GenericDungeonA1(plugin); + registerCommand(plugin, new Enter(this)); + registerCommand(plugin, new Exit(this)); + + } + +} diff --git a/src/buttondevteam/alipresents/components/dungeons/commands/Enter.java b/src/buttondevteam/alipresents/components/dungeons/commands/Enter.java new file mode 100644 index 0000000..d93b8d7 --- /dev/null +++ b/src/buttondevteam/alipresents/components/dungeons/commands/Enter.java @@ -0,0 +1,23 @@ +package buttondevteam.alipresents.components.dungeons.commands; + +import org.bukkit.entity.Player; + +import buttondevteam.alipresents.architecture.commands.ModCommand; +import buttondevteam.alipresents.components.dungeons.DungeonComponent; + +public class Enter extends ModCommand{ + private DungeonComponent component; + public Enter(DungeonComponent component) { + this.component = component; + } + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + component.dungeonA1.enterDungeon(player); + return false; + } + @Override + public String GetCommandPath(){ + return "dungeon enter"; + } + +} diff --git a/src/buttondevteam/alipresents/components/dungeons/commands/Exit.java b/src/buttondevteam/alipresents/components/dungeons/commands/Exit.java new file mode 100644 index 0000000..88b2f74 --- /dev/null +++ b/src/buttondevteam/alipresents/components/dungeons/commands/Exit.java @@ -0,0 +1,23 @@ +package buttondevteam.alipresents.components.dungeons.commands; + +import org.bukkit.entity.Player; + +import buttondevteam.alipresents.architecture.commands.PlayerCommand; +import buttondevteam.alipresents.components.dungeons.DungeonComponent; + +public class Exit extends PlayerCommand { + + private DungeonComponent component; + public Exit(DungeonComponent component) { + this.component = component; + } + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + component.dungeonA1.exitDungeon(player); + return false; + } + public String getCommandPath(){ + return "dungeon exit"; + } + +} diff --git a/src/buttondevteam/alipresents/components/dungeons/dungeons/Dungeon.java b/src/buttondevteam/alipresents/components/dungeons/dungeons/Dungeon.java new file mode 100644 index 0000000..520c36a --- /dev/null +++ b/src/buttondevteam/alipresents/components/dungeons/dungeons/Dungeon.java @@ -0,0 +1,30 @@ +package buttondevteam.alipresents.components.dungeons.dungeons; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +/**Dungeon Object that represents a dungeon*/ +public abstract class Dungeon { + public abstract Location getDungeonEntrance(); + public abstract Location getDungeonExit(); + public boolean enterDungeon(Player player){ + + if (getDungeonEntrance() == null){ + player.sendMessage("There has been a collapse! You may not enter the dungeon now."); + return false; + } + player.teleport(getDungeonEntrance()); + player.setGameMode(GameMode.ADVENTURE); + return true; + } + public boolean exitDungeon(Player player){ + if (getDungeonExit() == null){ + player.sendMessage("Oh god, something went horribly wrong with exiting... Yell for help!"); + return false; + } + player.teleport(getDungeonExit()); + player.setGameMode(GameMode.SURVIVAL); + return true; + } +} diff --git a/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java b/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java new file mode 100644 index 0000000..d262f56 --- /dev/null +++ b/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java @@ -0,0 +1,45 @@ +package buttondevteam.alipresents.components.dungeons.dungeons; + +import org.bukkit.Location; +import org.bukkit.plugin.java.JavaPlugin; + +public class GenericDungeonA1 extends Dungeon{ + private Location dungeonEntrance; + private Location dungeonExit; + + public GenericDungeonA1(JavaPlugin plugin){ + if(!initDungeon(plugin)){ + plugin.getServer().broadcastMessage("DungeonA1 can't be initialized!"); + } + } + private boolean initDungeon(JavaPlugin plugin){ + if (plugin.getServer().getWorld("Dungeons") == null || plugin.getServer().getWorld("world") == null){ + plugin.getServer().broadcastMessage("GenericDungeonA1Error! One of the worlds is null!"); + plugin.getServer().broadcastMessage("Available Worlds... " + plugin.getServer().getWorlds().toString()); + return false; + } + + dungeonEntrance = new Location(plugin.getServer().getWorld("Dungeons"), -7.5, 138.0, -91.5); + dungeonExit = plugin.getServer().getWorld("world").getSpawnLocation().clone(); + + if (dungeonEntrance == null || dungeonExit == null){ + plugin.getServer().broadcastMessage("DungeonA1Error! Dungeon Entrance or Exit is null!"); + plugin.getServer().broadcastMessage("DungeonEnterance: " + dungeonEntrance.toString()); + plugin.getServer().broadcastMessage("Dungeon Exit: " + dungeonExit.toString()); + return false; + } + return true; + } + public void setDungeonEnterance(Location location){ + dungeonEntrance = location; + } + @Override + public Location getDungeonEntrance() { + return dungeonEntrance; + } + @Override + public Location getDungeonExit() { + return dungeonExit; + } + +}