I'm trying to make it so that when a player is waiting for the countdown to, they are in an area that they cannot go out of. I would like to do it from a configurable radius from the spawn point they are at but I'm unsure how to implement the radius into my code. Here is is. Code: @EventHandler public void onTeamMove(PlayerMoveEvent event) { Player p = event.getPlayer(); Location from = event.getFrom(); Location to = event.getTo(); int radius = plugin.getConfig().getInt("TeamDeathmatch.WaitingRadius"); int fromX = (int) from.getX(); int fromY = (int) from.getY(); int fromZ = (int) from.getZ(); int toX = (int) to.getX(); int toY = (int) to.getY(); int toZ = (int) to.getZ(); if (toX != fromX || toY != fromY || toZ != fromZ) { if (plugin.TDM.contains(p)) { p.teleport(from); p.sendMessage(ChatColor.DARK_RED + "[MCWar] " + ChatColor.DARK_AQUA + "Waiting for other players!"); } } } Thanks
are you wanting to beable to allow them to move in the radius? If so: get the x, add/subtract the radius number, if if the new x is < (or less) then teleport them back.
Yeah I want people to move in the radius, so it'll be like a temp worldguard region which you can't leave but are able to move around in. How do I add/subtract then number because I can't do anything with fromX and from.add(); won't allow the radius. Edit: tried doing this but it didn't show any messages or teleport me Code: if (from.add(radius, fromY, fromZ) == to) {
you would do: int rmx = fromX-radius int rpx = fromX+radius and so on... and then: if (toX > rpx || toX < rmx) { //code |
You calculate the x and z distance that the player has moved from the center using double deltaX = playerLocation.getX() - center.getX(); double deltaY = playerLocation.getY() - center.getY(); Then you want to calculate the distance from the center by getting the square root of the sum of the squares of the deltas.
Do you know why this is not working? Code: @EventHandler public void onTeamMove(PlayerMoveEvent event) { Player p = event.getPlayer(); Location pLoc = p.getLocation(); Location from = event.getFrom(); int radius = plugin.getConfig().getInt("TeamDeathmatch.WaitingRadius"); double deltaX = pLoc.getX() - from.getX(); double deltaY = pLoc.getY() - from.getY(); double deltaZ = pLoc.getZ() - from.getZ(); if (deltaX == radius || deltaY == radius || deltaZ == radius) { if (plugin.TDMFreeze.contains(p)) { p.teleport(from); p.sendMessage(ChatColor.DARK_RED + "[MCWar] " + ChatColor.DARK_AQUA + "Waiting for other players!"); } } }
Because you are checking if it equals the radius. So if the player moves 3 blocks, and your radius is 2, it won't trigger. You want to use 'greater equal to'
I still can't get it to work. Code: @EventHandler public void onTeamMove(PlayerMoveEvent event) { Player p = event.getPlayer(); Location pLoc = p.getLocation(); Location from = event.getFrom(); int radius = plugin.getConfig().getInt("TeamDeathmatch.WaitingRadius"); double deltaX = pLoc.getX() - from.getX(); double deltaY = pLoc.getY() - from.getY(); double deltaZ = pLoc.getZ() - from.getZ(); if (deltaX >= radius || deltaY >= radius || deltaZ >= radius) { if (plugin.TDMFreeze.contains(p)) { p.teleport(from); p.sendMessage(ChatColor.DARK_RED + "[MCWar] " + ChatColor.DARK_AQUA + "Waiting for other players!"); } } } With the code above it doesn't do anything and if I change the greater than/less than signs around then it only keeps me on the spawn block and i can't move at all
The problem is you're calculating your delta using the player location before and after the move evevnt. Since the server runs at 20 ticks per second, this value won't be too high. Your "from" location should be the center of your circle.