Added a way to set warps!
This commit is contained in:
parent
eefa682fb8
commit
69691157fd
@ -19,6 +19,9 @@ public class Arena {
|
||||
public int waitingTimeSeeker;
|
||||
public int gameTime;
|
||||
public ArrayList<ItemStack> disguiseBlocks;
|
||||
public LocationSerializable lobbyWarp;
|
||||
public LocationSerializable hidersWarp;
|
||||
public LocationSerializable seekersWarp;
|
||||
public List<Player> playersInArena;
|
||||
public ArenaState gameState;
|
||||
public int timer;
|
||||
@ -28,7 +31,9 @@ public class Arena {
|
||||
LocationSerializable pos2, int maxPlayers, int minPlayers,
|
||||
int amountSeekersOnStart, int timeInLobbyUntilStart,
|
||||
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) {
|
||||
this.arenaName = arenaName;
|
||||
this.pos1 = pos1;
|
||||
@ -44,6 +49,9 @@ public class Arena {
|
||||
this.gameState = gameState;
|
||||
this.timer = timer;
|
||||
this.seekers = seekers;
|
||||
this.lobbyWarp = lobbyWarp;
|
||||
this.hidersWarp = hidersWarp;
|
||||
this.seekersWarp = seekersWarp;
|
||||
}
|
||||
|
||||
public enum ArenaType {
|
||||
|
@ -5,13 +5,17 @@ import java.util.LinkedList;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnInventoryClickEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnInventoryCloseEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnPlayerDropItemEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnPlayerMoveEvent;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandC;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
import nl.Steffion.BlockHunt.Serializables.ArenaSerializable;
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
@ -37,6 +41,10 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
new OnInventoryClickEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new OnInventoryCloseEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new OnPlayerDropItemEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerMoveEvent(),
|
||||
this);
|
||||
|
||||
ConfigurationSerialization.registerClass(LocationSerializable.class,
|
||||
"Location");
|
||||
@ -116,8 +124,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
ConfigC.normal_ingameSeekerChoosen,
|
||||
true, "seeker-" + seeker.getName());
|
||||
arena.seekers.add(seeker);
|
||||
seeker.teleport(arena.seekersWarp);
|
||||
}
|
||||
|
||||
|
||||
for (Player arenaPlayer : arena.playersInArena) {
|
||||
if (!arena.seekers.contains(arenaPlayer)) {
|
||||
ItemStack block = arena.disguiseBlocks.get(W.random
|
||||
@ -138,6 +147,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
disguise);
|
||||
}
|
||||
|
||||
arenaPlayer.teleport(arena.hidersWarp);
|
||||
|
||||
MessageM.sendFMessage(
|
||||
arenaPlayer,
|
||||
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);
|
||||
|
@ -32,7 +32,7 @@ public class CMDcreate extends DefaultCMD {
|
||||
ArenaSerializable arena = new ArenaSerializable(
|
||||
args[1], W.pos1.get(player),
|
||||
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.save();
|
||||
ArenaHandler.loadArenas();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package nl.Steffion.BlockHunt.Commands;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.W;
|
||||
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.PlayerM;
|
||||
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.entity.Player;
|
||||
|
||||
@ -42,20 +45,47 @@ public class CMDjoin extends DefaultCMD {
|
||||
MessageM.sendFMessage(player,
|
||||
ConfigC.error_joinNoBlocksSet, true);
|
||||
} else {
|
||||
arena.playersInArena.add(player);
|
||||
ArenaHandler.sendFMessage(arena,
|
||||
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);
|
||||
LocationSerializable zero = new LocationSerializable(
|
||||
Bukkit.getWorld("world"), 0, 0, 0,
|
||||
0, 0);
|
||||
if (!arena.lobbyWarp.equals(zero)
|
||||
&& !arena.hidersWarp.equals(zero)
|
||||
&& !arena.seekersWarp.equals(zero)) {
|
||||
if (arena.gameState == ArenaState.WAITING
|
||||
|| arena.gameState == ArenaState.STARTING) {
|
||||
arena.playersInArena.add(player);
|
||||
player.teleport(arena.lobbyWarp);
|
||||
ArenaHandler
|
||||
.sendFMessage(
|
||||
arena,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
80
src/nl/Steffion/BlockHunt/Commands/CMDsetwarp.java
Normal file
80
src/nl/Steffion/BlockHunt/Commands/CMDsetwarp.java
Normal 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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
src/nl/Steffion/BlockHunt/Listeners/OnPlayerMoveEvent.java
Normal file
53
src/nl/Steffion/BlockHunt/Listeners/OnPlayerMoveEvent.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -74,6 +74,14 @@ public enum CommandC {
|
||||
ConfigC.help_set,
|
||||
1,
|
||||
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 ("%_",
|
||||
"%_",
|
||||
new CMDnotfound(),
|
||||
|
@ -22,6 +22,7 @@ public enum ConfigC {
|
||||
commandEnabled_wand (true, W.config),
|
||||
commandEnabled_create (true, W.config),
|
||||
commandEnabled_set (true, W.config),
|
||||
commandEnabled_setwarp (true, W.config),
|
||||
|
||||
wandID (280, 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_create ("%NCreates an arena from your selection.", 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_add2 ("Add", W.messages),
|
||||
@ -68,6 +70,8 @@ public enum ConfigC {
|
||||
W.messages),
|
||||
normal_ingameBlock ("%NYou're disguised as a(n) '%A%block%%N' block.",
|
||||
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!",
|
||||
W.messages),
|
||||
@ -84,6 +88,9 @@ public enum ConfigC {
|
||||
error_joinAlreadyJoined ("%EYou've already joined an arena!", W.messages),
|
||||
error_joinNoBlocksSet ("%EThere are none blocks set for this arena. Notify the administrator.",
|
||||
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/"
|
||||
+ W.pluginName + " <wand|w>%E.",
|
||||
W.messages),
|
||||
@ -93,7 +100,8 @@ public enum ConfigC {
|
||||
W.messages),
|
||||
error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.",
|
||||
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 ConfigM config;
|
||||
|
@ -21,7 +21,8 @@ public class PlayerM {
|
||||
reload (main + "reload", PType.MODERATOR),
|
||||
create (main + "create", PType.ADMIN),
|
||||
set (main + "set", PType.MODERATOR),
|
||||
join (main + "join", PType.PLAYER);
|
||||
join (main + "join", PType.PLAYER),
|
||||
setwarp (main + "setwarp", PType.MODERATOR);
|
||||
|
||||
public String perm;
|
||||
public PType type;
|
||||
|
@ -20,12 +20,14 @@ public class ArenaSerializable extends Arena implements
|
||||
LocationSerializable pos2, int maxPlayers, int minPlayers,
|
||||
int amountSeekersOnStart, int timeInLobbyUntilStart,
|
||||
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) {
|
||||
super(arenaName, pos1, pos2, maxPlayers, minPlayers,
|
||||
amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker,
|
||||
gameTime, disguiseBlocks, playersInArena, gameState, timer,
|
||||
seekers);
|
||||
gameTime, disguiseBlocks, lobbyWarp, hidersWarp, seekersWarp,
|
||||
playersInArena, gameState, timer, seekers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,6 +43,9 @@ public class ArenaSerializable extends Arena implements
|
||||
map.put("waitingTimeSeeker", waitingTimeSeeker);
|
||||
map.put("gameTime", gameTime);
|
||||
map.put("disguiseBlocks", disguiseBlocks);
|
||||
map.put("lobbyWarp", lobbyWarp);
|
||||
map.put("hidersWarp", hidersWarp);
|
||||
map.put("seekersWarp", seekersWarp);
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -58,6 +63,9 @@ public class ArenaSerializable extends Arena implements
|
||||
"waitingTimeSeeker", 20), (Integer) M.g(map,
|
||||
"gameTime", 200), (ArrayList<ItemStack>) M.g(map,
|
||||
"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>());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user