Don't allow teleporting once you've joined an arena
This commit is contained in:
parent
1f90bb83ff
commit
8028d7a340
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
target/
|
||||
lib/
|
||||
/bin/
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
|
@ -107,7 +107,7 @@ public class ArenaHandler {
|
||||
|
||||
MemoryStorage.pData.put(player, pad);
|
||||
|
||||
player.teleport(arena.lobbyWarp);
|
||||
PlayerHandler.teleport(player, arena.lobbyWarp);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
for (PotionEffect pe : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(pe.getType());
|
||||
@ -267,7 +267,7 @@ public class ArenaHandler {
|
||||
}
|
||||
seeker.getInventory().clear();
|
||||
arena.seekers.add(seeker);
|
||||
seeker.teleport(arena.seekersWarp);
|
||||
PlayerHandler.teleport(seeker, arena.seekersWarp);
|
||||
MemoryStorage.seekertime.put(seeker, arena.waitingTimeSeeker);
|
||||
seeker.setWalkSpeed(0.3F);
|
||||
|
||||
@ -300,7 +300,7 @@ public class ArenaHandler {
|
||||
player.setHealth(pad.pHealth);
|
||||
player.setFoodLevel(pad.pFood);
|
||||
player.addPotionEffects(pad.pPotionEffects);
|
||||
player.teleport(arena.spawnWarp);
|
||||
PlayerHandler.teleport(player, arena.spawnWarp);
|
||||
player.setGameMode(pad.pGameMode);
|
||||
player.setAllowFlight(pad.pFlying);
|
||||
if (player.getAllowFlight()) {
|
||||
@ -434,7 +434,7 @@ public class ArenaHandler {
|
||||
arena.timer = 0;
|
||||
arena.playersInArena.clear();
|
||||
}
|
||||
|
||||
|
||||
public static boolean noPlayersInArenas() {
|
||||
// Check if there are any players in any arena (quick way to early exit for event handlers)
|
||||
for (Arena arena : MemoryStorage.arenaList) {
|
||||
|
@ -7,6 +7,7 @@ import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.Listeners.*;
|
||||
import nl.Steffion.BlockHunt.PermissionsC.Permissions;
|
||||
import nl.Steffion.BlockHunt.Commands.CMDcreate;
|
||||
import nl.Steffion.BlockHunt.Commands.CMDhelp;
|
||||
@ -23,18 +24,6 @@ import nl.Steffion.BlockHunt.Commands.CMDshop;
|
||||
import nl.Steffion.BlockHunt.Commands.CMDstart;
|
||||
import nl.Steffion.BlockHunt.Commands.CMDtokens;
|
||||
import nl.Steffion.BlockHunt.Commands.CMDwand;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnBlockBreakEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnBlockPlaceEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnEntityDamageByEntityEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnEntityDamageEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnFoodLevelChangeEvent;
|
||||
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.Listeners.OnPlayerQuitEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnSignChangeEvent;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandManager;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigManager;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
@ -129,6 +118,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerDropItemEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerInteractEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerMoveEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerTeleportEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerQuitEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnSignChangeEvent(), this);
|
||||
|
||||
@ -249,7 +239,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
if (!arena.seekers.contains(seeker)) {
|
||||
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameSeekerChoosen, "seeker-" + seeker.getName());
|
||||
arena.seekers.add(seeker);
|
||||
seeker.teleport(arena.seekersWarp);
|
||||
PlayerHandler.teleport(seeker, arena.seekersWarp);
|
||||
seeker.getInventory().clear();
|
||||
seeker.updateInventory();
|
||||
seeker.setWalkSpeed(0.3F);
|
||||
@ -273,7 +263,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
|
||||
DisguiseAPI.disguiseToAll(arenaPlayer, disguise);
|
||||
arenaPlayer.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(arenaPlayer, arena.hidersWarp);
|
||||
ItemStack blockCount = new ItemStack(block.getType(), 5);
|
||||
arenaPlayer.getInventory().setItem(8, blockCount);
|
||||
arenaPlayer.getInventory().setHelmet(new ItemStack(block));
|
||||
@ -307,7 +297,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
if (MemoryStorage.seekertime.get(player) != null) {
|
||||
MemoryStorage.seekertime.put(player, MemoryStorage.seekertime.get(player) - 1);
|
||||
if (MemoryStorage.seekertime.get(player) <= 0) {
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
MemoryStorage.seekertime.remove(player);
|
||||
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameSeekerSpawned, "playername-" + player.getName());
|
||||
}
|
||||
@ -461,12 +451,12 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
/**
|
||||
* Args to String. Makes 1 string.
|
||||
*
|
||||
*
|
||||
* @param input
|
||||
* String list which should be converted to a string.
|
||||
* @param startArg
|
||||
* Start on this length.
|
||||
*
|
||||
*
|
||||
* @return The converted string.
|
||||
*/
|
||||
public static String stringBuilder(String[] input, int startArg) {
|
||||
@ -547,7 +537,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
/**
|
||||
* Short a String for like the Scoreboard title.
|
||||
*
|
||||
*
|
||||
* @param string
|
||||
* String to be shorten.
|
||||
* @param maxLenght
|
||||
|
@ -103,7 +103,8 @@ public enum ConfigC {
|
||||
"%TAG%ENo player found with the name '%A%playername%%E'!", MemoryStorage.messages), error_tokensUnknownsetting("%TAG%E'%A%option%%E' is not a known option!", MemoryStorage.messages), error_shopNeedMoreTokens(
|
||||
"%TAG%EYou need more tokens before you can buy this item.", MemoryStorage.messages), error_shopMaxSeekersReached(
|
||||
"%TAG%ESorry, the maximum amount of seekers has been reached!", MemoryStorage.messages), error_shopMaxHidersReached(
|
||||
"%TAG%ESorry, the maximum amount of hiders has been reached!", MemoryStorage.messages);
|
||||
"%TAG%ESorry, the maximum amount of hiders has been reached!", MemoryStorage.messages),
|
||||
error_teleportBlocked("%TAG%EYou cannot teleport while playing!", MemoryStorage.messages);
|
||||
|
||||
public Object value;
|
||||
public ConfigManager config;
|
||||
@ -111,7 +112,7 @@ public enum ConfigC {
|
||||
|
||||
/**
|
||||
* Makes an object from the list above.
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
* Setting in the config file.
|
||||
* @param config
|
||||
|
@ -5,12 +5,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import nl.Steffion.BlockHunt.Arena;
|
||||
import nl.Steffion.BlockHunt.*;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.BlockHunt;
|
||||
import nl.Steffion.BlockHunt.ConfigC;
|
||||
import nl.Steffion.BlockHunt.MemoryStorage;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -148,7 +144,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
|
||||
} else {
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
MemoryStorage.seekertime.put(player, arena.waitingTimeSeeker);
|
||||
player.teleport(arena.seekersWarp);
|
||||
PlayerHandler.teleport(player, arena.seekersWarp);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setWalkSpeed(0.3F);
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
package nl.Steffion.BlockHunt.Listeners;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena;
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.*;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.BlockHunt;
|
||||
import nl.Steffion.BlockHunt.MemoryStorage;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
@ -36,7 +33,7 @@ public class OnPlayerMoveEvent implements Listener {
|
||||
Location loc = player.getLocation();
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
return;
|
||||
}
|
||||
double maxX = Math.max(arena.pos1.getX(), arena.pos2.getX());
|
||||
@ -51,32 +48,32 @@ public class OnPlayerMoveEvent implements Listener {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
} else if (loc.getBlockX() < minX) {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
} else if (loc.getBlockZ() > maxZ) {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
} else if (loc.getBlockZ() < minZ) {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
} else if (loc.getBlockY() > maxY) {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
} else if (loc.getBlockY() < minY) {
|
||||
//event.setCancelled(true);
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
player.teleport(arena.hidersWarp);
|
||||
PlayerHandler.teleport(player, arena.hidersWarp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package nl.Steffion.BlockHunt.Listeners;
|
||||
|
||||
import nl.Steffion.BlockHunt.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
import nl.Steffion.BlockHunt.MemoryStorage;
|
||||
import org.bukkit.Location;
|
||||
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.PlayerTeleportEvent;
|
||||
|
||||
public class OnPlayerTeleportEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (MemoryStorage.pData.get(player) != null) {
|
||||
handlePlayer(event, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a player that is in an arena
|
||||
* @param event PlayerTeleportEvent
|
||||
* @param player Player
|
||||
*/
|
||||
private void handlePlayer(PlayerTeleportEvent event, Player player) {
|
||||
Location storedLoc = MemoryStorage.teleportLoc.remove(player);
|
||||
if (storedLoc == null || event.getTo().distanceSquared(storedLoc) > 1) {
|
||||
MessageManager.sendFMessage(player, ConfigC.error_teleportBlocked);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ package nl.Steffion.BlockHunt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import nl.Steffion.BlockHunt.Managers.CommandManager;
|
||||
@ -59,4 +60,6 @@ public class MemoryStorage {
|
||||
public static HashMap<Player, Location> moveLoc = new HashMap<>();
|
||||
public static HashMap<Player, Location> hiddenLoc = new HashMap<>();
|
||||
public static HashMap<Player, Boolean> hiddenLocWater = new HashMap<>();
|
||||
|
||||
public static Map<Player, Location> teleportLoc = new HashMap<>();
|
||||
}
|
||||
|
11
src/main/java/nl/Steffion/BlockHunt/PlayerHandler.java
Normal file
11
src/main/java/nl/Steffion/BlockHunt/PlayerHandler.java
Normal file
@ -0,0 +1,11 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerHandler {
|
||||
public static void teleport(Player player, Location location) {
|
||||
MemoryStorage.teleportLoc.put(player, location);
|
||||
player.teleport(location);
|
||||
}
|
||||
}
|
@ -87,4 +87,5 @@ error-tokensPlayerNotOnline: '%TAG%ENo player found with the name ''%A%playernam
|
||||
error-tokensUnknownsetting: '%TAG%E''%A%option%%E'' is not a known option!'
|
||||
error-shopNeedMoreTokens: '%TAG%EYou need more tokens before you can buy this item.'
|
||||
error-shopMaxSeekersReached: '%TAG%ESorry, the maximum amount of seekers has been reached!'
|
||||
error-shopMaxHidersReached: '%TAG%ESorry, the maximum amount of hiders has been reached!'
|
||||
error-shopMaxHidersReached: '%TAG%ESorry, the maximum amount of hiders has been reached!'
|
||||
error-teleportBlocked: '%TAG%EYou cannot teleport while playing!'
|
||||
|
@ -87,4 +87,5 @@ error-tokensPlayerNotOnline: '%TAG%ENo player found with the name ''%A%playernam
|
||||
error-tokensUnknownsetting: '%TAG%E''%A%option%%E'' is not a known option!'
|
||||
error-shopNeedMoreTokens: '%TAG%EYou need more tokens before you can buy this item.'
|
||||
error-shopMaxSeekersReached: '%TAG%ESorry, the maximum amount of seekers has been reached!'
|
||||
error-shopMaxHidersReached: '%TAG%ESorry, the maximum amount of hiders has been reached!'
|
||||
error-shopMaxHidersReached: '%TAG%ESorry, the maximum amount of hiders has been reached!'
|
||||
error-teleportBlocked: '%TAG%EYou cannot teleport while playing!'
|
||||
|
@ -97,3 +97,4 @@ error:
|
||||
shopNeedMoreTokens: '%TAG%EYou need more tokens before you can buy this item.'
|
||||
shopMaxSeekersReached: '%TAG%ESorry, the maximum amount of seekers has been reached!'
|
||||
shopMaxHidersReached: '%TAG%ESorry, the maximum amount of hiders has been reached!'
|
||||
teleportBlocked: '%TAG%EYou cannot teleport while playing!'
|
||||
|
Loading…
Reference in New Issue
Block a user