Merge remote-tracking branch 'origin/clans/beta' into clans/beta
This commit is contained in:
commit
3283b873e7
@ -0,0 +1,7 @@
|
||||
package mineplex.core.common.function;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Result<T>
|
||||
{
|
||||
public void Get(T result);
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
public class EnclosedObject<T>
|
||||
{
|
||||
private T _value;
|
||||
|
||||
public EnclosedObject()
|
||||
{
|
||||
this((T) null);
|
||||
}
|
||||
|
||||
public EnclosedObject(T t)
|
||||
{
|
||||
_value = t;
|
||||
}
|
||||
|
||||
public T Get()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
public T Set(T value)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<UUID> uuids = new ArrayList<UUID>();
|
||||
EnclosedObject<UUID> 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<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)
|
||||
|
@ -87,7 +87,8 @@ public class PacketHandler extends MiniPlugin
|
||||
return _playerVerifierMap.get(player);
|
||||
}
|
||||
|
||||
public void addPacketHandler(IPacketHandler packetHandler, Class<? extends Packet>... packetsToListen)
|
||||
@SafeVarargs
|
||||
public final void addPacketHandler(IPacketHandler packetHandler, Class<? extends Packet>... packetsToListen)
|
||||
{
|
||||
if (packetsToListen.length == 0)
|
||||
{
|
||||
|
97
Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java
Normal file
97
Plugins/Mineplex.Core/src/mineplex/core/vanish/Vanish.java
Normal file
@ -0,0 +1,97 @@
|
||||
package mineplex.core.vanish;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.vanish.commands.VanishCommand;
|
||||
import mineplex.core.vanish.events.PreVanishEvent;
|
||||
import mineplex.core.vanish.repository.VanishClient;
|
||||
import mineplex.core.vanish.repository.VanishRepository;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
|
||||
public class Vanish extends MiniClientPlugin<VanishClient>
|
||||
{
|
||||
private CoreClientManager _clientManager;
|
||||
private VanishRepository _repository;
|
||||
|
||||
public Vanish(JavaPlugin plugin, CoreClientManager clientManager, PacketHandler packetHandler)
|
||||
{
|
||||
super("Vanish", plugin);
|
||||
|
||||
_repository = new VanishRepository(this);
|
||||
_clientManager = clientManager;
|
||||
|
||||
packetHandler.addPacketHandler(packet -> {
|
||||
|
||||
}, PacketPlayOutChat.class);
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
Get(caller).State = enabled;
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void join
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void ClientLoad(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
_clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> {
|
||||
Get(event.getName()).State = _repository.getStatus(accountId.intValue());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void ClientLoad(PlayerJoinEvent event)
|
||||
{
|
||||
if (Get(event.getPlayer()).State)
|
||||
{
|
||||
event.setJoinMessage(null);
|
||||
informVanished(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private void informVanished(Player player)
|
||||
{
|
||||
UtilPlayer.message(player, C.cGold + "");
|
||||
}
|
||||
|
||||
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)";
|
||||
}
|
||||
|
||||
protected VanishClient AddPlayer(String player)
|
||||
{
|
||||
return new VanishClient();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package mineplex.core.vanish.repository;
|
||||
|
||||
public class VanishClient
|
||||
{
|
||||
public boolean State;
|
||||
}
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -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<ClansBanClient> clients = new ArrayList<>();
|
||||
final NonFinalInteger resultsProcessed = new NonFinalInteger();
|
||||
final EnclosedObject<Integer> resultsProcessed = new EnclosedObject<>();
|
||||
int resultsFound = 0;
|
||||
|
||||
while (resultSet.next())
|
||||
|
@ -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<Integer> 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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user