Added a way to set warps!

This commit is contained in:
Steffion 2013-08-04 16:24:41 +02:00
parent eefa682fb8
commit 69691157fd
11 changed files with 271 additions and 22 deletions

View File

@ -19,6 +19,9 @@ public class Arena {
public int waitingTimeSeeker; public int waitingTimeSeeker;
public int gameTime; public int gameTime;
public ArrayList<ItemStack> disguiseBlocks; public ArrayList<ItemStack> disguiseBlocks;
public LocationSerializable lobbyWarp;
public LocationSerializable hidersWarp;
public LocationSerializable seekersWarp;
public List<Player> playersInArena; public List<Player> playersInArena;
public ArenaState gameState; public ArenaState gameState;
public int timer; public int timer;
@ -28,7 +31,9 @@ public class Arena {
LocationSerializable pos2, int maxPlayers, int minPlayers, LocationSerializable pos2, int maxPlayers, int minPlayers,
int amountSeekersOnStart, int timeInLobbyUntilStart, int amountSeekersOnStart, int timeInLobbyUntilStart,
int waitingTimeSeeker, int gameTime, int waitingTimeSeeker, int gameTime,
ArrayList<ItemStack> disguiseBlocks, List<Player> playersInArena, ArrayList<ItemStack> disguiseBlocks,
LocationSerializable lobbyWarp, LocationSerializable hidersWarp,
LocationSerializable seekersWarp, List<Player> playersInArena,
ArenaState gameState, int timer, List<Player> seekers) { ArenaState gameState, int timer, List<Player> seekers) {
this.arenaName = arenaName; this.arenaName = arenaName;
this.pos1 = pos1; this.pos1 = pos1;
@ -44,6 +49,9 @@ public class Arena {
this.gameState = gameState; this.gameState = gameState;
this.timer = timer; this.timer = timer;
this.seekers = seekers; this.seekers = seekers;
this.lobbyWarp = lobbyWarp;
this.hidersWarp = hidersWarp;
this.seekersWarp = seekersWarp;
} }
public enum ArenaType { public enum ArenaType {

View File

@ -5,13 +5,17 @@ import java.util.LinkedList;
import nl.Steffion.BlockHunt.Arena.ArenaState; import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.Listeners.OnInventoryClickEvent; import nl.Steffion.BlockHunt.Listeners.OnInventoryClickEvent;
import nl.Steffion.BlockHunt.Listeners.OnInventoryCloseEvent; import nl.Steffion.BlockHunt.Listeners.OnInventoryCloseEvent;
import nl.Steffion.BlockHunt.Listeners.OnPlayerDropItemEvent;
import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent; import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent;
import nl.Steffion.BlockHunt.Listeners.OnPlayerMoveEvent;
import nl.Steffion.BlockHunt.Managers.CommandC; import nl.Steffion.BlockHunt.Managers.CommandC;
import nl.Steffion.BlockHunt.Managers.ConfigC; import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM; import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Serializables.ArenaSerializable; import nl.Steffion.BlockHunt.Serializables.ArenaSerializable;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable; import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
@ -37,6 +41,10 @@ public class BlockHunt extends JavaPlugin implements Listener {
new OnInventoryClickEvent(), this); new OnInventoryClickEvent(), this);
getServer().getPluginManager().registerEvents( getServer().getPluginManager().registerEvents(
new OnInventoryCloseEvent(), this); new OnInventoryCloseEvent(), this);
getServer().getPluginManager().registerEvents(
new OnPlayerDropItemEvent(), this);
getServer().getPluginManager().registerEvents(new OnPlayerMoveEvent(),
this);
ConfigurationSerialization.registerClass(LocationSerializable.class, ConfigurationSerialization.registerClass(LocationSerializable.class,
"Location"); "Location");
@ -116,6 +124,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
ConfigC.normal_ingameSeekerChoosen, ConfigC.normal_ingameSeekerChoosen,
true, "seeker-" + seeker.getName()); true, "seeker-" + seeker.getName());
arena.seekers.add(seeker); arena.seekers.add(seeker);
seeker.teleport(arena.seekersWarp);
} }
for (Player arenaPlayer : arena.playersInArena) { for (Player arenaPlayer : arena.playersInArena) {
@ -138,6 +147,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
disguise); disguise);
} }
arenaPlayer.teleport(arena.hidersWarp);
MessageM.sendFMessage( MessageM.sendFMessage(
arenaPlayer, arenaPlayer,
ConfigC.normal_ingameBlock, ConfigC.normal_ingameBlock,
@ -155,6 +166,24 @@ public class BlockHunt extends JavaPlugin implements Listener {
} }
} }
} }
for (Player player : arena.seekers) {
if (player.getInventory().getItem(0) == null
|| player.getInventory().getItem(0).getType() != Material.DIAMOND_SWORD) {
player.getInventory().setItem(0,
new ItemStack(Material.DIAMOND_SWORD, 1));
player.getInventory().setHelmet(
new ItemStack(Material.IRON_HELMET, 1));
player.getInventory().setChestplate(
new ItemStack(Material.IRON_CHESTPLATE, 1));
player.getInventory().setLeggings(
new ItemStack(Material.IRON_LEGGINGS, 1));
player.getInventory().setBoots(
new ItemStack(Material.IRON_BOOTS, 1));
player.getWorld().playSound(player.getLocation(),
Sound.ANVIL_USE, 1, 1);
}
}
} }
} }
}, 0, 20); }, 0, 20);

View File

@ -32,7 +32,7 @@ public class CMDcreate extends DefaultCMD {
ArenaSerializable arena = new ArenaSerializable( ArenaSerializable arena = new ArenaSerializable(
args[1], W.pos1.get(player), args[1], W.pos1.get(player),
W.pos2.get(player), 12, 3, 1, 90, 20, 300, W.pos2.get(player), 12, 3, 1, 90, 20, 300,
null, null, null, 0, null); null, null, null, null, null, null, 0, null);
W.arenas.getFile().set(args[1], arena); W.arenas.getFile().set(args[1], arena);
W.arenas.save(); W.arenas.save();
ArenaHandler.loadArenas(); ArenaHandler.loadArenas();

View File

@ -1,6 +1,7 @@
package nl.Steffion.BlockHunt.Commands; package nl.Steffion.BlockHunt.Commands;
import nl.Steffion.BlockHunt.Arena; import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.ArenaHandler; import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.W; import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.CommandC; import nl.Steffion.BlockHunt.Managers.CommandC;
@ -8,7 +9,9 @@ import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM; import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM; import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC; import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -42,20 +45,47 @@ public class CMDjoin extends DefaultCMD {
MessageM.sendFMessage(player, MessageM.sendFMessage(player,
ConfigC.error_joinNoBlocksSet, true); ConfigC.error_joinNoBlocksSet, true);
} else { } else {
arena.playersInArena.add(player); LocationSerializable zero = new LocationSerializable(
ArenaHandler.sendFMessage(arena, Bukkit.getWorld("world"), 0, 0, 0,
ConfigC.normal_joinJoinedArena, 0, 0);
true, if (!arena.lobbyWarp.equals(zero)
"playername-" + player.getName(), && !arena.hidersWarp.equals(zero)
"1-" + arena.playersInArena.size(), && !arena.seekersWarp.equals(zero)) {
"2-" + arena.maxPlayers); if (arena.gameState == ArenaState.WAITING
if (arena.playersInArena.size() < arena.minPlayers) { || arena.gameState == ArenaState.STARTING) {
ArenaHandler arena.playersInArena.add(player);
.sendFMessage( player.teleport(arena.lobbyWarp);
arena, ArenaHandler
ConfigC.warning_lobbyNeedAtleast, .sendFMessage(
true, arena,
"1-" + arena.minPlayers); ConfigC.normal_joinJoinedArena,
true,
"playername-"
+ player.getName(),
"1-"
+ arena.playersInArena
.size(),
"2-"
+ arena.maxPlayers);
if (arena.playersInArena.size() < arena.minPlayers) {
ArenaHandler
.sendFMessage(
arena,
ConfigC.warning_lobbyNeedAtleast,
true,
"1-"
+ arena.minPlayers);
}
} else {
MessageM.sendFMessage(
player,
ConfigC.error_joinArenaIngame,
true);
}
} else {
MessageM.sendFMessage(player,
ConfigC.error_joinWarpsNotSet,
true);
} }
} }
} }

View File

@ -0,0 +1,80 @@
package nl.Steffion.BlockHunt.Commands;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.CommandC;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class CMDsetwarp extends DefaultCMD {
@Override
public boolean exectue(Player player, Command cmd, String label,
String[] args) {
if (PlayerM.hasPerm(player, PermsC.set, true)) {
if (player != null) {
if (args.length <= 2) {
MessageM.sendFMessage(player,
ConfigC.error_notEnoughArguments, true, "syntax-"
+ CommandC.SETWARP.usage);
} else {
String arenaname = args[2];
String warpname = args[1];
Arena arena = null;
for (Arena arena2 : W.arenaList) {
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
arena = arena2;
}
}
if (arena != null) {
LocationSerializable loc = new LocationSerializable(
player.getLocation());
if (warpname.equalsIgnoreCase("lobby")) {
arena.lobbyWarp = loc;
save(arena);
MessageM.sendFMessage(player,
ConfigC.normal_setwarpWarpSet, true,
"warp-" + warpname);
} else if (warpname.equalsIgnoreCase("hiders")) {
arena.hidersWarp = loc;
save(arena);
MessageM.sendFMessage(player,
ConfigC.normal_setwarpWarpSet, true,
"warp-" + warpname);
} else if (warpname.equalsIgnoreCase("seekers")) {
arena.seekersWarp = loc;
save(arena);
MessageM.sendFMessage(player,
ConfigC.normal_setwarpWarpSet, true,
"warp-" + warpname);
} else {
MessageM.sendFMessage(player,
ConfigC.error_setwarpWarpNotFound, true,
"warp-" + warpname);
}
} else {
MessageM.sendFMessage(player, ConfigC.error_noArena,
true, "name-" + arenaname);
}
}
} else {
MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true);
}
}
return true;
}
public void save(Arena arena) {
W.arenas.getFile().set(arena.arenaName, arena);
W.arenas.save();
ArenaHandler.loadArenas();
}
}

View File

@ -0,0 +1,24 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.W;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
public class OnPlayerDropItemEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
Player player = event.getPlayer();
for (Arena arena : W.arenaList) {
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
}
}
}
}

View File

@ -0,0 +1,53 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.W;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class OnPlayerMoveEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMoveEvent(PlayerMoveEvent event) {
Player player = event.getPlayer();
for (Arena arena : W.arenaList) {
if (arena.playersInArena.contains(player)) {
double maxX = Math.max(arena.pos1.getX(), arena.pos2.getX());
double minX = Math.min(arena.pos1.getX(), arena.pos2.getX());
double maxY = Math.max(arena.pos1.getY(), arena.pos2.getY());
double minY = Math.min(arena.pos1.getY(), arena.pos2.getY());
double maxZ = Math.max(arena.pos1.getZ(), arena.pos2.getZ());
double minZ = Math.min(arena.pos1.getZ(), arena.pos2.getZ());
Location loc = player.getLocation();
if (loc.getBlockX() > maxX || loc.getBlockX() < minX) {
event.setCancelled(true);
loc.getWorld().playEffect(loc, Effect.ENDER_SIGNAL, 0);
loc.getWorld().playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
} else if (loc.getBlockZ() > maxZ || loc.getBlockZ() < minZ) {
event.setCancelled(true);
loc.getWorld().playEffect(loc, Effect.ENDER_SIGNAL, 0);
loc.getWorld().playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
} else if (loc.getBlockY() > maxY) {
event.setCancelled(true);
loc.getWorld().playEffect(loc, Effect.ENDER_SIGNAL, 0);
loc.getWorld().playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
player.teleport(loc.subtract(0, 1, 0));
} else if (loc.getBlockY() < minY) {
event.setCancelled(true);
loc.getWorld().playEffect(loc, Effect.ENDER_SIGNAL, 0);
loc.getWorld().playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
player.teleport(loc.add(0, 5, 0));
}
}
}
}
}

View File

@ -74,6 +74,14 @@ public enum CommandC {
ConfigC.help_set, ConfigC.help_set,
1, 1,
W.pluginName + " <set|s> <arenaname>"), W.pluginName + " <set|s> <arenaname>"),
SETWARP ("BlockHunt%setwarp_",
"BlockHunt%sw_",
new CMDsetwarp(),
ConfigC.commandEnabled_setwarp,
PermsC.setwarp,
ConfigC.help_setwarp,
1,
W.pluginName + " <setwarp|sw> <lobby|hiders|seekers> <arenaname>"),
NOT_FOUND ("%_", NOT_FOUND ("%_",
"%_", "%_",
new CMDnotfound(), new CMDnotfound(),

View File

@ -22,6 +22,7 @@ public enum ConfigC {
commandEnabled_wand (true, W.config), commandEnabled_wand (true, W.config),
commandEnabled_create (true, W.config), commandEnabled_create (true, W.config),
commandEnabled_set (true, W.config), commandEnabled_set (true, W.config),
commandEnabled_setwarp (true, W.config),
wandID (280, W.config), wandID (280, W.config),
wandName ("%A&l" + W.pluginName + "%N's selection wand", W.config), wandName ("%A&l" + W.pluginName + "%N's selection wand", W.config),
@ -44,6 +45,7 @@ public enum ConfigC {
help_wand ("%NGives you the wand selection tool.", W.messages), help_wand ("%NGives you the wand selection tool.", W.messages),
help_create ("%NCreates an arena from your selection.", W.messages), help_create ("%NCreates an arena from your selection.", W.messages),
help_set ("%NOpens a panel to set settings.", W.messages), help_set ("%NOpens a panel to set settings.", W.messages),
help_setwarp ("%NSets warps for your arena.", W.messages),
button_add ("%NAdd %A%1%%N to %A%2%%N", W.messages), button_add ("%NAdd %A%1%%N to %A%2%%N", W.messages),
button_add2 ("Add", W.messages), button_add2 ("Add", W.messages),
@ -68,6 +70,8 @@ public enum ConfigC {
W.messages), W.messages),
normal_ingameBlock ("%NYou're disguised as a(n) '%A%block%%N' block.", normal_ingameBlock ("%NYou're disguised as a(n) '%A%block%%N' block.",
W.messages), W.messages),
normal_setwarpWarpSet ("%NSet warp '%A%warp%%N' to your location!",
W.messages),
warning_lobbyNeedAtleast ("%WYou need atleast %A%1%%W player(s) to start the game!", warning_lobbyNeedAtleast ("%WYou need atleast %A%1%%W player(s) to start the game!",
W.messages), W.messages),
@ -84,6 +88,9 @@ public enum ConfigC {
error_joinAlreadyJoined ("%EYou've already joined an arena!", W.messages), error_joinAlreadyJoined ("%EYou've already joined an arena!", W.messages),
error_joinNoBlocksSet ("%EThere are none blocks set for this arena. Notify the administrator.", error_joinNoBlocksSet ("%EThere are none blocks set for this arena. Notify the administrator.",
W.messages), W.messages),
error_joinWarpsNotSet ("%EThere are no warps set for this arena. Notify the administrator.",
W.messages),
error_joinArenaIngame ("%EThis game has already started.", W.messages),
error_createSelectionFirst ("%EMake a selection first. Use the wand command: %A/" error_createSelectionFirst ("%EMake a selection first. Use the wand command: %A/"
+ W.pluginName + " <wand|w>%E.", + W.pluginName + " <wand|w>%E.",
W.messages), W.messages),
@ -93,7 +100,8 @@ public enum ConfigC {
W.messages), W.messages),
error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.", error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.",
W.messages), W.messages),
error_setNotABlock ("%EThat is not a block!", W.messages); error_setNotABlock ("%EThat is not a block!", W.messages),
error_setwarpWarpNotFound ("%EWarp '%A%warp%%E' is not valid!", W.messages);
public Object value; public Object value;
public ConfigM config; public ConfigM config;

View File

@ -21,7 +21,8 @@ public class PlayerM {
reload (main + "reload", PType.MODERATOR), reload (main + "reload", PType.MODERATOR),
create (main + "create", PType.ADMIN), create (main + "create", PType.ADMIN),
set (main + "set", PType.MODERATOR), set (main + "set", PType.MODERATOR),
join (main + "join", PType.PLAYER); join (main + "join", PType.PLAYER),
setwarp (main + "setwarp", PType.MODERATOR);
public String perm; public String perm;
public PType type; public PType type;

View File

@ -20,12 +20,14 @@ public class ArenaSerializable extends Arena implements
LocationSerializable pos2, int maxPlayers, int minPlayers, LocationSerializable pos2, int maxPlayers, int minPlayers,
int amountSeekersOnStart, int timeInLobbyUntilStart, int amountSeekersOnStart, int timeInLobbyUntilStart,
int waitingTimeSeeker, int gameTime, int waitingTimeSeeker, int gameTime,
ArrayList<ItemStack> disguiseBlocks, List<Player> playersInArena, ArrayList<ItemStack> disguiseBlocks,
LocationSerializable lobbyWarp, LocationSerializable hidersWarp,
LocationSerializable seekersWarp, List<Player> playersInArena,
ArenaState gameState, int timer, List<Player> seekers) { ArenaState gameState, int timer, List<Player> seekers) {
super(arenaName, pos1, pos2, maxPlayers, minPlayers, super(arenaName, pos1, pos2, maxPlayers, minPlayers,
amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker, amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker,
gameTime, disguiseBlocks, playersInArena, gameState, timer, gameTime, disguiseBlocks, lobbyWarp, hidersWarp, seekersWarp,
seekers); playersInArena, gameState, timer, seekers);
} }
@Override @Override
@ -41,6 +43,9 @@ public class ArenaSerializable extends Arena implements
map.put("waitingTimeSeeker", waitingTimeSeeker); map.put("waitingTimeSeeker", waitingTimeSeeker);
map.put("gameTime", gameTime); map.put("gameTime", gameTime);
map.put("disguiseBlocks", disguiseBlocks); map.put("disguiseBlocks", disguiseBlocks);
map.put("lobbyWarp", lobbyWarp);
map.put("hidersWarp", hidersWarp);
map.put("seekersWarp", seekersWarp);
return map; return map;
} }
@ -58,6 +63,9 @@ public class ArenaSerializable extends Arena implements
"waitingTimeSeeker", 20), (Integer) M.g(map, "waitingTimeSeeker", 20), (Integer) M.g(map,
"gameTime", 200), (ArrayList<ItemStack>) M.g(map, "gameTime", 200), (ArrayList<ItemStack>) M.g(map,
"disguiseBlocks", new ArrayList<ItemStack>()), "disguiseBlocks", new ArrayList<ItemStack>()),
(LocationSerializable) M.g(map, "lobbyWarp", loc),
(LocationSerializable) M.g(map, "hidersWarp", loc),
(LocationSerializable) M.g(map, "seekersWarp", loc),
new ArrayList<Player>(), ArenaState.WAITING, 0, new ArrayList<Player>(), ArenaState.WAITING, 0,
new ArrayList<Player>()); new ArrayList<Player>());
} }