Merge remote-tracking branch 'refs/remotes/origin/develop' into feature/gem-hunters
This commit is contained in:
commit
2657a98e70
@ -16,7 +16,6 @@ import java.util.logging.Logger;
|
||||
import mineplex.bungee.api.ApiDeleteCall;
|
||||
import mineplex.bungee.api.ApiGetCall;
|
||||
import mineplex.bungee.api.ApiPostCall;
|
||||
import mineplex.bungee.api.HttpCallBase;
|
||||
import mineplex.bungee.api.token.ARecord;
|
||||
import mineplex.bungee.api.token.DnsRecord;
|
||||
import mineplex.bungee.api.token.DomainRecords;
|
||||
@ -25,8 +24,8 @@ import mineplex.serverdata.data.BungeeServer;
|
||||
import mineplex.serverdata.data.DataRepository;
|
||||
import mineplex.serverdata.redis.RedisDataRepository;
|
||||
import mineplex.serverdata.servers.ConnectionData;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
|
||||
public class BungeeRotator
|
||||
{
|
||||
@ -97,7 +96,8 @@ public class BungeeRotator
|
||||
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
|
||||
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||
|
||||
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"),
|
||||
// Temporarily reassigning to US Redis IP for EU player redirection testing. 10.81.1.156 -> 10.33.53.16
|
||||
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"),
|
||||
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||
|
||||
//_ipRepository = new PlayerStatsRepository();
|
||||
@ -110,7 +110,7 @@ public class BungeeRotator
|
||||
try
|
||||
{
|
||||
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>(_repository.getElements());
|
||||
bungeeServers.addAll(_secondRepository.getElements());
|
||||
//bungeeServers.addAll(_secondRepository.getElements());
|
||||
|
||||
Collections.sort(bungeeServers, bungeeSorter);
|
||||
|
||||
|
@ -4,37 +4,43 @@ import java.util.UUID;
|
||||
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.redis.RedisDataRepository;
|
||||
import mineplex.serverdata.redis.atomic.RedisStringRepository;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
|
||||
public class PlayerCache
|
||||
public enum PlayerCache
|
||||
{
|
||||
private static PlayerCache _instance = null;
|
||||
|
||||
private RedisDataRepository<PlayerInfo> _repository;
|
||||
INSTANCE;
|
||||
|
||||
public static PlayerCache getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new PlayerCache();
|
||||
|
||||
return _instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private PlayerCache()
|
||||
|
||||
private final RedisDataRepository<PlayerInfo> _playerInfoRepository;
|
||||
private final RedisStringRepository _accountIdRepository;
|
||||
|
||||
PlayerCache()
|
||||
{
|
||||
_repository = new RedisDataRepository<PlayerInfo>(
|
||||
ServerManager.getMasterConnection(),
|
||||
_playerInfoRepository = new RedisDataRepository<PlayerInfo>(
|
||||
ServerManager.getMasterConnection(),
|
||||
ServerManager.getSlaveConnection(),
|
||||
Region.ALL,
|
||||
PlayerInfo.class,
|
||||
Region.ALL,
|
||||
PlayerInfo.class,
|
||||
"playercache");
|
||||
|
||||
_accountIdRepository = new RedisStringRepository(
|
||||
ServerManager.getMasterConnection(),
|
||||
ServerManager.getSlaveConnection(),
|
||||
Region.ALL,
|
||||
"accountid"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void addPlayer(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
_repository.addElement(player, 60 * 60 * 6); // 6 Hours
|
||||
_playerInfoRepository.addElement(player, 60 * 60 * 6); // 6 Hours
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -42,12 +48,12 @@ public class PlayerCache
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PlayerInfo getPlayer(UUID uuid)
|
||||
{
|
||||
try
|
||||
{
|
||||
PlayerInfo playerInfo = _repository.getElement(uuid.toString());
|
||||
PlayerInfo playerInfo = _playerInfoRepository.getElement(uuid.toString());
|
||||
return playerInfo;
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -55,23 +61,49 @@ public class PlayerCache
|
||||
System.out.println("Error retrieving player info in PlayerCache : " + exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to grab a player's account ID from the cache
|
||||
*
|
||||
* @param uuid Minecraft Account UUID
|
||||
* @return The account id of the player, or -1 if the player is not in the cache
|
||||
*/
|
||||
public int getAccountId(UUID uuid)
|
||||
{
|
||||
PlayerInfo info = getPlayer(uuid);
|
||||
return info == null ? -1 : info.getAccountId();
|
||||
String accountIdStr = _accountIdRepository.get(uuid.toString());
|
||||
|
||||
if (accountIdStr == null)
|
||||
return -1;
|
||||
|
||||
try
|
||||
{
|
||||
int accountId = Integer.parseInt(accountIdStr);
|
||||
if (accountId <= 0)
|
||||
{
|
||||
// remove invalid account id
|
||||
_accountIdRepository.del(uuid.toString());
|
||||
return -1;
|
||||
}
|
||||
return accountId;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
// remove invalid account id
|
||||
_accountIdRepository.del(uuid.toString());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAccountId(UUID uuid, int newId)
|
||||
{
|
||||
_accountIdRepository.set(uuid.toString(), String.valueOf(newId));
|
||||
}
|
||||
|
||||
public void clean()
|
||||
{
|
||||
_repository.clean();
|
||||
_playerInfoRepository.clean();
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +36,6 @@ public class PlayerInfo implements Data
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getAccountId()
|
||||
{
|
||||
return _accountId;
|
||||
}
|
||||
|
||||
public UUID getUUID()
|
||||
{
|
||||
return _uuid;
|
||||
@ -90,11 +85,6 @@ public class PlayerInfo implements Data
|
||||
{
|
||||
_version = version;
|
||||
}
|
||||
|
||||
public void setAccountId(int accountId)
|
||||
{
|
||||
_accountId = accountId;
|
||||
}
|
||||
|
||||
public void updateLoginTime()
|
||||
{
|
||||
|
@ -1,11 +1,20 @@
|
||||
package mineplex.core.common;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
|
||||
@ -18,24 +27,47 @@ public class Constants
|
||||
|
||||
static
|
||||
{
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName("com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService$GameProfileSerializer");
|
||||
Constructor<?> ctor = clazz.getDeclaredConstructor();
|
||||
ctor.setAccessible(true);
|
||||
builder.registerTypeAdapter(GameProfile.class, ctor.newInstance());
|
||||
}
|
||||
catch (ReflectiveOperationException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
builder
|
||||
GsonBuilder builder = new GsonBuilder()
|
||||
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter());
|
||||
|
||||
builder.registerTypeAdapter(GameProfile.class, new GameProfileSerializer());
|
||||
|
||||
GSON = builder.create();
|
||||
}
|
||||
|
||||
private static class GameProfileSerializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile>
|
||||
{
|
||||
public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if (!(json instanceof JsonObject))
|
||||
return new GameProfile(null, null);
|
||||
|
||||
JsonObject object = (JsonObject) json;
|
||||
UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null;
|
||||
String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
|
||||
GameProfile profile = new GameProfile(id, name);
|
||||
|
||||
if (object.has("properties"))
|
||||
profile.getProperties().putAll(context.deserialize(object.get("properties"), PropertyMap.class));
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject result = new JsonObject();
|
||||
|
||||
if (profile.getId() != null)
|
||||
result.add("id", context.serialize(profile.getId()));
|
||||
|
||||
if (profile.getName() != null)
|
||||
result.addProperty("name", profile.getName());
|
||||
|
||||
if (!profile.getProperties().isEmpty())
|
||||
result.add("properties", context.serialize(profile.getProperties()));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilEnt
|
||||
{
|
||||
public static final String FLAG_NO_REMOVE = "noremove";
|
||||
|
||||
//Custom Entity Names
|
||||
private static HashMap<Entity, String> _nameMap = new HashMap<Entity, String>();
|
||||
@ -76,6 +77,27 @@ public class UtilEnt
|
||||
// Not working right now
|
||||
//((CraftEntity)entity).getHandle().setSilent(silence);
|
||||
}
|
||||
|
||||
public static void addFlag(Entity entity, String flag)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
entity.setMetadata("flag:" + flag, new FixedMetadataValue(UtilServer.getPlugin(), true));
|
||||
}
|
||||
|
||||
public static void removeFlag(Entity entity, String flag)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
entity.removeMetadata("flag:" + flag, UtilServer.getPlugin());
|
||||
}
|
||||
|
||||
public static boolean hasFlag(Entity entity, String flag)
|
||||
{
|
||||
return entity.hasMetadata("flag:" + flag);
|
||||
}
|
||||
|
||||
public static void ghost(Entity entity, boolean ghost, boolean invisible)
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.command.TestRank;
|
||||
import mineplex.core.account.command.UpdateRank;
|
||||
@ -301,13 +300,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
if (client.getAccountId() > 0)
|
||||
{
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
|
||||
if (playerInfo != null)
|
||||
{
|
||||
playerInfo.setAccountId(client.getAccountId());
|
||||
PlayerCache.getInstance().addPlayer(playerInfo);
|
||||
}
|
||||
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
|
||||
}
|
||||
|
||||
loaded.set(client);
|
||||
@ -367,13 +360,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
if (client.getAccountId() > 0)
|
||||
{
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
|
||||
if (playerInfo != null)
|
||||
{
|
||||
playerInfo.setAccountId(client.getAccountId());
|
||||
PlayerCache.getInstance().addPlayer(playerInfo);
|
||||
}
|
||||
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -458,14 +445,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
if (client.getAccountId() > 0)
|
||||
{
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
|
||||
if (playerInfo != null)
|
||||
{
|
||||
client.setNetworkSessionLoginTime(playerInfo.getLoginTime());
|
||||
playerInfo.setAccountId(client.getAccountId());
|
||||
PlayerCache.getInstance().addPlayer(playerInfo);
|
||||
}
|
||||
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
|
||||
}
|
||||
|
||||
return !CLIENT_LOGIN_LOCKS.containsKey(client.getName());
|
||||
|
@ -11,8 +11,6 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
|
||||
if (getClientManager().Get(getPlayer()) != null)
|
||||
token.AccountId = getClientManager().Get(getPlayer()).getAccountId();
|
||||
else
|
||||
token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId();
|
||||
token.AccountId = PlayerCache.getInstance().getAccountId(getPlayer().getUniqueId());
|
||||
|
||||
token.Name = getPlayer().getName();
|
||||
token.PetType = _petType.toString();
|
||||
|
@ -617,12 +617,6 @@ public class GadgetManager extends MiniPlugin
|
||||
event.getPlayer().setFlySpeed(0.1f);
|
||||
// Loads saved gadgets
|
||||
_userGadgetPersistence.load(event.getPlayer());
|
||||
|
||||
// Disables gadgets if there are more than 100 players in a server
|
||||
if (UtilServer.getPlayers().length >= 100)
|
||||
{
|
||||
setGadgetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Gadget> getGadgets(GadgetType gadgetType)
|
||||
@ -980,12 +974,6 @@ public class GadgetManager extends MiniPlugin
|
||||
event.getPlayer().setWalkSpeed(0.2f);
|
||||
event.getPlayer().setFlySpeed(0.1f);
|
||||
_soulManager.giveSoul(event.getPlayer());
|
||||
|
||||
// Enables gadgets if there are less than 100 players
|
||||
if (UtilServer.getPlayers().length < 100)
|
||||
{
|
||||
setGadgetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.EntityEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -69,6 +70,9 @@ public class ItemFleshHook extends ItemGadget implements IThrown
|
||||
if (Manager.collideEvent(player, this, target))
|
||||
return;
|
||||
|
||||
if (target instanceof ArmorStand)
|
||||
return;
|
||||
|
||||
//Pull
|
||||
UtilAction.velocity(target,
|
||||
UtilAlg.getTrajectory(target.getLocation(), player.getLocation()),
|
||||
|
@ -2,6 +2,7 @@ package mineplex.core.gadget.gadgets.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -56,6 +57,8 @@ public class ItemSnowball extends ItemGadget
|
||||
|
||||
if(Manager.collideEvent(_snowballs.remove(ball), this, event.getEntity())) return;
|
||||
|
||||
if (event.getEntity() instanceof ArmorStand)
|
||||
return;
|
||||
|
||||
UtilAction.velocity(event.getEntity(), event.getDamager().getVelocity().normalize().add(new Vector(0,0.5,0)).multiply(0.5));
|
||||
event.getDamager().getWorld().playSound(event.getDamager().getLocation(), Sound.STEP_SNOW, 1, 0.5f);
|
||||
|
@ -3,18 +3,10 @@ package mineplex.core.gadget.gadgets.morph;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.MapUtil;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.disguise.disguises.DisguiseCat;
|
||||
import mineplex.core.disguise.disguises.DisguiseChicken;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
@ -23,100 +15,163 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFallingSand;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Slime;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.disguise.disguises.DisguiseBlock;
|
||||
import mineplex.core.disguise.disguises.DisguiseSlime;
|
||||
import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
|
||||
public class BlockForm
|
||||
{
|
||||
private MorphBlock _host;
|
||||
private Player _player;
|
||||
|
||||
private Material _mat;
|
||||
private Material _blockMat;
|
||||
private int _blockData;
|
||||
|
||||
private Block _block;
|
||||
private Location _loc;
|
||||
|
||||
public BlockForm(MorphBlock host, Player player, Material mat)
|
||||
private Slime _fallingBlock;
|
||||
private ArmorStand _fallingBlockBase;
|
||||
|
||||
private DisguiseBlock _disguiseBlock;
|
||||
private DisguiseSlime _disguiseBlockBase;
|
||||
private DisguiseSlime _hiddenDisguise;
|
||||
|
||||
private EntityPlayer _entityPlayer;
|
||||
private Entity _nmsFallingBlockBase;
|
||||
|
||||
public BlockForm(MorphBlock host, Player player, Material blockMat, int blockData)
|
||||
{
|
||||
_host = host;
|
||||
_player = player;
|
||||
|
||||
_mat = mat;
|
||||
_blockMat = blockMat;
|
||||
_blockData = blockData;
|
||||
|
||||
_loc = player.getLocation();
|
||||
|
||||
Apply();
|
||||
_entityPlayer = ((CraftPlayer) player).getHandle();
|
||||
|
||||
_hiddenDisguise = new DisguiseSlime(player);
|
||||
_hiddenDisguise.setInvisible(true);
|
||||
|
||||
_host.Manager.getDisguiseManager().disguise(_hiddenDisguise);
|
||||
|
||||
this._fallingBlock = _loc.getWorld().spawn(_loc, Slime.class);
|
||||
this._fallingBlock.setSize(0);
|
||||
this._fallingBlock.setRemoveWhenFarAway(false);
|
||||
UtilEnt.vegetate(this._fallingBlock, true);
|
||||
UtilEnt.ghost(this._fallingBlock, true, true);
|
||||
|
||||
this._fallingBlockBase = (ArmorStand) new EntityArmorStand(((CraftWorld) this._loc.getWorld()).getHandle(), this._loc.getX(), this._loc.getY(), this._loc.getZ()).getBukkitEntity();
|
||||
this._fallingBlockBase.setGravity(false);
|
||||
this._fallingBlockBase.setVisible(false);
|
||||
this._fallingBlockBase.setRemoveWhenFarAway(false);
|
||||
this._fallingBlockBase.setPassenger(this._fallingBlock);
|
||||
|
||||
UtilEnt.addFlag(this._fallingBlock, UtilEnt.FLAG_NO_REMOVE);
|
||||
UtilEnt.addFlag(this._fallingBlock, MorphBlock.FLAG_BLOCK_MORPH_COMPONENT);
|
||||
UtilEnt.addFlag(this._fallingBlockBase, UtilEnt.FLAG_NO_REMOVE);
|
||||
UtilEnt.addFlag(this._fallingBlockBase, MorphBlock.FLAG_BLOCK_MORPH_COMPONENT);
|
||||
|
||||
_nmsFallingBlockBase = ((CraftEntity) _fallingBlockBase).getHandle();
|
||||
_disguiseBlockBase = new DisguiseSlime(_fallingBlockBase);
|
||||
_disguiseBlockBase.SetSize(0);
|
||||
_disguiseBlockBase.setInvisible(true);
|
||||
_host.Manager.getDisguiseManager().disguise(_disguiseBlockBase);
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
private void createFallingBlock()
|
||||
{
|
||||
// Remove Old
|
||||
if (_player.getPassenger() != null)
|
||||
{
|
||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
||||
removeFallingBlock();
|
||||
|
||||
_player.getPassenger().remove();
|
||||
_player.eject();
|
||||
_disguiseBlock = new DisguiseBlock(_fallingBlock, _blockMat.getId(), _blockData);
|
||||
_disguiseBlock.setHideIfNotDisguised(true);
|
||||
_host.Manager.getDisguiseManager().disguise(_disguiseBlock);
|
||||
|
||||
_fallingBlockBase.setPassenger(_fallingBlock);
|
||||
}
|
||||
|
||||
private void removeFallingBlock()
|
||||
{
|
||||
if (_disguiseBlock != null)
|
||||
{
|
||||
_host.Manager.getDisguiseManager().undisguise(_disguiseBlock);
|
||||
_disguiseBlock = null;
|
||||
_fallingBlockBase.setPassenger(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
removeSolidBlock();
|
||||
createFallingBlock();
|
||||
// Inform
|
||||
|
||||
String name = ItemStackFactory.Instance.GetName(_blockMat, (byte) _blockData, false);
|
||||
|
||||
if (!name.contains("Block"))
|
||||
{
|
||||
name = name + " Block";
|
||||
}
|
||||
|
||||
((CraftEntity) _player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32);
|
||||
|
||||
// Player > Chicken
|
||||
DisguiseChicken disguise = new DisguiseChicken(_player);
|
||||
disguise.setBaby();
|
||||
disguise.setSoundDisguise(new DisguiseCat(_player));
|
||||
disguise.setInvisible(true);
|
||||
//_host.Manager.getDisguiseManager().disguise(disguise);
|
||||
UtilMorph.disguise(_player, disguise, _host.Manager.getDisguiseManager());
|
||||
|
||||
// Apply Falling Block
|
||||
FallingBlockCheck();
|
||||
|
||||
// Inform
|
||||
String blockName = F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false));
|
||||
if (!blockName.contains("Block"))
|
||||
UtilPlayer
|
||||
.message(
|
||||
_player,
|
||||
F.main("Morph",
|
||||
"You are now a "
|
||||
+ F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!"));
|
||||
else
|
||||
UtilPlayer.message(_player,
|
||||
F.main("Morph", "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) + "!"));
|
||||
UtilPlayer.message(_player, F.main("Morph", "You are now " + F.vowelAN(name) + " " + F.elem(name) + "!"));
|
||||
|
||||
// Sound
|
||||
_player.playSound(_player.getLocation(), Sound.ZOMBIE_UNFECT, 2f, 2f);
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
public void remove()
|
||||
{
|
||||
SolidifyRemove();
|
||||
removeSolidBlock();
|
||||
removeFallingBlock();
|
||||
|
||||
//_host.Manager.getDisguiseManager().undisguise(_player);
|
||||
UtilMorph.undisguise(_player, _host.Manager.getDisguiseManager());
|
||||
|
||||
// Remove FB
|
||||
if (_player.getPassenger() != null)
|
||||
{
|
||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
||||
|
||||
_player.getPassenger().remove();
|
||||
_player.eject();
|
||||
}
|
||||
|
||||
((CraftEntity) _player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0), Entity.META_ENTITYDATA, (byte) 0);
|
||||
_host.Manager.getDisguiseManager().undisguise(_hiddenDisguise);
|
||||
_host.Manager.getDisguiseManager().undisguise(_disguiseBlockBase);
|
||||
_fallingBlockBase.remove();
|
||||
_fallingBlockBase = null;
|
||||
_fallingBlock.remove();
|
||||
_fallingBlock = null;
|
||||
_nmsFallingBlockBase = null;
|
||||
}
|
||||
|
||||
public void SolidifyUpdate()
|
||||
public void update()
|
||||
{
|
||||
if (!_player.isSprinting())
|
||||
((CraftEntity) _player).getHandle().getDataWatcher()
|
||||
.watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32);
|
||||
|
||||
// Not a Block
|
||||
if (_block == null)
|
||||
{
|
||||
if (_fallingBlockBase.getPassenger() != _fallingBlock)
|
||||
_fallingBlockBase.setPassenger(_fallingBlock);
|
||||
|
||||
if (!_nmsFallingBlockBase.getBukkitEntity().getWorld().equals(_player.getWorld()))
|
||||
_nmsFallingBlockBase.getBukkitEntity().teleport(_player);
|
||||
else
|
||||
{
|
||||
_nmsFallingBlockBase.locX = _entityPlayer.locX;
|
||||
_nmsFallingBlockBase.locY = _entityPlayer.locY;
|
||||
_nmsFallingBlockBase.locZ = _entityPlayer.locZ;
|
||||
_nmsFallingBlockBase.motX = _entityPlayer.motX;
|
||||
_nmsFallingBlockBase.motY = _entityPlayer.motY;
|
||||
_nmsFallingBlockBase.motZ = _entityPlayer.motZ;
|
||||
_nmsFallingBlockBase.velocityChanged = true;
|
||||
}
|
||||
|
||||
// Moved
|
||||
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
||||
{
|
||||
@ -135,7 +190,7 @@ public class BlockForm
|
||||
{
|
||||
Block block = _player.getLocation().getBlock();
|
||||
|
||||
List<Block> blockList = new ArrayList<Block>();
|
||||
List<Block> blockList = new ArrayList<>();
|
||||
blockList.add(block);
|
||||
|
||||
GadgetBlockEvent event = new GadgetBlockEvent(_host, blockList);
|
||||
@ -155,17 +210,18 @@ public class BlockForm
|
||||
_block = block;
|
||||
|
||||
// Effect
|
||||
_player.playEffect(_player.getLocation(), Effect.STEP_SOUND, _mat);
|
||||
// block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, _mat);
|
||||
_player.playEffect(_block.getLocation(), Effect.STEP_SOUND, _blockMat);
|
||||
|
||||
removeFallingBlock();
|
||||
|
||||
// Display
|
||||
SolidifyVisual();
|
||||
|
||||
// Invisible
|
||||
// Host.Manager.GetCondition().Factory().Cloak("Disguised as Block", Player, Player, 60000, false, false);
|
||||
for (Player other : UtilServer.getPlayers())
|
||||
{
|
||||
other.sendBlockChange(_block.getLocation(), _blockMat, (byte) _blockData);
|
||||
}
|
||||
|
||||
// Sound
|
||||
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 2f);
|
||||
_player.playSound(_block.getLocation(), Sound.NOTE_PLING, 1f, 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,93 +231,60 @@ public class BlockForm
|
||||
// Moved
|
||||
if (!_loc.getBlock().equals(_player.getLocation().getBlock()))
|
||||
{
|
||||
SolidifyRemove();
|
||||
}
|
||||
// Send Packets
|
||||
else
|
||||
{
|
||||
SolidifyVisual();
|
||||
removeSolidBlock();
|
||||
createFallingBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SolidifyRemove()
|
||||
private void removeSolidBlock()
|
||||
{
|
||||
if (_block != null)
|
||||
{
|
||||
MapUtil.QuickChangeBlockAt(_block.getLocation(), 0, (byte) 0);
|
||||
Location location = _block.getLocation();
|
||||
_block = null;
|
||||
|
||||
for (Player other : UtilServer.getPlayers())
|
||||
{
|
||||
other.sendBlockChange(location, 0, (byte) 0);
|
||||
}
|
||||
|
||||
_player.setExp(0f);
|
||||
|
||||
// Inform
|
||||
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
|
||||
}
|
||||
|
||||
_player.setExp(0f);
|
||||
|
||||
// Host.Manager.GetCondition().EndCondition(Player, null, "Disguised as Block");
|
||||
|
||||
// Inform
|
||||
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
|
||||
|
||||
FallingBlockCheck();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void SolidifyVisual()
|
||||
public void setType(Block block)
|
||||
{
|
||||
if (_block == null)
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
// Remove Old
|
||||
if (_player.getPassenger() != null)
|
||||
{
|
||||
Recharge.Instance.useForce(_player, "PassengerChange", 100);
|
||||
|
||||
_player.getPassenger().remove();
|
||||
_player.eject();
|
||||
}
|
||||
|
||||
// Others
|
||||
for (Player other : UtilServer.getPlayers())
|
||||
other.sendBlockChange(_player.getLocation(), _mat, (byte) 0);
|
||||
|
||||
// Self
|
||||
_player.sendBlockChange(_player.getLocation(), 36, (byte) 0);
|
||||
|
||||
FallingBlockCheck();
|
||||
}
|
||||
|
||||
public void FallingBlockCheck()
|
||||
{
|
||||
// Block Form (Hide Falling)
|
||||
if (_block != null)
|
||||
if (block.getType() == Material.AIR)
|
||||
return;
|
||||
|
||||
// Recreate Falling
|
||||
if (_player.getPassenger() == null || !_player.getPassenger().isValid())
|
||||
{
|
||||
if (!Recharge.Instance.use(_player, "PassengerChange", 100, false, false))
|
||||
return;
|
||||
if (_blockMat == block.getType() && _blockData == block.getData())
|
||||
return;
|
||||
|
||||
// Falling Block
|
||||
FallingBlock block = _player.getWorld().spawnFallingBlock(_player.getEyeLocation(), _mat, (byte) 0);
|
||||
|
||||
// No Arrow Collision
|
||||
((CraftFallingSand) block).getHandle().spectating = true;
|
||||
|
||||
_player.setPassenger(block);
|
||||
|
||||
_host.fallingBlockRegister(block);
|
||||
}
|
||||
|
||||
// Ensure Falling doesnt Despawn
|
||||
else
|
||||
{
|
||||
((CraftFallingSand) _player.getPassenger()).getHandle().ticksLived = 1;
|
||||
_player.getPassenger().setTicksLived(1);
|
||||
}
|
||||
_blockMat = block.getType();
|
||||
_blockData = block.getData();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public Block GetBlock()
|
||||
public Block getBlock()
|
||||
{
|
||||
return _block;
|
||||
}
|
||||
|
||||
public IBlockData getBlockData()
|
||||
{
|
||||
return CraftMagicNumbers.getBlock(_blockMat).fromLegacyData(_blockData);
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return this._player;
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,54 @@
|
||||
package mineplex.core.gadget.gadgets.morph;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInBlockDig;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutBlockChange;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.event.StackerEvent;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.types.MorphGadget;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.utils.UtilScheduler;
|
||||
|
||||
public class MorphBlock extends MorphGadget implements IPacketHandler
|
||||
{
|
||||
public static final String FLAG_BLOCK_MORPH_COMPONENT = "block-morph-component";
|
||||
|
||||
private Map<Player, BlockForm> _active = new HashMap<>();
|
||||
|
||||
public class MorphBlock extends MorphGadget
|
||||
{
|
||||
private HashMap<Player, BlockForm> _active = new HashMap<Player, BlockForm>();
|
||||
private HashSet<FallingBlock> _blocks = new HashSet<FallingBlock>();
|
||||
|
||||
public MorphBlock(GadgetManager manager)
|
||||
{
|
||||
super(manager, "Block Morph", UtilText.splitLinesToArray(new String[]
|
||||
{
|
||||
C.cGray + "The blockiest block that ever blocked.",
|
||||
C.blankLine,
|
||||
"#" + C.cWhite + "Left Click to use Change Block",
|
||||
"#" + C.cWhite + "Stay Still to use Solidify",
|
||||
}, LineFormat.LORE),
|
||||
super(manager, "Block Morph", UtilText.splitLinesToArray(new String[]
|
||||
{
|
||||
C.cGray + "The blockiest block that ever blocked.",
|
||||
C.blankLine,
|
||||
"#" + C.cWhite + "Left Click to use Change Block",
|
||||
"#" + C.cWhite + "Stay Still to use Solidify",
|
||||
}, LineFormat.LORE),
|
||||
30000,
|
||||
Material.EMERALD_BLOCK, (byte)0);
|
||||
Material.EMERALD_BLOCK, (byte) 0);
|
||||
|
||||
UtilScheduler.runEvery(UpdateType.TICK, () -> _active.values().forEach(BlockForm::update));
|
||||
|
||||
manager.getPacketManager().addPacketHandler(this, PacketPlayOutBlockChange.class, PacketPlayInBlockDig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +56,7 @@ public class MorphBlock extends MorphGadget
|
||||
{
|
||||
this.applyArmor(player, message);
|
||||
|
||||
_active.put(player, new BlockForm(this, player, Material.EMERALD_BLOCK));
|
||||
_active.put(player, new BlockForm(this, player, Material.EMERALD_BLOCK, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,108 +64,86 @@ public class MorphBlock extends MorphGadget
|
||||
{
|
||||
this.removeArmor(player);
|
||||
|
||||
|
||||
BlockForm form = _active.remove(player);
|
||||
if (form != null)
|
||||
{
|
||||
form.Remove();
|
||||
form.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void formUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (BlockForm form : _active.values())
|
||||
{
|
||||
form.SolidifyUpdate();
|
||||
form.FallingBlockCheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void formChange(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.getClickedBlock() == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!UtilEvent.isAction(event, ActionType.L_BLOCK) && !UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
return;
|
||||
|
||||
if (!UtilBlock.solid(event.getClickedBlock()))
|
||||
return;
|
||||
|
||||
|
||||
if (!Recharge.Instance.use(event.getPlayer(), getName(), 500, false, false))
|
||||
return;
|
||||
|
||||
|
||||
BlockForm form = _active.get(event.getPlayer());
|
||||
|
||||
|
||||
if (form == null)
|
||||
return;
|
||||
|
||||
form.Remove();
|
||||
|
||||
_active.put(event.getPlayer(), new BlockForm(this, event.getPlayer(), event.getClickedBlock().getType()));
|
||||
|
||||
form.setType(event.getClickedBlock());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void stacker(StackerEvent event)
|
||||
public void onDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (_active.containsKey(event.getEntity()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void fallingBlockRegister(FallingBlock block)
|
||||
{
|
||||
_blocks.add(block);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void fallingBlockForm(EntityChangeBlockEvent event)
|
||||
{
|
||||
if (_blocks.remove(event.getEntity()))
|
||||
if (UtilEnt.hasFlag(event.getEntity(), FLAG_BLOCK_MORPH_COMPONENT))
|
||||
{
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void fallingBlockClean(UpdateEvent event)
|
||||
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
Iterator<FallingBlock> blockIterator = _blocks.iterator();
|
||||
|
||||
while (blockIterator.hasNext())
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutBlockChange)
|
||||
{
|
||||
FallingBlock block = blockIterator.next();
|
||||
|
||||
if (!block.isValid() || block.getVehicle() == null)
|
||||
PacketPlayOutBlockChange packet = (PacketPlayOutBlockChange) packetInfo.getPacket();
|
||||
|
||||
for (BlockForm form : _active.values())
|
||||
{
|
||||
block.remove();
|
||||
blockIterator.remove();
|
||||
if (form.getBlock() == null)
|
||||
continue;
|
||||
|
||||
Location location = form.getBlock().getLocation();
|
||||
if (packetInfo.getPlayer().getWorld() == location.getWorld() && packet.a.getX() == location.getX() && packet.a.getY() == location.getY() && packet.a.getZ() == location.getZ())
|
||||
{
|
||||
if (packetInfo.getPlayer() == form.getPlayer())
|
||||
{
|
||||
packet.block = Blocks.AIR.getBlockData();
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.block = form.getBlockData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemSpawnCancel(ItemSpawnEvent event)
|
||||
{
|
||||
Iterator<FallingBlock> blockIterator = _blocks.iterator();
|
||||
|
||||
while (blockIterator.hasNext())
|
||||
else if (packetInfo.getPacket() instanceof PacketPlayInBlockDig)
|
||||
{
|
||||
FallingBlock block = blockIterator.next();
|
||||
|
||||
if (UtilMath.offset(block, event.getEntity()) < 0.1)
|
||||
PacketPlayInBlockDig packet = (PacketPlayInBlockDig) packetInfo.getPacket();
|
||||
|
||||
if (packet.c != PacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK)
|
||||
return;
|
||||
|
||||
for (BlockForm form : _active.values())
|
||||
{
|
||||
block.remove();
|
||||
blockIterator.remove();
|
||||
event.setCancelled(true);
|
||||
if (form.getBlock() == null)
|
||||
continue;
|
||||
|
||||
Location location = form.getBlock().getLocation();
|
||||
if (packetInfo.getPlayer().getWorld() == location.getWorld() && packet.a.getX() == location.getX() && packet.a.getY() == location.getY() && packet.a.getZ() == location.getZ())
|
||||
{
|
||||
packetInfo.setCancelled(true);
|
||||
packetInfo.getPlayer().sendBlockChange(location, 0, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package mineplex.core.inventory;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.Callback;
|
||||
@ -144,10 +143,10 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
if (playerInfo != null)
|
||||
int accountId = PlayerCache.getInstance().getAccountId(uuid);
|
||||
if (accountId != -1)
|
||||
{
|
||||
addItemToInventoryForOffline(callback, playerInfo.getAccountId(), item, count);
|
||||
addItemToInventoryForOffline(callback, accountId, item, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ public class PetReward extends UnknownPackageReward
|
||||
if (_inventoryManager.getClientManager().Get(player) != null)
|
||||
token.AccountId = _inventoryManager.getClientManager().Get(player).getAccountId();
|
||||
else
|
||||
token.AccountId = PlayerCache.getInstance().getPlayer(player.getUniqueId()).getAccountId();
|
||||
token.AccountId = PlayerCache.getInstance().getAccountId(player.getUniqueId());
|
||||
|
||||
token.Name = player.getName();
|
||||
token.PetType = _petType.toString();
|
||||
|
@ -4,12 +4,14 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilTasks;
|
||||
import mineplex.core.task.repository.TaskRepository;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -54,7 +56,7 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
|
||||
return new TaskClient();
|
||||
}
|
||||
|
||||
public void addTaskForOfflinePlayer(final Callback<Boolean> callback, final UUID uuid, final String task)
|
||||
public void addTaskForOfflinePlayer(Consumer<Boolean> callback, final UUID uuid, final String task)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@ -75,16 +77,20 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
|
||||
updateTasks();
|
||||
}
|
||||
|
||||
final boolean success = _repository.addAccountTask(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), getTaskId(task));
|
||||
|
||||
if (callback != null)
|
||||
int accountId = PlayerCache.getInstance().getAccountId(uuid);
|
||||
|
||||
if (accountId != -1)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
|
||||
UtilTasks.onMainThread(callback).accept(_repository.addAccountTask(accountId, getTaskId(task)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientManager.loadAccountIdFromUUID(uuid, id ->
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
callback.run(success);
|
||||
}
|
||||
if (id > 0)
|
||||
UtilTasks.onMainThread(callback).accept(_repository.addAccountTask(accountId, getTaskId(task)));
|
||||
else
|
||||
UtilTasks.onMainThread(callback).accept(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -114,27 +120,24 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
|
||||
}
|
||||
}
|
||||
|
||||
addTaskForOfflinePlayer(new Callback<Boolean>()
|
||||
addTaskForOfflinePlayer(success ->
|
||||
{
|
||||
public void run(Boolean success)
|
||||
if (!success)
|
||||
{
|
||||
if (!success.booleanValue())
|
||||
System.out.println("Add task FAILED for " + player.getName());
|
||||
|
||||
synchronized (_taskLock)
|
||||
{
|
||||
System.out.println("Add task FAILED for " + player.getName());
|
||||
|
||||
synchronized (_taskLock)
|
||||
if (_tasks.containsKey(taskName))
|
||||
{
|
||||
if (_tasks.containsKey(taskName))
|
||||
{
|
||||
Get(player).TasksCompleted.remove(_tasks.get(taskName));
|
||||
}
|
||||
Get(player).TasksCompleted.remove(_tasks.get(taskName));
|
||||
}
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback.run(success);
|
||||
}
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback.run(success);
|
||||
}
|
||||
}, player.getUniqueId(), taskName);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class LocateCommand extends CommandBase<Teleport>
|
||||
{
|
||||
public LocateCommand(Teleport plugin)
|
||||
{
|
||||
super(plugin, Rank.MODERATOR, "locate", "where", "find");
|
||||
super(plugin, Rank.HELPER, "locate", "where", "find");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +60,7 @@ import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
@ -710,9 +711,11 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
|
||||
event.getEntity().leaveVehicle();
|
||||
event.getEntity().teleport(GetSpawn());
|
||||
}
|
||||
|
||||
else
|
||||
event.getEntity().remove();
|
||||
{
|
||||
if (!UtilEnt.hasFlag(event.getEntity(), UtilEnt.FLAG_NO_REMOVE))
|
||||
event.getEntity().remove();
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package mineplex.serverdata.redis.atomic;
|
||||
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.redis.RedisRepository;
|
||||
import mineplex.serverdata.servers.ConnectionData;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import static mineplex.serverdata.Utility.currentTimeMillis;
|
||||
|
||||
public class RedisStringRepository extends RedisRepository
|
||||
{
|
||||
private final String _dataKey;
|
||||
|
||||
public RedisStringRepository(ConnectionData writeConn, ConnectionData readConn, Region region, String dataKey)
|
||||
{
|
||||
super(writeConn, readConn, region);
|
||||
this._dataKey = dataKey;
|
||||
}
|
||||
|
||||
public void set(String key, String value)
|
||||
{
|
||||
try (Jedis jedis = getResource(true))
|
||||
{
|
||||
jedis.set(generateKey(key), value);
|
||||
}
|
||||
}
|
||||
|
||||
public String get(String key)
|
||||
{
|
||||
String element;
|
||||
|
||||
try (Jedis jedis = getResource(false))
|
||||
{
|
||||
element = jedis.get(generateKey(key));
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void del(String key)
|
||||
{
|
||||
try (Jedis jedis = getResource(true))
|
||||
{
|
||||
jedis.del(generateKey(key));
|
||||
}
|
||||
}
|
||||
|
||||
private String getElementSetKey()
|
||||
{
|
||||
return concatenate("data", _dataKey, getRegion().toString());
|
||||
}
|
||||
|
||||
private String generateKey(String dataId)
|
||||
{
|
||||
return concatenate(getElementSetKey(), dataId);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user