This commit is contained in:
Ben 2016-03-08 16:49:32 +00:00
parent d108679d43
commit 0ff434cf91
11 changed files with 278 additions and 85 deletions

View File

@ -0,0 +1,7 @@
package mineplex.core.common.function;
@FunctionalInterface
public interface Result<T>
{
public void Get(T result);
}

View File

@ -0,0 +1,26 @@
package mineplex.core.common.util;
public class EnclosedObject<T>
{
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -10,26 +10,27 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.google.gson.reflect.TypeToken;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.reflect.TypeToken;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.IQuerylessLoginProcessor; import mineplex.core.account.IQuerylessLoginProcessor;
import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.LoginToken;
import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.EnclosedObject;
import mineplex.core.common.util.NautHashMap; 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.DBPool;
import mineplex.serverdata.database.DatabaseRunnable; import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnBoolean; import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnTimestamp; import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.server.remotecall.JsonWebCall;
public class AccountRepository extends MinecraftRepository public class AccountRepository extends MinecraftRepository
{ {
@ -189,7 +190,7 @@ public class AccountRepository extends MinecraftRepository
public UUID getClientUUID(String name) public UUID getClientUUID(String name)
{ {
final List<UUID> uuids = new ArrayList<UUID>(); EnclosedObject<UUID> uuid = new EnclosedObject<>();
executeQuery(SELECT_ACCOUNT_UUID_BY_NAME, new ResultSetCallable() executeQuery(SELECT_ACCOUNT_UUID_BY_NAME, new ResultSetCallable()
{ {
@ -198,15 +199,12 @@ public class AccountRepository extends MinecraftRepository
{ {
while (resultSet.next()) while (resultSet.next())
{ {
uuids.add(UUID.fromString(resultSet.getString(1))); uuid.Set(UUID.fromString(resultSet.getString(1)));
} }
} }
}, new ColumnVarChar("name", 100, name)); }, new ColumnVarChar("name", 100, name));
if (uuids.size() > 0) return uuid.Get();
return uuids.get(0);
else
return null;
} }
public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm) public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)

View File

@ -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<VanishClient>
{
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();
}
}

View File

@ -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<Vanish>
{
public VanishCommand(Vanish plugin)
{
super(plugin, Rank.HELPER, "incognito", "vanish");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.toggle(caller);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,6 @@
package mineplex.core.vanish.repository;
public class VanishClient
{
public boolean State;
}

View File

@ -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<Boolean> 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()
{
}
}