Fixes #1177
Additional check for left click with milk on adult entity
Add setting for enabling persistent meta
Only set fly persistent meta if it differs from the current gamemode fly
mode.
This commit is contained in:
Jesse Boyd 2016-06-16 20:16:48 +10:00
parent 28ad14500a
commit 480453b716
5 changed files with 58 additions and 31 deletions

View File

@ -2102,7 +2102,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Entity victim = event.getEntity();
if (!entityDamage(damager, victim)) {
event.setCancelled(true);
if (event.isCancelled()) {
if (victim instanceof Ageable) {
Ageable ageable = (Ageable) victim;
if (ageable.getAge() == -24000) {
@ -2111,6 +2111,8 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
}
event.setCancelled(true);
}
}
public boolean entityDamage(Entity damager, Entity victim) {

View File

@ -285,6 +285,8 @@ public class Settings extends Config {
public static boolean UUID_CACHE = true;
@Comment("Notify players of updates")
public static boolean UPDATER = true;
@Comment("Stores user metadata in a database")
public static boolean PERSISTENT_META = true;
@Comment("Optimizes permission checks")
public static boolean PERMISSION_CACHE = true;
@Comment("Optimizes block changing code")

View File

@ -415,6 +415,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
}
public void populatePersistentMetaMap() {
if (Settings.Enabled_Components.PERSISTENT_META) {
DBFunc.getPersistentMeta(getUUID(), new RunnableVal<Map<String, byte[]>>() {
@Override
public void run(Map<String, byte[]> value) {
@ -422,6 +423,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
}
});
}
}
public byte[] getPersistentMeta(String key) {
return this.metaMap.get(key);
@ -431,14 +433,18 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
if (this.metaMap.containsKey(key)) {
this.metaMap.remove(key);
}
if (Settings.Enabled_Components.PERSISTENT_META) {
DBFunc.removePersistentMeta(getUUID(), key);
}
}
public void setPersistentMeta(String key, byte[] value) {
boolean delete = hasPersistentMeta(key);
this.metaMap.put(key, value);
if (Settings.Enabled_Components.PERSISTENT_META) {
DBFunc.addPersistentMeta(getUUID(), key, value, delete);
}
}
public boolean hasPersistentMeta(String key) {
return this.metaMap.containsKey(key);

View File

@ -57,11 +57,15 @@ public class ExpireManager {
}
public void handleEntry(PlotPlayer pp, Plot plot) {
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear") && plotsToDelete.contains(plot) && !isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) {
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear") && plotsToDelete.contains(plot)) {
if (!isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) {
confirmExpiry(pp);
} else {
plotsToDelete.remove(plot);
confirmExpiry(pp);
}
}
}
public long getTimestamp(UUID uuid) {
Long value = this.dates_cache.get(uuid);
@ -69,29 +73,37 @@ public class ExpireManager {
}
public void confirmExpiry(final PlotPlayer pp) {
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp
.hasPermission("plots.admin.command.autoclear")) {
if (pp.getMeta("ignoreExpireTask") != null) {
return;
}
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size();
for (final Plot current : plotsToDelete) {
while (!plotsToDelete.isEmpty()) {
Iterator<Plot> iter = plotsToDelete.iterator();
final Plot current = iter.next();
if (!isExpired(new ArrayDeque<>(tasks), current).isEmpty()) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
pp.setMeta("ignoreExpireTask", true);
pp.teleport(current.getCenter());
pp.deleteMeta("ignoreExpireTask");
PlotMessage msg = new PlotMessage()
.text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired")
.text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired: ").color("$1").text(current.toString()).color("$2").suggest("/plot list expired")
.tooltip("/plot list expired")
//.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired")
.text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete")
.text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").suggest("/plot delete")
.tooltip("/plot delete")
.text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d")
.text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").suggest("/plot set keep 1d")
.tooltip("/plot set keep 1d")
.text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true")
.text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").suggest("/plot set keep true")
.tooltip("/plot set keep true");
msg.send(pp);
}
});
return;
} else {
iter.remove();
}
}
plotsToDelete.clear();

View File

@ -72,6 +72,17 @@ public class PlotListener {
}
}
}
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag.isPresent()) {
boolean flight = player.getFlight();
if (flyFlag.get() != player.getFlight()) {
PlotGameMode gamemode = player.getGameMode();
if (flight != (gamemode == PlotGameMode.CREATIVE || gamemode == PlotGameMode.SPECTATOR)) {
player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight()));
}
player.setFlight(flyFlag.get());
}
}
Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
if (gamemodeFlag.isPresent()) {
if (player.getGameMode() != gamemodeFlag.get()) {
@ -83,13 +94,6 @@ public class PlotListener {
}
}
}
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag.isPresent()) {
if (flyFlag.get() != player.getFlight()) {
player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight()));
player.setFlight(flyFlag.get());
}
}
Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
if (timeFlag.isPresent()) {
try {
@ -200,6 +204,7 @@ public class PlotListener {
if (plot.getFlag(Flags.FLY).isPresent()) {
if (player.hasPersistentMeta("flight")) {
player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight")));
player.removePersistentMeta("flight");
} else {
PlotGameMode gameMode = player.getGameMode();
if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) {