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,14 +2102,16 @@ public class PlayerEvents extends PlotListener implements Listener {
} }
Entity victim = event.getEntity(); Entity victim = event.getEntity();
if (!entityDamage(damager, victim)) { if (!entityDamage(damager, victim)) {
event.setCancelled(true); if (event.isCancelled()) {
if (victim instanceof Ageable) { if (victim instanceof Ageable) {
Ageable ageable = (Ageable) victim; Ageable ageable = (Ageable) victim;
if (ageable.getAge() == -24000) { if (ageable.getAge() == -24000) {
ageable.setAge(0); ageable.setAge(0);
ageable.setAdult(); ageable.setAdult();
}
} }
} }
event.setCancelled(true);
} }
} }

View File

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

View File

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

View File

@ -57,9 +57,13 @@ public class ExpireManager {
} }
public void handleEntry(PlotPlayer pp, Plot plot) { 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)) {
plotsToDelete.remove(plot); if (!isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) {
confirmExpiry(pp); confirmExpiry(pp);
} else {
plotsToDelete.remove(plot);
confirmExpiry(pp);
}
} }
} }
@ -69,29 +73,37 @@ public class ExpireManager {
} }
public void confirmExpiry(final PlotPlayer pp) { public void confirmExpiry(final PlotPlayer pp) {
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp if (pp.getMeta("ignoreExpireTask") != null) {
.hasPermission("plots.admin.command.autoclear")) { return;
}
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size(); 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()) { if (!isExpired(new ArrayDeque<>(tasks), current).isEmpty()) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
pp.setMeta("ignoreExpireTask", true);
pp.teleport(current.getCenter()); pp.teleport(current.getCenter());
pp.deleteMeta("ignoreExpireTask");
PlotMessage msg = new PlotMessage() 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") .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 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") .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") .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"); .tooltip("/plot set keep true");
msg.send(pp); msg.send(pp);
} }
}); });
return; return;
} else {
iter.remove();
} }
} }
plotsToDelete.clear(); 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); Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
if (gamemodeFlag.isPresent()) { if (gamemodeFlag.isPresent()) {
if (player.getGameMode() != gamemodeFlag.get()) { 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); Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
if (timeFlag.isPresent()) { if (timeFlag.isPresent()) {
try { try {
@ -200,6 +204,7 @@ public class PlotListener {
if (plot.getFlag(Flags.FLY).isPresent()) { if (plot.getFlag(Flags.FLY).isPresent()) {
if (player.hasPersistentMeta("flight")) { if (player.hasPersistentMeta("flight")) {
player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight"))); player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight")));
player.removePersistentMeta("flight");
} else { } else {
PlotGameMode gameMode = player.getGameMode(); PlotGameMode gameMode = player.getGameMode();
if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) { if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) {