fixes #763
This commit is contained in:
Jesse Boyd 2015-11-29 19:21:32 +11:00
parent c2b781da98
commit 9118f111e4
17 changed files with 100 additions and 92 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>3.2.19</version>
<version>3.2.20</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -699,7 +699,7 @@ public class PS {
try {
final ArrayList<Plot> overflow = new ArrayList<>();
if ((range > limit) && (size > 1024)) {
plots = new Plot[Math.min((int) range, limit)];
plots = new Plot[limit];
final int factor = (int) ((range / limit));
for (int i = 0; i < size; i++) {
Plot plot = list.get(i);

View File

@ -134,12 +134,9 @@ public class Info extends SubCommand {
full = false;
}
MainUtil.format(info, plot, player, full, new RunnableVal<String>() {
@Override
public void run() {
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
MainUtil.sendMessage(player, value, false);
MainUtil.sendMessage(player, C.PLOT_INFO_FOOTER);
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
}
});
return true;

View File

@ -320,6 +320,9 @@ public class MainCommand extends CommandManager<PlotPlayer> {
@Override
public int handle(final PlotPlayer plr, final String input) {
// Clear perm caching //
plr.deleteMeta("perm");
////////////////////////
final String[] parts = input.split(" ");
String[] args;
String label;

View File

@ -331,7 +331,7 @@ public class list extends SubCommand {
}
}
if (sort) {
plots = PS.get().sortPlots(plots, SortType.CREATION_DATE_TIMESTAMP, world);
plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, world);
}
if (page < 0) {
page = 0;

View File

@ -675,14 +675,18 @@ public enum C {
final Map<String, String> map = new LinkedHashMap<String, String>();
if (args.length > 0) {
for (int i = args.length - 1; i >= 0; i--) {
if (args[i] == null) {
args[i] = "";
String arg = args[i].toString();
if (arg == null || arg.length() == 0) {
map.put("%s" + i, "");
} else {
arg = C.color(arg);
map.put("%s" + i, arg);
}
if (i == 0) {
map.put("%s", arg);
}
map.put("%s" + i, args[i].toString());
}
map.put("%s", args[0].toString());
}
map.putAll(replacements);
m = StringMan.replaceFromMap(m, map);
return m;
}

View File

@ -40,7 +40,7 @@ public class Settings {
/**
* Default UUID_FECTHING: false
*/
public static boolean PERMISSION_CACHING = false;
public static boolean PERMISSION_CACHING = true;
public static boolean CACHE_RATINGS = true;
public static boolean UUID_FROM_DISK = false;

View File

@ -2819,7 +2819,7 @@ public class SQLManager implements AbstractDB {
final ConcurrentHashMap<PlotId, Plot> map = entry.getValue();
if (map.size() > 0) {
for (final Entry<PlotId, Plot> entry2 : map.entrySet()) {
PS.debug("$1Plot was deleted: " + entry.getValue() + "// TODO implement this when sure safe");
PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe");
}
}
}

View File

@ -157,8 +157,16 @@ public class FlagManager {
return result == null ? null : (Flag) result.clone();
}
/**
* Returns the raw flag<br>
* - Faster
* - You should not modify the flag
* @param plot
* @param flag
* @return
*/
public static Flag getPlotFlagRaw(final Plot plot, final String flag) {
if (!plot.hasOwner()) {
if (plot.owner == null) {
return null;
}
return getSettingFlag(plot.world, plot.getSettings(), flag);

View File

@ -63,12 +63,11 @@ public abstract class EventUtil {
public boolean checkPlayerBlockEvent(final PlotPlayer pp, final PlayerBlockEventType type, final Location loc, final LazyBlock block, boolean notifyPerms) {
final Plot plot = MainUtil.getPlotAbs(loc);
final UUID uuid = pp.getUUID();
if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) {
return true;
}
} else if (plot.isAdded(uuid)) {
} else if (plot.isAdded(pp.getUUID())) {
return true;
}
switch (type) {
@ -83,7 +82,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
final Flag use = FlagManager.getPlotFlagRaw(plot, "use");
@ -151,7 +150,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
@ -168,7 +167,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms);
}
final Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
@ -185,7 +184,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), false);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false);
}
if (FlagManager.isPlotFlagTrue(plot, "device-interact")) {
@ -194,12 +193,10 @@ public abstract class EventUtil {
final Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
final HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
long time = System.currentTimeMillis();
notifyPerms = notifyPerms && (31 * (time / 31) == time);
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
return true;
}
return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s()));
return !(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s()));
}
return true;
}
@ -207,7 +204,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) {
@ -227,7 +224,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) {
@ -247,7 +244,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) {
@ -267,7 +264,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
@ -288,7 +285,7 @@ public abstract class EventUtil {
// if (plot == null) {
// return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
// }
// if (!plot.hasOwner()) {
// if (plot.owner == null) {
// return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
// }
//
@ -306,7 +303,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}
@ -327,7 +324,7 @@ public abstract class EventUtil {
if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms);
}
if (!plot.hasOwner()) {
if (plot.owner == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
}

View File

@ -2177,18 +2177,7 @@ public class MainUtil {
* @return boolean success
*/
public static boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
if (c.s().length() > 1) {
String msg = c.s();
if ((args != null) && (args.length > 0)) {
msg = C.format(c, args);
}
if (plr == null) {
ConsolePlayer.getConsole().sendMessage(msg);
} else {
sendMessage(plr, msg, c.usePrefix());
}
}
return true;
return sendMessage(plr, c, (Object[]) args);
}
/**
@ -2200,17 +2189,23 @@ public class MainUtil {
* @return boolean success
*/
public static boolean sendMessage(final PlotPlayer plr, final C c, final Object... args) {
if (c.s().length() > 1) {
String msg = c.s();
if ((args != null) && (args.length > 0)) {
msg = C.format(c, args);
}
if (plr == null) {
ConsolePlayer.getConsole().sendMessage(msg);
} else {
sendMessage(plr, msg, c.usePrefix());
}
if (c.s().length() == 0) {
return true;
}
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
String msg = c.s();
if (args.length != 0) {
msg = c.format(c, args);
}
if (plr != null) {
plr.sendMessage((c.usePrefix() ? C.PREFIX.s() + msg : msg));
} else {
ConsolePlayer.getConsole().sendMessage((c.usePrefix() ? C.PREFIX.s() : "") + msg);
}
}
});
return true;
}

View File

@ -1,6 +1,9 @@
package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandCaller;
@ -10,7 +13,22 @@ public class Permissions {
}
public static boolean hasPermission(final PlotPlayer player, final String perm) {
return hasPermission((CommandCaller) player, perm);
if (!Settings.PERMISSION_CACHING) {
return hasPermission((CommandCaller) player, perm);
}
HashMap<String, Boolean> map = (HashMap<String, Boolean>) player.getMeta("perm");
if (map != null) {
Boolean result = map.get(perm);
if (result != null) {
return result;
}
} else {
map = new HashMap<>();
player.setMeta("perm", map);
}
boolean result = hasPermission((CommandCaller) player, perm);
map.put(perm, result);
return result;
}
public static boolean hasPermission(final CommandCaller player, String perm) {

View File

@ -116,11 +116,11 @@ public abstract class UUIDHandlerImplementation {
offline = null;
}
}
if (offline != null) {
if (offline != null && !offline.equals(uuid)) {
unknown.remove(offline);
final Set<Plot> plots = PS.get().getPlots(offline);
if (plots.size() > 0) {
for (final Plot plot : PS.get().getPlots(offline)) {
for (final Plot plot : plots) {
plot.owner = uuid;
}
DBFunc.replaceUUID(offline, uuid);
@ -136,7 +136,7 @@ public abstract class UUIDHandlerImplementation {
if (!offline.equals(uuid)) {
final Set<Plot> plots = PS.get().getPlots(offline);
if (plots.size() > 0) {
for (final Plot plot : PS.get().getPlots(offline)) {
for (final Plot plot : plots) {
plot.owner = uuid;
}
DBFunc.replaceUUID(offline, uuid);

View File

@ -334,7 +334,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
}
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final BukkitPlayer pp = (BukkitPlayer) BukkitUtil.getPlayer(player);
Plot plot = pp.getCurrentPlot();
if (plot == null) {
return;
@ -1035,27 +1035,26 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(final PlayerInteractEvent event) {
final Action action = event.getAction();
final Block block = event.getClickedBlock();
if (block == null) {
return;
}
final Player player = event.getPlayer();
final String world = player.getWorld().getName();
if (!PS.get().isPlotWorld(world)) {
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (pp.getPlotWorld() == null) {
return;
}
final Location loc = BukkitUtil.getLocation(block.getLocation());
final PlotPlayer pp = BukkitUtil.getPlayer(player);
PlayerBlockEventType eventType = null;
BukkitLazyBlock lb;
Location loc;
final Action action = event.getAction();
switch (action) {
case PHYSICAL: {
eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
Block block = event.getClickedBlock();
lb = new BukkitLazyBlock(block);
loc = BukkitUtil.getLocation(block.getLocation());
break;
}
case RIGHT_CLICK_BLOCK: {
Block block = event.getClickedBlock();
loc = BukkitUtil.getLocation(block.getLocation());
final Material blockType = block.getType();
final int blockId = blockType.getId();
switch (blockType) {
@ -1137,8 +1136,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
lb = new BukkitLazyBlock(id, block);
break;
}
lb = new BukkitLazyBlock(new PlotBlock((short) hand.getTypeId(), (byte) hand.getDurability()));
switch (hand.getType()) {
Material handType = hand.getType();
lb = new BukkitLazyBlock(new PlotBlock((short) handType.getId(), (byte) 0));
switch (handType) {
case MONSTER_EGG:
case MONSTER_EGGS: {
eventType = PlayerBlockEventType.SPAWN_MOB;
@ -1181,7 +1181,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
eventType = PlayerBlockEventType.EAT;
break;
}
case MINECART:
case STORAGE_MINECART:
case POWERED_MINECART:
@ -1205,6 +1204,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
break;
}
case LEFT_CLICK_BLOCK: {
Block block = event.getClickedBlock();
loc = BukkitUtil.getLocation(block.getLocation());
eventType = PlayerBlockEventType.BREAK_BLOCK;
lb = new BukkitLazyBlock(block);
break;

View File

@ -7,7 +7,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
public class BukkitLazyBlock extends LazyBlock {
private int id = -1;
private int id;
private Block block;
private PlotBlock pb;
@ -30,7 +30,7 @@ public class BukkitLazyBlock extends LazyBlock {
if (pb != null) {
return pb;
}
if (id == -1) {
if (id == 0) {
id = block.getTypeId();
}
byte data;
@ -121,8 +121,10 @@ public class BukkitLazyBlock extends LazyBlock {
case 191:
case 192:
data = 0;
break;
default:
data = block.getData();
break;
}
pb = new PlotBlock((short) id, data);
return pb;
@ -131,7 +133,7 @@ public class BukkitLazyBlock extends LazyBlock {
@Override
public int getId() {
if (id == -1) {
if (id == 0) {
id = block.getTypeId();
}
return id;

View File

@ -14,7 +14,6 @@ import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
@ -71,26 +70,10 @@ public class BukkitPlayer extends PlotPlayer {
@Override
public boolean hasPermission(final String node) {
if (Settings.PERMISSION_CACHING) {
if (noPerm.contains(node)) {
return false;
}
if (hasPerm.contains(node)) {
return true;
}
}
if (offline && (EconHandler.manager != null)) {
return EconHandler.manager.hasPermission(getName(), node);
}
final boolean value = player.hasPermission(node);
if (Settings.PERMISSION_CACHING) {
if (value) {
hasPerm.add(node);
} else {
noPerm.add(node);
}
}
return value;
return player.hasPermission(node);
}
public Permission getPermission(final String node) {

Binary file not shown.