From 1a86d5fb9e9d0b51e5a87cb4cf8a84082f3c07d3 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Mon, 25 Jul 2016 01:19:29 -0400 Subject: [PATCH 1/5] Added Polar Bear where missing --- .../bukkit/listeners/PlayerEvents.java | 22 ++++++++++--------- .../bukkit/util/BukkitChunkManager.java | 18 ++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 3cecf4b40..47a6ca301 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -28,16 +28,6 @@ import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlotListener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -121,6 +111,17 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; + /** * Player Events involving plots. * @@ -1467,6 +1468,7 @@ public class PlayerEvents extends PlotListener implements Listener { case MINECART_TNT: case BOAT: return checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); + case POLAR_BEAR: case RABBIT: case SHEEP: case MUSHROOM_COW: diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index a73bb63c3..fef2434e0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -17,14 +17,6 @@ import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue; import com.plotsquared.bukkit.object.entity.EntityWrapper; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.DyeColor; @@ -57,6 +49,15 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + public class BukkitChunkManager extends ChunkManager { public static boolean isIn(RegionWrapper region, int x, int z) { @@ -546,6 +547,7 @@ public class BukkitChunkManager extends ChunkManager { case BOAT: count[4]++; break; + case POLAR_BEAR: case RABBIT: case SHEEP: case MUSHROOM_COW: From 5d92701100cfb9a4f2e4826b8c6bd2bd81bc5e33 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Mon, 25 Jul 2016 18:04:17 -0400 Subject: [PATCH 2/5] Fixed deny-teleport flag --- .../src/main/java/com/intellectualcrafters/plot/flag/Flags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java index 7b8247d25..439d4b0cd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java @@ -113,7 +113,7 @@ public final class Flags { } }; public static final BooleanFlag SLEEP = new BooleanFlag("sleep"); - public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("teleport-deny"); + public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport"); private static final HashMap> flags; From 290e5c68dc2c90a874d24fd2a738e52224205868 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Mon, 25 Jul 2016 18:42:31 -0400 Subject: [PATCH 3/5] Fix Sponge generation casting --- .../plotsquared/sponge/util/SpongeSetupUtils.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java index a72b6574e..e814beaf5 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java @@ -26,7 +26,7 @@ import java.util.Objects; import java.util.Optional; public class SpongeSetupUtils extends SetupUtils { - + @Override public void updateGenerators() { if (!SetupUtils.generators.isEmpty()) { @@ -48,7 +48,7 @@ public class SpongeSetupUtils extends SetupUtils { } } } - + @Override public String getGenerator(PlotArea plotArea) { if (SetupUtils.generators.isEmpty()) { @@ -61,7 +61,7 @@ public class SpongeSetupUtils extends SetupUtils { WorldGenerator generator = world.getWorldGenerator(); throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } - + @Override public String setupWorld(SetupObject object) { SetupUtils.manager.updateGenerators(); @@ -140,16 +140,16 @@ public class SpongeSetupUtils extends SetupUtils { if (object.setupGenerator != null) { // create world with generator GeneratorWrapper gw = SetupUtils.generators.get(object.setupGenerator); - WorldArchetype wgm = (WorldArchetype) gw.getPlatformGenerator(); - + WorldGeneratorModifier wgm = (WorldGeneratorModifier) gw.getPlatformGenerator(); + WorldArchetype settings = WorldArchetype.builder() .loadsOnStartup(true) .keepsSpawnLoaded(true) .dimension(DimensionTypes.OVERWORLD) - .generator(GeneratorTypes.OVERWORLD) + .generator(GeneratorTypes.FLAT) .usesMapFeatures(false) .enabled(true) - //.generatorModifiers(wgm) + .generatorModifiers(wgm) .build("PS",object.world); WorldProperties properties = null; try { From 5f8c77a6cdb3c30ccc41fbc07512ce762316d7e6 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Mon, 25 Jul 2016 18:43:11 -0400 Subject: [PATCH 4/5] Change Sponge method behavior --- .../java/com/plotsquared/sponge/object/SpongePlayer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index 8bc5fd9e4..840d3f5ad 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -1,6 +1,7 @@ package com.plotsquared.sponge.object; import com.flowpowered.math.vector.Vector3d; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -111,8 +112,12 @@ public class SpongePlayer extends PlotPlayer { @Override public void setCompassTarget(Location location) { - TargetedLocationData target = this.player.getOrCreate(TargetedLocationData.class).get(); - target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(location).getPosition()); + Optional target = this.player.getOrCreate(TargetedLocationData.class); + if (target.isPresent()) { + target.get().set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(location).getPosition()); + } else { + PS.debug("Failed to set compass target."); + } } @Override From 80ea3e9ce776aa6ba3c10dc3e670455b3af90173 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Mon, 25 Jul 2016 20:00:59 -0400 Subject: [PATCH 5/5] Sponge Fixes and minor changes. --- .../com/plotsquared/bukkit/BukkitMain.java | 2 - .../bukkit/listeners/ForceFieldListener.java | 3 +- .../bukkit/listeners/PlayerEvents.java | 2 +- .../com/intellectualcrafters/plot/PS.java | 1 - .../com/plotsquared/sponge/SpongeMain.java | 3 - .../sponge/listener/ForceFieldListener.java | 97 +++++++++++++++++++ .../sponge/listener/MainListener.java | 2 + 7 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 Sponge/src/main/java/com/plotsquared/sponge/listener/ForceFieldListener.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 7fb9c2fde..e3152a8a7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -39,7 +39,6 @@ import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.listeners.ChunkListener; import com.plotsquared.bukkit.listeners.EntitySpawnListener; -import com.plotsquared.bukkit.listeners.ForceFieldListener; import com.plotsquared.bukkit.listeners.PlayerEvents; import com.plotsquared.bukkit.listeners.PlayerEvents183; import com.plotsquared.bukkit.listeners.PlayerEvents_1_8; @@ -401,7 +400,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain @Override public void registerForceFieldEvents() { - getServer().getPluginManager().registerEvents(new ForceFieldListener(), this); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java index a4258421c..d32185f23 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -8,14 +8,13 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import org.bukkit.entity.Player; -import org.bukkit.event.Listener; import org.bukkit.util.Vector; import java.util.HashSet; import java.util.Set; import java.util.UUID; -public class ForceFieldListener implements Listener { +public class ForceFieldListener { private static Set getNearbyPlayers(Player player, Plot plot) { Set players = new HashSet<>(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 47a6ca301..d0a37ee77 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -484,7 +484,7 @@ public class PlayerEvents extends PlotListener implements Listener { pp.deleteMeta("lastplot"); return; } - Plot now = area.getPlot(loc); + Plot now = area.getPlotAbs(loc); Plot lastPlot = pp.getMeta("lastplot"); if (now == null) { if (lastPlot != null && !plotExit(pp, lastPlot)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 00c70d52d..b9374448d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -171,7 +171,6 @@ public class PS { this.IMP.registerPlayerEvents(); this.IMP.registerInventoryEvents(); this.IMP.registerPlotPlusEvents(); - this.IMP.registerForceFieldEvents(); } // Required this.IMP.registerWorldEvents(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 0ceef43dc..d895d3eb2 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -242,14 +242,11 @@ public class SpongeMain implements IPlotMain { @Override public void registerPlotPlusEvents() { - // TODO Auto-generated method stub PS.log("registerPlotPlusEvents is not implemented!"); } @Override public void registerForceFieldEvents() { - // TODO Auto-generated method stub - PS.log("registerForceFieldEvents is not implemented!"); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/ForceFieldListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/ForceFieldListener.java new file mode 100644 index 000000000..0b5e4c3ca --- /dev/null +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/ForceFieldListener.java @@ -0,0 +1,97 @@ +package com.plotsquared.sponge.listener; + +import com.flowpowered.math.vector.Vector3d; +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.plotsquared.sponge.object.SpongePlayer; +import com.plotsquared.sponge.util.SpongeUtil; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.player.Player; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class ForceFieldListener { + + private static Set getNearbyPlayers(Player player, Plot plot) { + Set players = new HashSet<>(); + for (Entity nearbyEntity : player.getNearbyEntities(entity -> entity.getType().equals(EntityTypes.PLAYER))) { + Player nearbyPlayer = (Player) nearbyEntity; + PlotPlayer plotPlayer; + if ((plotPlayer = SpongeUtil.getPlayer(nearbyPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) { + continue; + } + if (!plot.isAdded(plotPlayer.getUUID())) { + players.add(plotPlayer); + } + + } + return players; + } + + private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) { + for (Entity nearbyEntity : player.getNearbyEntities(entity -> entity.getType().equals(EntityTypes.PLAYER))) { + Player nearbyPlayer = (Player) nearbyEntity; + PlotPlayer plotPlayer; + if ((plotPlayer = SpongeUtil.getPlayer(nearbyPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) { + continue; + } + if (plot.isAdded(plotPlayer.getUUID())) { + return plotPlayer; + } + } + return null; + } + + private static Vector3d calculateVelocity(PlotPlayer player, PlotPlayer e) { + Location playerLocation = player.getLocationFull(); + Location oPlayerLocation = e.getLocation(); + double playerX = playerLocation.getX(); + double playerY = playerLocation.getY(); + double playerZ = playerLocation.getZ(); + double oPlayerX = oPlayerLocation.getX(); + double oPlayerY = oPlayerLocation.getY(); + double oPlayerZ = oPlayerLocation.getZ(); + double x = 0d; + if (playerX < oPlayerX) { + x = 1.0d; + } else if (playerX > oPlayerX) { + x = -1.0d; + } + double y = 0d; + if (playerY < oPlayerY) { + y = 0.5d; + } else if (playerY > oPlayerY) { + y = -0.5d; + } + double z = 0d; + if (playerZ < oPlayerZ) { + z = 1.0d; + } else if (playerZ > oPlayerZ) { + z = -1.0d; + } + return new Vector3d(x, y, z); + } + + public static void handleForcefield(Player player, PlotPlayer plotPlayer, Plot plot) { + if (Flags.FORCEFIELD.isTrue(plot)) { + UUID uuid = plotPlayer.getUUID(); + if (plot.isAdded(uuid)) { + Set players = getNearbyPlayers(player, plot); + for (PlotPlayer oPlayer : players) { + ((SpongePlayer) oPlayer).player.setVelocity(calculateVelocity(plotPlayer, oPlayer)); + } + } else { + PlotPlayer oPlayer = hasNearbyPermitted(player, plot); + if (oPlayer == null) { + return; + } + player.setVelocity(calculateVelocity(oPlayer, plotPlayer)); + } + } + } +} diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index cd44889ee..c2d256c30 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -662,6 +662,7 @@ public class MainListener { return; } } else if (now.equals(lastPlot)) { + ForceFieldListener.handleForcefield(player, pp, now); return; } else if (!PlotListener.plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); @@ -711,6 +712,7 @@ public class MainListener { return; } } else if (now.equals(lastPlot)) { + ForceFieldListener.handleForcefield(player, pp, now); return; } else if (!PlotListener.plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);