mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Sponge Fixes and minor changes.
This commit is contained in:
parent
5f8c77a6cd
commit
80ea3e9ce7
@ -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
|
||||
|
@ -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<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||
Set<PlotPlayer> players = new HashSet<>();
|
||||
|
@ -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)) {
|
||||
|
@ -171,7 +171,6 @@ public class PS {
|
||||
this.IMP.registerPlayerEvents();
|
||||
this.IMP.registerInventoryEvents();
|
||||
this.IMP.registerPlotPlusEvents();
|
||||
this.IMP.registerForceFieldEvents();
|
||||
}
|
||||
// Required
|
||||
this.IMP.registerWorldEvents();
|
||||
|
@ -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
|
||||
|
@ -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<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||
Set<PlotPlayer> 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<PlotPlayer> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user