Started work on Dungeons

This commit is contained in:
alisolarflare 2016-12-22 19:58:43 -05:00
parent 67aab38168
commit d839fd9dd1
5 changed files with 141 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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