diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index c062fcdc4..7b666ca2c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -46,15 +46,15 @@ import java.util.Map.Entry; import java.util.UUID; @CommandDeclaration( -command = "rate", -permission = "plots.rate", -description = "Rate the plot", -usage = "/plot rate [#|next]", -aliases = { "rt" }, -category = CommandCategory.INFO, -requiredType = RequiredType.NONE) + command = "rate", + permission = "plots.rate", + description = "Rate the plot", + usage = "/plot rate [#|next]", + aliases = {"rt"}, + category = CommandCategory.INFO, + requiredType = RequiredType.NONE) public class Rate extends SubCommand { - + @Override public boolean onCommand(final PlotPlayer player, final String[] args) { if (args.length == 1) { @@ -64,13 +64,13 @@ public class Rate extends SubCommand { @Override public int compare(final Plot p1, final Plot p2) { double v1 = 0; - double v2 = 0; - if (p1.getSettings().ratings != null) { + if (!p1.getRatings().isEmpty()) { for (final Entry entry : p1.getRatings().entrySet()) { v1 -= 11 - entry.getValue().getAverageRating(); } } - if (p2.getSettings().ratings != null) { + double v2 = 0; + if (!p2.getRatings().isEmpty()) { for (final Entry entry : p2.getRatings().entrySet()) { v2 -= 11 - entry.getValue().getAverageRating(); } @@ -83,10 +83,8 @@ public class Rate extends SubCommand { }); final UUID uuid = player.getUUID(); for (final Plot p : plots) { - if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) - && p.isBasePlot() - && ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid)) - && !p.isAdded(uuid)) { + if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) && p.isBasePlot() && (p.getRatings().isEmpty() || !p.getRatings() + .containsKey(uuid)) && !p.isAdded(uuid)) { p.teleportPlayer(player); MainUtil.sendMessage(player, C.RATE_THIS); return true; @@ -116,7 +114,7 @@ public class Rate extends SubCommand { final Runnable run = new Runnable() { @Override public void run() { - if (plot.getSettings().ratings.containsKey(player.getUUID())) { + if (plot.getRatings().containsKey(player.getUUID())) { sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } @@ -171,7 +169,7 @@ public class Rate extends SubCommand { }); return true; } - plot.getSettings().ratings = new HashMap(); + plot.getSettings().ratings = new HashMap<>(); } run.run(); return true; @@ -218,7 +216,7 @@ public class Rate extends SubCommand { }); return true; } - plot.getSettings().ratings = new HashMap(); + plot.getSettings().ratings = new HashMap<>(); } run.run(); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index dcbfa847f..373fa774a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -20,17 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.ChunkLoc; @@ -46,6 +35,17 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + @CommandDeclaration( command = "trim", permission = "plots.admin", @@ -125,7 +125,7 @@ public class Trim extends SubCommand { final ArrayList plots = new ArrayList<>(); plots.addAll(PS.get().getPlots(world)); result.value1 = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); - result.value2 = new HashSet(); + result.value2 = new HashSet<>(); MainUtil.sendMessage(null, " - MCA #: " + result.value1.size()); MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)"); MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs"); @@ -169,7 +169,7 @@ public class Trim extends SubCommand { return false; } Trim.TASK = true; - final boolean regen = args.length == 2 ? Boolean.parseBoolean(args[1]) : false; + final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]); getTrimRegions(world, new RunnableVal2, Set>() { @Override public void run(final Set viable, final Set nonViable) { @@ -178,7 +178,7 @@ public class Trim extends SubCommand { regenTask = new Runnable() { @Override public void run() { - if (nonViable.size() == 0) { + if (nonViable.isEmpty()) { Trim.TASK = false; plr.sendMessage("Trim done!"); return; diff --git a/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java index 972f43273..2f31cb58f 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/OfflinePlotPlayer.java @@ -4,14 +4,15 @@ import java.util.UUID; /** * Created 2015-02-20 for PlotSquared - * + * + */ public interface OfflinePlotPlayer { - public UUID getUUID(); + UUID getUUID(); - public long getLastPlayed(); + long getLastPlayed(); - public boolean isOnline(); + boolean isOnline(); - public String getName(); + String getName(); } diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index 07e200f09..4bf4b5838 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -53,11 +53,12 @@ public class PlotId { if (string == null) { return null; } - int x, y; final String[] parts = string.split(";"); if (parts.length < 2) { return null; } + int x; + int y; try { x = Integer.parseInt(parts[0]); y = Integer.parseInt(parts[1]); diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 37c4be8a9..03ea04bc8 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -1,13 +1,5 @@ package com.intellectualcrafters.plot.object; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.config.Settings; @@ -21,6 +13,14 @@ import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandCaller; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + /** * The PlotPlayer class
* - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations
@@ -213,10 +213,10 @@ public abstract class PlotPlayer implements CommandCaller { ////////////// PARTIALLY IMPLEMENTED /////////// /** * Get the player's last recorded location or null if they don't any plot relevant location - * @return + * @return The location */ public Location getLocation() { - final Location loc = (Location) getMeta("location"); + final Location loc = getMeta("location"); if (loc != null) { return loc; } diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 7a7cffbe7..8149b3059 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -20,16 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.util; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.regex.Matcher; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -48,6 +38,16 @@ import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.regex.Matcher; + /** * plot functions * @@ -633,13 +633,13 @@ public class MainUtil { final Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description"); final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString(); - final String flags = StringMan.replaceFromMap( - "$2" - + (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty() ? - StringMan.join(FlagManager.getPlotFlags( - - plot.getArea(), plot.getSettings(), true) - .values(), "$1, $2") : C.NONE.s()), C.replacements); + final String flags; + if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) { + flags = StringMan.replaceFromMap( + "$2" + StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "$1, $2"), C.replacements); + } else { + flags = StringMan.replaceFromMap("$2" + C.NONE.s(), C.replacements); + } final boolean build = plot.isAdded(player.getUUID()); final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners()); diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 6bc34f950..7106a597a 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,16 +1,33 @@ package com.plotsquared.bukkit.listeners; -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 com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotHandler; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotInventory; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.RegExUtil; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.object.BukkitLazyBlock; +import com.plotsquared.bukkit.object.BukkitPlayer; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.listener.PlayerBlockEventType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -89,34 +106,16 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotHandler; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotInventory; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.RegExUtil; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.bukkit.BukkitMain; -import com.plotsquared.bukkit.object.BukkitLazyBlock; -import com.plotsquared.bukkit.object.BukkitPlayer; -import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.listener.PlayerBlockEventType; +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 @@ -142,10 +141,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen PlotPlayer player = entry.getValue(); final Location loc = player.getLocation(); if (loc.getWorld().equals(world)) { - if (16 * Math.abs(loc.getX() - x) / 16 > distance) { - continue; - } - if (16 * Math.abs(loc.getZ() - z) / 16 > distance) { + if (16 * Math.abs(loc.getX() - x) / 16 > distance || 16 * Math.abs(loc.getZ() - z) / 16 > distance) { continue; } ((BukkitPlayer) player).player.sendBlockChange(bloc, type, data); @@ -234,9 +230,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPhysicsEvent(final BlockPhysicsEvent event) { - switch (event.getChangedTypeId()) { - case 149: - case 150: { + switch (event.getChangedType()) { + case REDSTONE_COMPARATOR_OFF: + case REDSTONE_COMPARATOR_ON: { final Block block = event.getBlock(); final Location loc = BukkitUtil.getLocation(block.getLocation()); PlotArea area = loc.getPlotArea(); @@ -252,10 +248,10 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } return; } - case 122: - case 145: - case 12: - case 13: + case DRAGON_EGG: + case ANVIL: + case SAND: + case GRAVEL: final Block block = event.getBlock(); final Location loc = BukkitUtil.getLocation(block.getLocation()); PlotArea area = loc.getPlotArea(); @@ -295,10 +291,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } return; } - if (plot.isAdded(pp.getUUID())) { - return; - } - if (Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) { + if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) { return; } entity.remove(); @@ -495,17 +488,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } else if (lastPlot != null && now.equals(lastPlot)) { return; - } else { - if (!plotEntry(pp, now)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!now.equals(lastPlot)) { - player.teleport(from); - } else { - player.teleport(player.getWorld().getSpawnLocation()); - } - event.setCancelled(true); - return; - } + } else if (!plotEntry(pp, now)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + player.teleport(from); + event.setCancelled(true); + return; } final Integer border = area.getBorder(); if (x2 > border) { @@ -553,17 +540,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } else if (lastPlot != null && now.equals(lastPlot)) { return; - } else { - if (!plotEntry(pp, now)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!now.equals(lastPlot)) { - player.teleport(from); - } else { - player.teleport(player.getWorld().getSpawnLocation()); - } - event.setCancelled(true); - return; - } + } else if (!plotEntry(pp, now)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + player.teleport(from); + event.setCancelled(true); + return; } final Integer border = area.getBorder(); if (z2 > border) { diff --git a/src/main/java/com/plotsquared/sponge/object/SpongeOfflinePlayer.java b/src/main/java/com/plotsquared/sponge/object/SpongeOfflinePlayer.java new file mode 100644 index 000000000..ed724bcb0 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/object/SpongeOfflinePlayer.java @@ -0,0 +1,24 @@ +package com.plotsquared.sponge.object; + +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; + +import java.util.UUID; + +public class SpongeOfflinePlayer implements OfflinePlotPlayer { + + @Override public UUID getUUID() { + return null; + } + + @Override public long getLastPlayed() { + return 0; + } + + @Override public boolean isOnline() { + return false; + } + + @Override public String getName() { + return null; + } +}