From 0ff434cf916f300e755541c4a2835e3658db653a Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 16:49:32 +0000 Subject: [PATCH] progress --- .../mineplex/core/common/function/Result.java | 7 ++ .../core/common/util/EnclosedObject.java | 26 +++++++ .../core/common/util/NonFinalInteger.java | 33 -------- .../core/common/util/NumberFloater.java | 28 +++++++ .../core/common/util/NumericalPulser.java | 42 ---------- .../account/repository/AccountRepository.java | 18 ++--- .../src/mineplex/core/vanish/Vanish.java | 77 +++++++++++++++++++ .../core/vanish/commands/VanishCommand.java | 21 +++++ .../core/vanish/events/PreVanishEvent.java | 52 +++++++++++++ .../core/vanish/repository/VanishClient.java | 6 ++ .../vanish/repository/VanishRepository.java | 53 +++++++++++++ 11 files changed, 278 insertions(+), 85 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/function/Result.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumberFloater.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/vanish/commands/VanishCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/vanish/events/PreVanishEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishClient.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishRepository.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/function/Result.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/function/Result.java new file mode 100644 index 000000000..cb45540e3 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/function/Result.java @@ -0,0 +1,7 @@ +package mineplex.core.common.function; + +@FunctionalInterface +public interface Result +{ + public void Get(T result); +} 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 new file mode 100644 index 000000000..d985c1b13 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/EnclosedObject.java @@ -0,0 +1,26 @@ +package mineplex.core.common.util; + +public class EnclosedObject +{ + private T _value; + + public EnclosedObject() + { + this(null); + } + + public EnclosedObject(T t) + { + _value = t; + } + + public T Get() + { + return _value; + } + + public T Set(T value) + { + return _value = value; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java deleted file mode 100644 index 6638cbed9..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.common.util; - -public class NonFinalInteger -{ - private int _value; - - public NonFinalInteger() - { - this(0); - } - - public NonFinalInteger(int value) - { - _value = value; - } - - public NonFinalInteger add(int value) - { - _value += value; - return this; - } - - public NonFinalInteger subtract(int value) - { - _value -= value; - return this; - } - - public int get() - { - return _value; - } -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumberFloater.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumberFloater.java new file mode 100644 index 000000000..7a07934f5 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumberFloater.java @@ -0,0 +1,28 @@ +package mineplex.core.common.util; + +public class NumberFloater +{ + private double _min; + private double _max; + private double _modifyPerCall; + + private double _cur; + private boolean _up; + + public NumberFloater(double min, double max, double modify) + { + _min = min; + _max = max; + _modifyPerCall = modify; + } + + public double pulse() + { + if (_up && (_cur = UtilMath.clamp(_cur += _modifyPerCall, _min, _max)) >= _max) + _up = false; + else if ((_cur = UtilMath.clamp(_cur -= _modifyPerCall, _min, _max)) <= _min) + _up = true; + + return _cur; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java deleted file mode 100644 index e0de3e7d2..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java +++ /dev/null @@ -1,42 +0,0 @@ -package mineplex.core.common.util; - -public class NumericalPulser -{ - private double _min; - private double _max; - private double _modifyPerCall; - - private double _cur; - private boolean _up; - - public NumericalPulser(double min, double max, double modify) - { - _min = min; - _max = max; - _modifyPerCall = modify; - } - - public double pulse() - { - if (_up) - { - _cur = UtilMath.clamp(_cur += _modifyPerCall, _min, _max); - - if (_cur >= _max) - { - _up = false; - } - } - else - { - _cur = UtilMath.clamp(_cur -= _modifyPerCall, _min, _max); - - if (_cur <= _min) - { - _up = true; - } - } - - return _cur; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 746b3cf6b..1cd0d96cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -10,26 +10,27 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; -import mineplex.core.database.MinecraftRepository; import org.bukkit.Bukkit; -import com.google.gson.reflect.TypeToken; import org.bukkit.plugin.java.JavaPlugin; +import com.google.gson.reflect.TypeToken; + import mineplex.core.account.ILoginProcessor; import mineplex.core.account.IQuerylessLoginProcessor; import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.EnclosedObject; import mineplex.core.common.util.NautHashMap; +import mineplex.core.database.MinecraftRepository; +import mineplex.core.server.remotecall.JsonWebCall; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DatabaseRunnable; -import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnBoolean; import mineplex.serverdata.database.column.ColumnTimestamp; import mineplex.serverdata.database.column.ColumnVarChar; -import mineplex.core.server.remotecall.JsonWebCall; public class AccountRepository extends MinecraftRepository { @@ -189,7 +190,7 @@ public class AccountRepository extends MinecraftRepository public UUID getClientUUID(String name) { - final List uuids = new ArrayList(); + EnclosedObject uuid = new EnclosedObject<>(); executeQuery(SELECT_ACCOUNT_UUID_BY_NAME, new ResultSetCallable() { @@ -198,15 +199,12 @@ public class AccountRepository extends MinecraftRepository { while (resultSet.next()) { - uuids.add(UUID.fromString(resultSet.getString(1))); + uuid.Set(UUID.fromString(resultSet.getString(1))); } } }, new ColumnVarChar("name", 100, name)); - if (uuids.size() > 0) - return uuids.get(0); - else - return null; + return uuid.Get(); } public void saveRank(final Callback callback, final String name, final UUID uuid, final Rank rank, final boolean perm) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java b/Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java new file mode 100644 index 000000000..54df46561 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java @@ -0,0 +1,77 @@ +package mineplex.core.vanish; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.event.ClientWebResponseEvent; +import mineplex.core.common.util.UtilServer; +import mineplex.core.vanish.commands.VanishCommand; +import mineplex.core.vanish.events.PreVanishEvent; +import mineplex.core.vanish.repository.VanishClient; +import mineplex.core.vanish.repository.VanishRepository; + +public class Vanish extends MiniClientPlugin +{ + private CoreClientManager _clientManager; + private VanishRepository _repository; + + public Vanish(JavaPlugin plugin, CoreClientManager clientManager) + { + super("Vanish", plugin); + + _repository = new VanishRepository(this); + _clientManager = clientManager; + } + + public void addCommands() + { + addCommand(new VanishCommand(this)); + } + + public boolean toggle(Player caller) + { + boolean enabled = !Get(caller).State; + + PreVanishEvent event = new PreVanishEvent(caller, enabled);//UtilServer.callEvent(new PreVanishEvent(caller, true)); + + UtilServer.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return; + } + + Get(caller).State = enabled; + + return enabled; + } + + @EventHandler + public void ClientLoad(ClientWebResponseEvent event) + { + Get(event.get + } + + public String getQuery(int accountId, String uuid, String name) + { + return "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, enabled TINYINT(1) NOT NULL, enabledTime BIGINT)"; + } + + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + int accountId = resultSet.getInt("accountId"); + boolean enabled = resultSet.getBoolean("enabled"); + } + + protected VanishClient AddPlayer(String player) + { + return new VanishClient(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/vanish/commands/VanishCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/vanish/commands/VanishCommand.java new file mode 100644 index 000000000..e1c32da32 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/vanish/commands/VanishCommand.java @@ -0,0 +1,21 @@ +package mineplex.core.vanish.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.vanish.Vanish; + +public class VanishCommand extends CommandBase +{ + public VanishCommand(Vanish plugin) + { + super(plugin, Rank.HELPER, "incognito", "vanish"); + } + + @Override + public void Execute(Player caller, String[] args) + { + Plugin.toggle(caller); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/vanish/events/PreVanishEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/vanish/events/PreVanishEvent.java new file mode 100644 index 000000000..77cfa676a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/vanish/events/PreVanishEvent.java @@ -0,0 +1,52 @@ +package mineplex.core.vanish.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PreVanishEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private boolean _newState; + + private boolean _cancelled; + + public PreVanishEvent(Player player, boolean newState) + { + _player = player; + _newState = newState; + } + + public boolean getNewState() + { + return _newState; + } + + public Player getPlayer() + { + return _player; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishClient.java b/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishClient.java new file mode 100644 index 000000000..4d64d6960 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishClient.java @@ -0,0 +1,6 @@ +package mineplex.core.vanish.repository; + +public class VanishClient +{ + public boolean State; +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishRepository.java new file mode 100644 index 000000000..1d3cf0239 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/vanish/repository/VanishRepository.java @@ -0,0 +1,53 @@ +package mineplex.core.vanish.repository; + +import mineplex.core.common.util.EnclosedObject; +import mineplex.core.database.MinecraftRepository; +import mineplex.core.vanish.Vanish; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.column.ColumnBoolean; +import mineplex.serverdata.database.column.ColumnInt; + +public class VanishRepository extends MinecraftRepository +{ + private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, status TINYINT(1) DEFAULT '0');"; + private static final String GET_STATUS = "SELECT * FROM incognitoStaff WHERE accountId = ?;"; + private static final String SET_STATUS = "INSERT INTO incognitoStaff (accountId, status) VALUES (?, ?);"; + + private Vanish _vanish; + + public VanishRepository(Vanish vanish) + { + super(vanish.getPlugin(), DBPool.getAccount()); + + _vanish = vanish; + } + + public void setStatus(int accountId, boolean status) + { + executeUpdate(SET_STATUS, new ColumnInt("accountId", accountId), new ColumnBoolean("status", status)); + } + + public boolean getStatus(int accountId) + { + EnclosedObject status = new EnclosedObject<>(); + + executeQuery(GET_STATUS, result -> { + if (result.next()) + status.Set(Boolean.valueOf(result.getBoolean("accountId"))); + else + status.Set(Boolean.FALSE); + }, new ColumnInt("accountId", accountId)); + + return status.GetDispose().booleanValue(); + } + + protected void initialize() + { + executeUpdate(CREATE_TABLE); + } + + protected void update() + { + } + +}