From c7b9bfeb4b7d3b52c567da58500789900af93d61 Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Wed, 2 Jan 2019 23:11:26 -0500 Subject: [PATCH 1/2] Migrate from Guava Optionals to Java Optionals --- .../bukkit/listeners/PlayerEvents.java | 5 +- .../bukkit/listeners/PlotPlusListener.java | 14 ++- .../plotsquared/plot/commands/Buy.java | 2 +- .../plotsquared/plot/commands/FlagCmd.java | 1 - .../plotsquared/plot/commands/ListCmd.java | 6 +- .../plotsquared/plot/flag/FlagManager.java | 33 +------ .../plot/listener/PlotListener.java | 16 ++-- .../plotsquared/plot/object/Plot.java | 1 - .../plotsquared/plot/util/EventUtil.java | 85 +++++-------------- .../plotsquared/plot/util/MainUtil.java | 1 - .../plot/util/expiry/ExpireManager.java | 1 - .../plot/util/expiry/PlotAnalysis.java | 1 - .../plotsquared/plot/FlagTest.java | 6 +- 13 files changed, 40 insertions(+), 132 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 27376e138..d1b132528 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventTy import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.*; -import com.google.common.base.Optional; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -1693,7 +1692,7 @@ import java.util.regex.Pattern; return; } Plot plot = area.getOwnedPlot(location); - if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) { + if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) { event.setCancelled(true); } event.blockList().removeIf( @@ -2170,7 +2169,7 @@ import java.util.regex.Pattern; || !plotIgnited.equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( - !plot.getFlag(Flags.BLOCK_IGNITION).or(false) || plotIgnited == null + !plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null || !plotIgnited.equals(plot))) { event.setCancelled(true); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java index 929391143..a4df7c6b3 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.google.common.base.Optional; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.block.Block; @@ -28,6 +27,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; +import java.util.Optional; import java.util.UUID; @SuppressWarnings("unused") @@ -139,15 +139,11 @@ public class PlotPlusListener extends PlotListener implements Listener { Player player = event.getPlayer(); Plot plot = event.getPlot(); Optional feed = plot.getFlag(Flags.FEED); - if (feed.isPresent()) { - Integer[] value = feed.get(); - feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)); - } + feed.ifPresent( value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)) + ); Optional heal = plot.getFlag(Flags.HEAL); - if (heal.isPresent()) { - Integer[] value = heal.get(); - healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)); - } + heal.ifPresent( value -> healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)) + ); } @EventHandler diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index af552ec67..25f9484b1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -11,8 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import com.google.common.base.Optional; +import java.util.Optional; import java.util.Set; @CommandDeclaration(command = "buy", description = "Buy the plot you are standing on", diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index d7ab4e9cd..d1e8c9d04 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.*; -import com.google.common.base.Optional; import java.util.*; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index 472103853..9df74d30b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -8,7 +8,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import com.google.common.base.Optional; import java.util.*; import java.util.Map.Entry; @@ -162,10 +161,9 @@ public class ListCmd extends SubCommand { plots = new ArrayList<>(); for (Plot plot : PlotSquared.get().getPlots()) { Optional flag = plot.getFlag(Flags.DONE); - if (!flag.isPresent()) { - continue; + if (flag.isPresent()) { + plots.add(plot); } - plots.add(plot); } Collections.sort(plots, new Comparator() { @Override public int compare(Plot a, Plot b) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java index c52b77f44..06be89e15 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/FlagManager.java @@ -5,10 +5,8 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; -import java.lang.reflect.Field; import java.util.*; /** @@ -16,38 +14,9 @@ import java.util.*; */ public class FlagManager { - - /** - * Some events can be called millions of times each second (e.g. physics) - * and reusing is a lot faster. - */ - private static final Optional MUTABLE_OPTIONAL; - private static Field MUTABLE_OPTIONAL_FIELD; - - static { - MUTABLE_OPTIONAL = Optional.of(new Object()); - try { - MUTABLE_OPTIONAL_FIELD = MUTABLE_OPTIONAL.getClass().getDeclaredField("reference"); - MUTABLE_OPTIONAL_FIELD.setAccessible(true); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - } - public static Optional getPlotFlag(Plot plot, Flag key) { V value = FlagManager.getPlotFlagRaw(plot, key); - if (value != null) { - if (PlotSquared.get().isMainThread(Thread.currentThread())) { - try { - MUTABLE_OPTIONAL_FIELD.set(MUTABLE_OPTIONAL, value); - return MUTABLE_OPTIONAL; - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - return Optional.of(value); - } - return Optional.absent(); + return Optional.ofNullable(value); } /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index 5f056a0bd..64b4adcaa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -8,10 +8,10 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import com.google.common.base.Optional; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.UUID; public class PlotListener { @@ -122,9 +122,8 @@ public class PlotListener { } } Optional weatherFlag = plot.getFlag(Flags.WEATHER); - if (weatherFlag.isPresent()) { - player.setWeather(weatherFlag.get()); - } Optional musicFlag = plot.getFlag(Flags.MUSIC); + weatherFlag.ifPresent(player::setWeather); + Optional musicFlag = plot.getFlag(Flags.MUSIC); if (musicFlag.isPresent()) { final String id = musicFlag.get(); final PlotBlock block = PlotBlock.get(id); @@ -211,14 +210,13 @@ public class PlotListener { } } Optional farewell = plot.getFlag(Flags.FAREWELL); - if (farewell.isPresent()) { - MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, player, false, + farewell.ifPresent(s -> MainUtil.format(C.PREFIX_FAREWELL.s() + s, plot, player, false, new RunnableVal() { - @Override public void run(String value) { + @Override + public void run(String value) { MainUtil.sendMessage(player, value); } - }); - } + })); Optional leave = plot.getFlag(Flags.NOTIFY_LEAVE); if (leave.isPresent() && leave.get()) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 994557f1c..ef5277bdc 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -16,7 +16,6 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; -import com.google.common.base.Optional; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableSet; import com.sk89q.jnbt.CompoundTag; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index 1a7d8bb8c..4773d1696 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -8,11 +8,11 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import com.google.common.base.Optional; import javax.annotation.Nullable; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.UUID; public abstract class EventUtil { @@ -154,7 +154,7 @@ public abstract class EventUtil { return Permissions .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (plot.getFlag(Flags.HANGING_BREAK).or(false)) { + if (plot.getFlag(Flags.HANGING_BREAK).orElse(false)) { return true; } if (plot.hasOwner()) { @@ -170,7 +170,7 @@ public abstract class EventUtil { return Permissions .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (plot.getFlag(Flags.MISC_BREAK).or(false)) { + if (plot.getFlag(Flags.MISC_BREAK).orElse(false)) { return true; } if (plot.hasOwner()) { @@ -186,7 +186,7 @@ public abstract class EventUtil { return Permissions .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) { + if (plot.getFlag(Flags.VEHICLE_BREAK).orElse(false)) { return true; } if (plot.hasOwner()) { @@ -210,12 +210,7 @@ public abstract class EventUtil { notifyPerms); } Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value; - if (flagValue.isPresent()) { - value = flagValue.get(); - } else { - value = null; - } + HashSet value = flagValue.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { return Permissions @@ -235,12 +230,7 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms); } Optional> flagValue = plot.getFlag(Flags.PLACE); - HashSet value; - if (flagValue.isPresent()) { - value = flagValue.get(); - } else { - value = null; - } + HashSet value = flagValue.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -261,16 +251,11 @@ public abstract class EventUtil { return Permissions .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false); } - if (plot.getFlag(Flags.DEVICE_INTERACT).or(false)) { + if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) { return true; } Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value; - if (flagValue.isPresent()) { - value = flagValue.get(); - } else { - value = null; - } + HashSet value = flagValue.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -291,16 +276,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) { + if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) { return true; } Optional> flagValue = plot.getFlag(Flags.USE); - HashSet value; - if (flagValue.isPresent()) { - value = flagValue.get(); - } else { - value = null; - } + HashSet value = flagValue.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -322,16 +302,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.MISC_INTERACT).or(false)) { + if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) { return true; } Optional> flag = plot.getFlag(Flags.USE); - HashSet value; - if (flag.isPresent()) { - value = flag.get(); - } else { - value = null; - } + HashSet value = flag.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -353,16 +328,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.VEHICLE_USE).or(false)) { + if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) { return true; } Optional> flag = plot.getFlag(Flags.USE); - HashSet value; - if (flag.isPresent()) { - value = flag.get(); - } else { - value = null; - } + HashSet value = flag.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -384,16 +354,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.MOB_PLACE).or(false)) { + if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) { return true; } Optional> flagValue = plot.getFlag(Flags.PLACE); - HashSet value; - if (flagValue.isPresent()) { - value = flagValue.get(); - } else { - value = null; - } + HashSet value = flagValue.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -417,16 +382,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.MISC_PLACE).or(false)) { + if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) { return true; } Optional> flag = plot.getFlag(Flags.PLACE); - HashSet value; - if (flag.isPresent()) { - value = flag.get(); - } else { - value = null; - } + HashSet value = flag.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions @@ -449,16 +409,11 @@ public abstract class EventUtil { .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.VEHICLE_PLACE).or(false)) { + if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) { return true; } Optional> flag = plot.getFlag(Flags.PLACE); - HashSet value; - if (flag.isPresent()) { - value = flag.get(); - } else { - value = null; - } + HashSet value = flag.orElse(null); if (value == null || !PlotBlock.containsEverything(value) && !value .contains(block.getPlotBlock())) { if (Permissions diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index ad4d22847..5cbecb16d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.stream.AbstractDelegateOutputStream; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import com.google.common.base.Optional; import java.io.*; import java.net.HttpURLConnection; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java index b15877936..84f86daa2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java @@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import com.google.common.base.Optional; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java index 118cda789..b17f3ce47 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java @@ -8,7 +8,6 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.google.common.base.Optional; import java.lang.reflect.Array; import java.util.*; diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index cab3040ec..c2b81a729 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -9,12 +9,12 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest; -import com.google.common.base.Optional; import org.junit.Before; import org.junit.Test; import java.util.Collection; import java.util.HashSet; +import java.util.Optional; import java.util.UUID; import static org.junit.Assert.assertEquals; @@ -39,9 +39,7 @@ public class FlagTest { testBlock = PlotBlock.get((short) 1, (byte) 0); flag.get().add(testBlock); } - if (flag.isPresent()) { - System.out.println(Flags.USE.valueToString(flag.get())); - } + flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); Optional> flag2 = plot.getFlag(Flags.USE); if (flag2.isPresent()) { // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); From e12a7bb85f08e622e872334388ae478316e5fb02 Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Wed, 2 Jan 2019 23:15:42 -0500 Subject: [PATCH 2/2] Migrated remaining Optionals --- .../intellectualsites/plotsquared/plot/commands/Inbox.java | 2 +- .../plotsquared/plot/object/PlotSettings.java | 3 +-- .../plotsquared/plot/object/comment/InboxOwner.java | 2 +- .../plotsquared/plot/object/comment/InboxPublic.java | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java index bf1bb74be..5c7cfc0ac 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Inbox.java @@ -10,10 +10,10 @@ import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.util.CommentManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.google.common.base.Optional; import java.util.ArrayList; import java.util.List; +import java.util.Optional; @CommandDeclaration(command = "inbox", description = "Review the comments for a plot", usage = "/plot inbox [inbox] [delete |clear|page]", permission = "plots.inbox", diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java index 2eadd85ff..4f3701f56 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java @@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; -import com.google.common.base.Optional; import java.util.*; @@ -146,7 +145,7 @@ public class PlotSettings { public Optional> getComments(String inbox) { ArrayList c = new ArrayList<>(); if (this.comments == null) { - return Optional.absent(); + return Optional.empty(); } for (PlotComment comment : this.comments) { if (comment.inbox.equals(inbox)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxOwner.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxOwner.java index d15f194ba..d3a80013e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxOwner.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxOwner.java @@ -4,10 +4,10 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.google.common.base.Optional; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class InboxOwner extends CommentInbox { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxPublic.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxPublic.java index 2d94026f4..a14954e28 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxPublic.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/comment/InboxPublic.java @@ -4,10 +4,10 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.google.common.base.Optional; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class InboxPublic extends CommentInbox {