This commit is contained in:
Matt 2016-02-20 16:50:10 -05:00
parent 36ebd1983d
commit ef5846f688
8 changed files with 146 additions and 141 deletions

View File

@ -46,15 +46,15 @@ import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "rate", command = "rate",
permission = "plots.rate", permission = "plots.rate",
description = "Rate the plot", description = "Rate the plot",
usage = "/plot rate [#|next]", usage = "/plot rate [#|next]",
aliases = { "rt" }, aliases = {"rt"},
category = CommandCategory.INFO, category = CommandCategory.INFO,
requiredType = RequiredType.NONE) requiredType = RequiredType.NONE)
public class Rate extends SubCommand { public class Rate extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String[] args) { public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 1) { if (args.length == 1) {
@ -64,13 +64,13 @@ public class Rate extends SubCommand {
@Override @Override
public int compare(final Plot p1, final Plot p2) { public int compare(final Plot p1, final Plot p2) {
double v1 = 0; double v1 = 0;
double v2 = 0; if (!p1.getRatings().isEmpty()) {
if (p1.getSettings().ratings != null) {
for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating(); v1 -= 11 - entry.getValue().getAverageRating();
} }
} }
if (p2.getSettings().ratings != null) { double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet()) { for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating(); v2 -= 11 - entry.getValue().getAverageRating();
} }
@ -83,10 +83,8 @@ public class Rate extends SubCommand {
}); });
final UUID uuid = player.getUUID(); final UUID uuid = player.getUUID();
for (final Plot p : plots) { for (final Plot p : plots) {
if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) && p.isBasePlot() && (p.getRatings().isEmpty() || !p.getRatings()
&& p.isBasePlot() .containsKey(uuid)) && !p.isAdded(uuid)) {
&& ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid))
&& !p.isAdded(uuid)) {
p.teleportPlayer(player); p.teleportPlayer(player);
MainUtil.sendMessage(player, C.RATE_THIS); MainUtil.sendMessage(player, C.RATE_THIS);
return true; return true;
@ -116,7 +114,7 @@ public class Rate extends SubCommand {
final Runnable run = new Runnable() { final Runnable run = new Runnable() {
@Override @Override
public void run() { 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()); sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return; return;
} }
@ -171,7 +169,7 @@ public class Rate extends SubCommand {
}); });
return true; return true;
} }
plot.getSettings().ratings = new HashMap<UUID, Integer>(); plot.getSettings().ratings = new HashMap<>();
} }
run.run(); run.run();
return true; return true;
@ -218,7 +216,7 @@ public class Rate extends SubCommand {
}); });
return true; return true;
} }
plot.getSettings().ratings = new HashMap<UUID, Integer>(); plot.getSettings().ratings = new HashMap<>();
} }
run.run(); run.run();
return true; return true;

View File

@ -20,17 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; 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.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
@ -46,6 +35,17 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; 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( @CommandDeclaration(
command = "trim", command = "trim",
permission = "plots.admin", permission = "plots.admin",
@ -125,7 +125,7 @@ public class Trim extends SubCommand {
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PS.get().getPlots(world)); plots.addAll(PS.get().getPlots(world));
result.value1 = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); result.value1 = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
result.value2 = new HashSet<ChunkLoc>(); result.value2 = new HashSet<>();
MainUtil.sendMessage(null, " - MCA #: " + result.value1.size()); MainUtil.sendMessage(null, " - MCA #: " + result.value1.size());
MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)"); MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)");
MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs"); MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs");
@ -169,7 +169,7 @@ public class Trim extends SubCommand {
return false; return false;
} }
Trim.TASK = true; 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<ChunkLoc>, Set<ChunkLoc>>() { getTrimRegions(world, new RunnableVal2<Set<ChunkLoc>, Set<ChunkLoc>>() {
@Override @Override
public void run(final Set<ChunkLoc> viable, final Set<ChunkLoc> nonViable) { public void run(final Set<ChunkLoc> viable, final Set<ChunkLoc> nonViable) {
@ -178,7 +178,7 @@ public class Trim extends SubCommand {
regenTask = new Runnable() { regenTask = new Runnable() {
@Override @Override
public void run() { public void run() {
if (nonViable.size() == 0) { if (nonViable.isEmpty()) {
Trim.TASK = false; Trim.TASK = false;
plr.sendMessage("Trim done!"); plr.sendMessage("Trim done!");
return; return;

View File

@ -4,14 +4,15 @@ import java.util.UUID;
/** /**
* Created 2015-02-20 for PlotSquared * Created 2015-02-20 for PlotSquared
* *
*/ */
public interface OfflinePlotPlayer { public interface OfflinePlotPlayer {
public UUID getUUID(); UUID getUUID();
public long getLastPlayed(); long getLastPlayed();
public boolean isOnline(); boolean isOnline();
public String getName(); String getName();
} }

View File

@ -53,11 +53,12 @@ public class PlotId {
if (string == null) { if (string == null) {
return null; return null;
} }
int x, y;
final String[] parts = string.split(";"); final String[] parts = string.split(";");
if (parts.length < 2) { if (parts.length < 2) {
return null; return null;
} }
int x;
int y;
try { try {
x = Integer.parseInt(parts[0]); x = Integer.parseInt(parts[0]);
y = Integer.parseInt(parts[1]); y = Integer.parseInt(parts[1]);

View File

@ -1,13 +1,5 @@
package com.intellectualcrafters.plot.object; 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.PS;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -21,6 +13,14 @@ import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandCaller; 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<br> * The PlotPlayer class<br>
* - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations<br> * - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations<br>
@ -213,10 +213,10 @@ public abstract class PlotPlayer implements CommandCaller {
////////////// PARTIALLY IMPLEMENTED /////////// ////////////// PARTIALLY IMPLEMENTED ///////////
/** /**
* Get the player's last recorded location or null if they don't any plot relevant location * Get the player's last recorded location or null if they don't any plot relevant location
* @return * @return The location
*/ */
public Location getLocation() { public Location getLocation() {
final Location loc = (Location) getMeta("location"); final Location loc = getMeta("location");
if (loc != null) { if (loc != null) {
return loc; return loc;
} }

View File

@ -20,16 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util; 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.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; 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.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; 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 * plot functions
* *
@ -633,13 +633,13 @@ public class MainUtil {
final Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description"); final Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description");
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString(); final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
final String flags = StringMan.replaceFromMap( final String flags;
"$2" if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) {
+ (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty() ? flags = StringMan.replaceFromMap(
StringMan.join(FlagManager.getPlotFlags( "$2" + StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "$1, $2"), C.replacements);
} else {
plot.getArea(), plot.getSettings(), true) flags = StringMan.replaceFromMap("$2" + C.NONE.s(), C.replacements);
.values(), "$1, $2") : C.NONE.s()), C.replacements); }
final boolean build = plot.isAdded(player.getUUID()); final boolean build = plot.isAdded(player.getUUID());
final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners()); final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());

View File

@ -1,16 +1,33 @@
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import java.util.ArrayList; import com.intellectualcrafters.plot.PS;
import java.util.Arrays; import com.intellectualcrafters.plot.config.C;
import java.util.HashSet; import com.intellectualcrafters.plot.config.Settings;
import java.util.Iterator; import com.intellectualcrafters.plot.flag.Flag;
import java.util.List; import com.intellectualcrafters.plot.flag.FlagManager;
import java.util.Map.Entry; import com.intellectualcrafters.plot.object.Location;
import java.util.Objects; import com.intellectualcrafters.plot.object.Plot;
import java.util.Set; import com.intellectualcrafters.plot.object.PlotArea;
import java.util.UUID; import com.intellectualcrafters.plot.object.PlotBlock;
import java.util.regex.Pattern; 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.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -89,34 +106,16 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.PS; import java.util.ArrayList;
import com.intellectualcrafters.plot.config.C; import java.util.Arrays;
import com.intellectualcrafters.plot.config.Settings; import java.util.HashSet;
import com.intellectualcrafters.plot.flag.Flag; import java.util.Iterator;
import com.intellectualcrafters.plot.flag.FlagManager; import java.util.List;
import com.intellectualcrafters.plot.object.Location; import java.util.Map.Entry;
import com.intellectualcrafters.plot.object.Plot; import java.util.Objects;
import com.intellectualcrafters.plot.object.PlotArea; import java.util.Set;
import com.intellectualcrafters.plot.object.PlotBlock; import java.util.UUID;
import com.intellectualcrafters.plot.object.PlotHandler; import java.util.regex.Pattern;
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;
/** /**
* Player Events involving plots * Player Events involving plots
@ -142,10 +141,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
PlotPlayer player = entry.getValue(); PlotPlayer player = entry.getValue();
final Location loc = player.getLocation(); final Location loc = player.getLocation();
if (loc.getWorld().equals(world)) { if (loc.getWorld().equals(world)) {
if (16 * Math.abs(loc.getX() - x) / 16 > distance) { if (16 * Math.abs(loc.getX() - x) / 16 > distance || 16 * Math.abs(loc.getZ() - z) / 16 > distance) {
continue;
}
if (16 * Math.abs(loc.getZ() - z) / 16 > distance) {
continue; continue;
} }
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data); ((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) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPhysicsEvent(final BlockPhysicsEvent event) { public void onPhysicsEvent(final BlockPhysicsEvent event) {
switch (event.getChangedTypeId()) { switch (event.getChangedType()) {
case 149: case REDSTONE_COMPARATOR_OFF:
case 150: { case REDSTONE_COMPARATOR_ON: {
final Block block = event.getBlock(); final Block block = event.getBlock();
final Location loc = BukkitUtil.getLocation(block.getLocation()); final Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
@ -252,10 +248,10 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
return; return;
} }
case 122: case DRAGON_EGG:
case 145: case ANVIL:
case 12: case SAND:
case 13: case GRAVEL:
final Block block = event.getBlock(); final Block block = event.getBlock();
final Location loc = BukkitUtil.getLocation(block.getLocation()); final Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
@ -295,10 +291,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
return; return;
} }
if (plot.isAdded(pp.getUUID())) { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
return;
}
if (Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) {
return; return;
} }
entity.remove(); entity.remove();
@ -495,17 +488,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
} else if (lastPlot != null && now.equals(lastPlot)) { } else if (lastPlot != null && now.equals(lastPlot)) {
return; return;
} else { } else if (!plotEntry(pp, now)) {
if (!plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); player.teleport(from);
if (!now.equals(lastPlot)) { event.setCancelled(true);
player.teleport(from); return;
} else {
player.teleport(player.getWorld().getSpawnLocation());
}
event.setCancelled(true);
return;
}
} }
final Integer border = area.getBorder(); final Integer border = area.getBorder();
if (x2 > border) { if (x2 > border) {
@ -553,17 +540,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
} else if (lastPlot != null && now.equals(lastPlot)) { } else if (lastPlot != null && now.equals(lastPlot)) {
return; return;
} else { } else if (!plotEntry(pp, now)) {
if (!plotEntry(pp, now)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); player.teleport(from);
if (!now.equals(lastPlot)) { event.setCancelled(true);
player.teleport(from); return;
} else {
player.teleport(player.getWorld().getSpawnLocation());
}
event.setCancelled(true);
return;
}
} }
final Integer border = area.getBorder(); final Integer border = area.getBorder();
if (z2 > border) { if (z2 > border) {

View File

@ -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;
}
}