diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java index d985c1b13..37038f8ca 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java @@ -6,7 +6,7 @@ public class EnclosedObject public EnclosedObject() { - this(null); + this((T) null); } public EnclosedObject(T t) @@ -23,4 +23,90 @@ public class EnclosedObject { return _value = value; } + + public String toString() + { + return _value.toString(); + } + + // Arithmetic operations, will only work if T is an instance of Number + public long Add(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).longValue() + number.longValue(); + } + + public long Subtract(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).longValue() - number.longValue(); + } + + public long Multiply(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).longValue() * number.longValue(); + } + + public long Divide(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).longValue() / number.longValue(); + } + + public double PreciseAdd(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).doubleValue() + number.doubleValue(); + } + + public double PreciseSubtract(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).doubleValue() - number.doubleValue(); + } + + public double PreciseMultiply(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).doubleValue() * number.doubleValue(); + } + + public double PreciseDivide(Number number) + { + if (!(_value instanceof Number)) + { + throw new RuntimeException("Type of T must be an instance of Number to perform arithmetic."); + } + + return ((Number) _value).doubleValue() / number.doubleValue(); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java index 287d3c1de..0e2449ea6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java @@ -6,14 +6,13 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; -import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClient; import mineplex.core.common.util.Callback; -import mineplex.core.common.util.NonFinalInteger; +import mineplex.core.common.util.EnclosedObject; +import mineplex.core.database.MinecraftRepository; import mineplex.serverdata.database.DBPool; -import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnBoolean; import mineplex.serverdata.database.column.ColumnInt; @@ -127,7 +126,7 @@ public class ClansBanRepository extends MinecraftRepository public void processResultSet(ResultSet resultSet) throws SQLException { final List clients = new ArrayList<>(); - final NonFinalInteger resultsProcessed = new NonFinalInteger(); + final EnclosedObject resultsProcessed = new EnclosedObject<>(); int resultsFound = 0; while (resultSet.next()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 332ec8f47..15ddf2aa9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -27,9 +27,9 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.ColorFader; +import mineplex.core.common.util.EnclosedObject; import mineplex.core.common.util.F; import mineplex.core.common.util.LoopIterator; -import mineplex.core.common.util.NonFinalInteger; import mineplex.core.common.util.RGBData; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; @@ -543,18 +543,18 @@ public class Outpost implements Listener { _state = OutpostState.DESTRUCTING; - NonFinalInteger wait = new NonFinalInteger(0); + EnclosedObject wait = new EnclosedObject<>(0); _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(13).forEach(block -> _outpostManager.runSyncLater(() -> { UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); - }, wait.add(4 + UtilMath.random.nextInt(4)).get()) + }, wait.Add(Integer.valueOf(4 + UtilMath.random.nextInt(4)))) ); _outpostManager.runSyncLater(() -> { _blocks.values().stream().forEach(OutpostBlock::restore); - }, wait.get() + 5L); + }, wait.Get().intValue() + 5L); _outpostManager.runSyncLater(() -> { _blocks.values().stream().forEach(block -> { @@ -578,7 +578,7 @@ public class Outpost implements Listener }); cleanup(); - }, wait.get() + 6L); + }, wait.Get().intValue() + 6L); if (_lifetimeLeft != null) _lifetimeLeft.stop();