Merge branch 'develop' of github.com:Mineplex-LLC/Minecraft-PC into develop

This commit is contained in:
Jonathan Williams 2016-03-23 16:02:30 -05:00
commit 105f62e563
19 changed files with 728 additions and 310 deletions

View File

@ -48,13 +48,6 @@ public class PlayerCache
try
{
PlayerInfo playerInfo = _repository.getElement(uuid.toString());
System.out.println("Got playerInfo: " + playerInfo);
if (playerInfo != null)
{
System.out.println("account id: " + playerInfo.getAccountId());
System.out.println("name: " + playerInfo.getName());
}
return playerInfo;
}
catch (Exception exception)
@ -65,6 +58,17 @@ public class PlayerCache
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();
}
public void clean()
{

View File

@ -789,4 +789,29 @@ public class UtilPlayer
return null;
}
public static boolean isGliding(Player player)
{
return ((CraftPlayer) player).getHandle().isGliding();
}
public static void setGliding(Player player, boolean gliding)
{
((CraftPlayer) player).getHandle().setGliding(gliding);
}
public static void setAutoDeploy(Player player, boolean autoDeploy)
{
((CraftPlayer) player).getHandle().setAutoWingsDeploy(autoDeploy);
}
public static void setGlidableWithoutWings(Player player, boolean glidableWithoutWings)
{
((CraftPlayer) player).getHandle().setGlidableWithoutWings(glidableWithoutWings);
}
public static void setAutoDeployDistance(Player player, float distance)
{
((CraftPlayer) player).getHandle().setWingsDeployAt(distance);
}
}

View File

@ -11,38 +11,40 @@ public class UtilShapes
{
private final static BlockFace[] radial =
{
BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.NORTH,
BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST
BlockFace.SOUTH,
BlockFace.SOUTH_WEST,
BlockFace.WEST,
BlockFace.NORTH_WEST,
BlockFace.NORTH,
BlockFace.NORTH_EAST,
BlockFace.EAST,
BlockFace.SOUTH_EAST
};
public static ArrayList<Location> getCircle(Location loc, boolean hollow, double radius)
{
return getCircleBlocks(loc, radius, 0, hollow, false);
return getSphereBlocks(loc, radius, 0, hollow);
}
public static ArrayList<Location> getSphereBlocks(Location loc, double radius, double height, boolean hollow)
{
return getCircleBlocks(loc, radius, height, hollow, true);
}
private static ArrayList<Location> getCircleBlocks(Location loc, double radius, double height, boolean hollow, boolean sphere)
public static ArrayList<Location> getSphereBlocks(Location loc, double width, double height, boolean hollow)
{
ArrayList<Location> circleblocks = new ArrayList<Location>();
double cx = loc.getBlockX();
double cy = loc.getBlockY();
double cz = loc.getBlockZ();
for (double y = (sphere ? cy - radius : cy); y < (sphere ? cy + radius : cy + height + 1); y++)
for (double y = height; y < height + 1; y++)
{
for (double x = cx - radius; x <= cx + radius; x++)
for (double x = -width; x <= width; x++)
{
for (double z = cz - radius; z <= cz + radius; z++)
for (double z = -width; z <= width; z++)
{
double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0);
double dist = (x * x) + (z * z) + (y * y);
if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1)))
if (dist < width * width
&& !(hollow && Math.abs(x) - width < 1 && Math.abs(z) - width < 1 && Math.abs(y) - height < 1))
{
Location l = new Location(loc.getWorld(), x, y, z);
Location l = new Location(loc.getWorld(), x + cx, y + cy, z + cz);
circleblocks.add(l);
}
}
@ -75,7 +77,8 @@ public class UtilShapes
right = radial[high];
return new BlockFace[]
{
left, right
left,
right
};
}
}
@ -87,13 +90,19 @@ public class UtilShapes
BlockFace[] faces = getSideBlockFaces(facing);
return new Block[]
{
b.getRelative(faces[0]), b.getRelative(faces[1])
b.getRelative(faces[0]),
b.getRelative(faces[1])
};
}
public static BlockFace getFacing(float yaw)
{
return radial[Math.round(yaw / 45f) & 0x7];
return radial[Math.round(yaw / 45f) % 8];
}
public static float getFacing(BlockFace face)
{
return UtilAlg.GetYaw(new Vector(face.getModX(), face.getModY(), face.getModZ()).normalize());
}
public static ArrayList<Location> getLinesDistancedPoints(Location startingPoint, Location endingPoint,
@ -133,6 +142,24 @@ public class UtilShapes
return locs;
}
/**
* Rotates the blocks around 0,0,0
*/
public static ArrayList<Location> rotate(ArrayList<Location> locs, double degree)
{
ArrayList<Location> rotated = new ArrayList<Location>();
for (Location loc : locs)
{
double xRot = Math.cos(degree) * (loc.getX()) - Math.sin(degree) * (loc.getZ());
double zRot = loc.getZ() + Math.sin(degree) * (loc.getX()) + Math.cos(degree) * (loc.getZ());
rotated.add(new Location(loc.getWorld(), xRot, loc.getY(), zRot));
}
return rotated;
}
public static ArrayList<Location> getDistancedCircle(Location center, double pointsDistance, double circleRadius)
{
return getPointsInCircle(center, (int) ((circleRadius * Math.PI * 2) / pointsDistance), circleRadius);
@ -157,12 +184,14 @@ public class UtilShapes
new int[]
{
allowDiagonal ? facing.getModX() : facing.getModZ(), allowDiagonal ? 0 : -facing.getModX()
allowDiagonal ? facing.getModX() : facing.getModZ(),
allowDiagonal ? 0 : -facing.getModX()
},
new int[]
{
allowDiagonal ? 0 : -facing.getModZ(), allowDiagonal ? facing.getModZ() : facing.getModX()
allowDiagonal ? 0 : -facing.getModZ(),
allowDiagonal ? facing.getModZ() : facing.getModX()
}
};
@ -189,7 +218,8 @@ public class UtilShapes
{
faces = new BlockFace[]
{
faces[1], faces[0]
faces[1],
faces[0]
};
}
@ -228,7 +258,8 @@ public class UtilShapes
return new Block[]
{
b.getRelative(faces[0]), b.getRelative(faces[1])
b.getRelative(faces[0]),
b.getRelative(faces[1])
};
}

View File

@ -28,6 +28,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_8_R3.PacketPlayOutNewAttachEntity;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
@ -67,12 +68,12 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
{
super("Custom Tag Fix", plugin);
packetHandler.addPacketHandler(this, true, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class,
PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class,
PacketPlayOutNamedEntitySpawn.class, PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class);
packetHandler.addPacketHandler(this, true, PacketPlayOutEntityDestroy.class, PacketPlayOutEntityMetadata.class,
PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutNamedEntitySpawn.class,
PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class, PacketPlayOutNewAttachEntity.class);
// NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
// NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
// NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
// NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
NCPHookManager.addHook(CheckType.ALL, this);
}
@ -257,15 +258,16 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
return;
}
int newId = UtilEnt.getNewEntityId();
Integer[] ids = new Integer[]
{
UtilEnt.getNewEntityId(),
UtilEnt.getNewEntityId()
};
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
_entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[]
{
newId
});
_entityMap.get(owner.getName()).put(spawnPacket.a, ids);
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true, -1);
sendProtocolPackets(owner, spawnPacket.a, entityName, verifier, true, ids);
break;
}
}
@ -302,17 +304,16 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
return;
}
int newId = UtilEnt.getNewEntityId();
int newId2 = UtilEnt.getNewEntityId();
Integer[] ids = new Integer[]
{
UtilEnt.getNewEntityId(),
UtilEnt.getNewEntityId()
};
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
_entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[]
{
newId,
newId2
});
_entityMap.get(owner.getName()).put(spawnPacket.a, ids);
sendProtocolPackets(owner, spawnPacket.a, newId2, entityName, verifier, true, newId);
sendProtocolPackets(owner, spawnPacket.a, entityName, verifier, true, ids);
break;
}
}
@ -332,13 +333,13 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
}
String newName = currentName;
boolean newDisplay = isDisplaying;
boolean displayName = isDisplaying;
for (WatchableObject watchable : (List<WatchableObject>) metaPacket.b)
{
if (watchable.a() == 3 && watchable.b() instanceof Byte)
{
newDisplay = ((Byte) watchable.b()) == 1;
displayName = ((Byte) watchable.b()) == 1;
}
if (watchable.a() == 2 && watchable.b() instanceof String)
@ -348,10 +349,10 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
}
// If the name has changed and the name should be showing, or the name display status has changed.
if ((!newName.equals(currentName) && newDisplay) || newDisplay != isDisplaying)
if ((!newName.equals(currentName) && displayName) || displayName != isDisplaying)
{
// If name is still being displayed
if (newDisplay)
if (displayName)
{
Integer[] newId;
@ -364,6 +365,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
{
newId = new Integer[]
{
UtilEnt.getNewEntityId(),
UtilEnt.getNewEntityId()
};
@ -371,7 +373,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
}
_entityNameMap.get(owner.getName()).put(metaPacket.a, newName);
sendProtocolPackets(owner, metaPacket.a, newId[0], newName, verifier, !isDisplaying, -1);
sendProtocolPackets(owner, metaPacket.a, newName, verifier, !isDisplaying, newId);
}
else
{ // Lets delete it
@ -452,9 +454,25 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
}
}
}
else if (packet instanceof PacketPlayOutAttachEntity)
else if (packet instanceof PacketPlayOutAttachEntity || packet instanceof PacketPlayOutNewAttachEntity)
{
PacketPlayOutAttachEntity attachPacket = (PacketPlayOutAttachEntity) packet;
int vech = -1;
int rider = -1;
if (packet instanceof PacketPlayOutAttachEntity)
{
PacketPlayOutAttachEntity attachPacket = (PacketPlayOutAttachEntity) packet;
vech = attachPacket.b;
rider = attachPacket.c;
}
else if (packet instanceof PacketPlayOutNewAttachEntity)
{
PacketPlayOutNewAttachEntity attachPacket = (PacketPlayOutNewAttachEntity) packet;
vech = attachPacket.a;
if (attachPacket.b.length > 0)
rider = attachPacket.b[0];
}
// c = rider, b = ridden
// When detaching, c is sent, b is -1
@ -473,27 +491,27 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
int vehicleId = -1;
if (_entityRiding.get(owner.getName()).containsKey(attachPacket.b))
if (_entityRiding.get(owner.getName()).containsKey(vech))
{
vehicleId = _entityRiding.get(owner.getName()).get(attachPacket.b);
vehicleId = _entityRiding.get(owner.getName()).get(vech);
}
if (attachPacket.c == -1 && _entityMap.get(owner.getName()).containsKey(vehicleId))
if (rider == -1 && _entityMap.get(owner.getName()).containsKey(vehicleId))
{
Integer[] ids = _entityMap.get(owner.getName()).get(vehicleId);
_entityRiding.get(owner.getName()).remove(attachPacket.b);
_entityRiding.get(owner.getName()).remove(vech);
sendProtocolPackets(owner, vehicleId, ids[ids.length - 1], _entityNameMap.get(owner.getName()).get(vehicleId),
verifier, true, ids.length > 1 ? ids[0] : -1);
sendProtocolPackets(owner, vehicleId, _entityNameMap.get(owner.getName()).get(vehicleId), verifier, true,
ids);
}
else
{
Integer[] ids = _entityMap.get(owner.getName()).get(attachPacket.c);
Integer[] ids = _entityMap.get(owner.getName()).get(rider);
if (ids != null && ids[0] != attachPacket.b)
if (ids != null && ids[1] != vech)
{
_entityRiding.get(owner.getName()).put(attachPacket.b, attachPacket.c);
_entityRiding.get(owner.getName()).put(vech, rider);
int[] newIds = new int[ids.length];
@ -509,8 +527,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
}
}
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName,
final PacketVerifier packetList, final boolean newPacket, final int squidId)
private void sendProtocolPackets(final Player owner, final int entityId, String entityName, final PacketVerifier packetList,
final boolean newPacket, final Integer[] entityIds)
{
CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName);
_plugin.getServer().getPluginManager().callEvent(event);
@ -522,60 +540,81 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
{
DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
watcher.a(0, (byte) (0 | 1 << 5), Entity.META_ENTITYDATA, (byte) (0 | 1 << 5)); // Invisible
watcher.a(0, (byte) 32, Entity.META_ENTITYDATA, (byte) 32); // Invisible
watcher.a(1, Short.valueOf((short) 300), Entity.META_AIR, 0);
watcher.a(2, finalEntityName, Entity.META_CUSTOMNAME, finalEntityName);
watcher.a(3, (byte) 1, Entity.META_CUSTOMNAME_VISIBLE, true);
watcher.a(10, (byte) (0 | 0x1), EntityArmorStand.META_ARMOR_OPTION, (byte) (0 | 0x1)); // Small
watcher.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); // Small
if (newPacket)
{
if (squidId >= 0)
{
watcher.watch(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16);
DataWatcher squidWatcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
squidWatcher.a(0, (byte) (0 | 1 << 5), Entity.META_ENTITYDATA, (byte) (0 | 1 << 5));
squidWatcher.a(0, (byte) 32, Entity.META_ENTITYDATA, (byte) 32);
PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
spawnPacket.a = squidId;
spawnPacket.a = entityIds[1];
spawnPacket.b = (byte) EntityType.SQUID.getTypeId();
spawnPacket.c = 1000000;
spawnPacket.c = owner.getLocation().getBlockX() * 32;
spawnPacket.d = -150;
spawnPacket.e = owner.getLocation().getBlockZ() * 32;
spawnPacket.l = squidWatcher;
spawnPacket.uuid = UUID.randomUUID();
UtilPlayer.sendPacket(owner, spawnPacket);
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
vehiclePacket.a = 0;
vehiclePacket.b = spawnPacket.a;
vehiclePacket.c = entityId;
if (UtilPlayer.is1_9(owner))
{
UtilPlayer.sendPacket(owner, new PacketPlayOutNewAttachEntity(entityId, new int[]
{
entityIds[1]
}));
}
else
{
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
vehiclePacket.a = 0;
vehiclePacket.b = spawnPacket.a;
vehiclePacket.c = entityId;
UtilPlayer.sendPacket(owner, vehiclePacket);
UtilPlayer.sendPacket(owner, vehiclePacket);
}
}
PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
spawnPacket.a = newEntityId;
spawnPacket.a = entityIds[0];
spawnPacket.b = (byte) 30;
spawnPacket.c = 1000000;
spawnPacket.c = owner.getLocation().getBlockX() * 32;
spawnPacket.d = -150;
spawnPacket.e = owner.getLocation().getBlockZ() * 32;
spawnPacket.l = watcher;
spawnPacket.uuid = UUID.randomUUID();
UtilPlayer.sendPacket(owner, spawnPacket);
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
vehiclePacket.a = 0;
vehiclePacket.b = spawnPacket.a;
vehiclePacket.c = squidId >= 0 ? squidId : entityId;
if (UtilPlayer.is1_9(owner))
{
UtilPlayer.sendPacket(owner, new PacketPlayOutNewAttachEntity(entityIds[1], new int[]
{
entityIds[0]
}));
}
else
{
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
vehiclePacket.a = 0;
vehiclePacket.b = entityIds[0];
vehiclePacket.c = entityIds[1];
UtilPlayer.sendPacket(owner, vehiclePacket);
UtilPlayer.sendPacket(owner, vehiclePacket);
}
}
else
{
PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata();
entityMetadata.a = newEntityId;
entityMetadata.a = entityIds[0];
entityMetadata.b = watcher.c();
packetList.bypassProcess(entityMetadata);

View File

@ -1,11 +1,15 @@
package mineplex.core;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import mineplex.core.command.CommandCenter;
import mineplex.core.command.ICommand;
import mineplex.core.common.util.F;
@ -15,6 +19,9 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
public abstract class MiniPlugin implements Listener
{
private static final ExecutorService threadPool = Executors.newCachedThreadPool(
new ThreadFactoryBuilder().setNameFormat("MiniPlugin Async %1$d").build());
protected String _moduleName = "Default";
protected JavaPlugin _plugin;
protected NautHashMap<String, ICommand> _commands;
@ -105,7 +112,8 @@ public abstract class MiniPlugin implements Listener
public void runAsync(Runnable runnable)
{
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable);
// Instead of using
threadPool.execute(runnable);
}
public void runAsync(Runnable runnable, long time)

View File

@ -1,8 +1,8 @@
package mineplex.core.account;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
@ -49,9 +49,8 @@ public class CoreClientManager extends MiniPlugin
private NautHashMap<String, CoreClient> _clientList;
private HashSet<String> _duplicateLoginGlitchPreventionList;
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
private LinkedList<IQuerylessLoginProcessor> _querylessLoginProcessors = new LinkedList<IQuerylessLoginProcessor>();
private List<ILoginProcessor> _loginProcessors = new ArrayList<>();
private Object _clientLock = new Object();
private static AtomicInteger _clientsConnecting = new AtomicInteger(0);
@ -260,7 +259,7 @@ public class CoreClientManager extends MiniPlugin
CoreClient client = Add(playerName);
client.SetRank(Rank.valueOf(token.Rank), false);
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName()));
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -332,7 +331,7 @@ public class CoreClientManager extends MiniPlugin
CoreClient client = Add(playerName);
client.SetRank(Rank.valueOf(token.Rank), false);
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName()));
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
@ -373,12 +372,12 @@ public class CoreClientManager extends MiniPlugin
_clientLoginLock.put(client.GetPlayerName(), new Object());
ClientToken token = null;
Gson gson = new Gson();
runAsync(new Runnable()
{
public void run()
{
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName()));
_clientLoginLock.remove(client.GetPlayerName());
}
});
@ -386,7 +385,8 @@ public class CoreClientManager extends MiniPlugin
TimingManager.start(client.GetPlayerName() + " GetClient.");
String response = _repository.GetClient(client.GetPlayerName(), uuid, ipAddress);
TimingManager.stop(client.GetPlayerName() + " GetClient.");
TimingManager.start(client.GetPlayerName() + " Event.");
token = gson.fromJson(response, ClientToken.class);
client.SetRank(Rank.valueOf(token.Rank), false);
@ -395,7 +395,9 @@ public class CoreClientManager extends MiniPlugin
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
TimingManager.stop(client.GetPlayerName() + " Event.");
TimingManager.start(client.GetPlayerName() + " While Loop.");
while (_clientLoginLock.containsKey(client.GetPlayerName()) && System.currentTimeMillis() - timeStart < 15000)
{
try
@ -407,6 +409,7 @@ public class CoreClientManager extends MiniPlugin
e.printStackTrace();
}
}
TimingManager.stop(client.GetPlayerName() + " While Loop.");
if (_clientLoginLock.containsKey(client.GetPlayerName()))
{
@ -646,14 +649,9 @@ public class CoreClientManager extends MiniPlugin
public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
{
_loginProcessors.put(processor.getName(), processor);
_loginProcessors.add(processor);
}
public void addStoredProcedureLoginProcessor(IQuerylessLoginProcessor processor)
{
_querylessLoginProcessors.add(processor);
}
public boolean hasRank(Player player, Rank rank)
{
CoreClient client = Get(player);
@ -662,10 +660,4 @@ public class CoreClientManager extends MiniPlugin
return client.GetRank().has(rank);
}
public int getCachedClientAccountId(UUID uuid)
{
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
return playerInfo == null ? -1 : playerInfo.getAccountId();
}
}

View File

@ -6,30 +6,28 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.Bukkit;
import com.google.gson.reflect.TypeToken;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.cache.player.PlayerCache;
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.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
{
@ -59,100 +57,66 @@ public class AccountRepository extends MinecraftRepository
//executeUpdate(CREATE_ACCOUNT_TABLE);
}
public int login(NautHashMap<String, ILoginProcessor> loginProcessors, LinkedList<IQuerylessLoginProcessor> querylessLoginProcessors, String uuid, String name)
public int login(final List<ILoginProcessor> loginProcessors, final UUID uuid, final String name)
{
// First we try to grab the account id from cache - this saves an extra trip to database
int accountId = -1;
try (
Connection connection = getConnection();
Statement statement = connection.createStatement()
)
try (Connection connection = getConnection(); Statement statement = connection.createStatement())
{
statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;");
ResultSet resultSet = statement.getResultSet();
while (resultSet.next())
int cachedId = PlayerCache.getInstance().getAccountId(uuid);
if (cachedId > 0)
{
accountId = resultSet.getInt(1);
accountId = cachedId;
System.out.println("Loaded Account ID From Cache [" + name + " - " + accountId + "]");
}
if (accountId == -1)
else
{
final List<Integer> tempList = new ArrayList<Integer>(1);
executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
tempList.add(resultSet.getInt(1));
}
}
},new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name));
accountId = tempList.get(0);
}
/*
boolean statementStatus = statement.execute(
"UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"
+ "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';"
+ "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = '" + uuid + "';"
+ "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';"
);
*/
// Player was not found in cache, we need to grab the account id from database
statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;");
ResultSet resultSet = statement.getResultSet();
String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';";
for (ILoginProcessor loginProcessor : loginProcessors.values())
{
loginString += loginProcessor.getQuery(accountId, uuid, name);
}
statement.execute(loginString);
/*
while (true)
{
if (statementStatus)
if (resultSet.next())
{
System.out.println("ResultSet : " + statement.getResultSet().getMetaData().getColumnCount() + " columns:");
for (int i = 0; i < statement.getResultSet().getMetaData().getColumnCount(); i++)
{
System.out.println(statement.getResultSet().getMetaData().getColumnName(i + 1));
}
accountId = resultSet.getInt(1);
}
else
{
if (statement.getUpdateCount() == -1)
break;
// Player doesn't exist in our database, add them to the accounts table
final List<Integer> tempList = new ArrayList<Integer>(1);
System.out.println("Update statement : " + statement.getUpdateCount() + " rows affected.");
executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
tempList.add(resultSet.getInt(1));
}
}
}, new ColumnVarChar("uuid", 100, uuid.toString()), new ColumnVarChar("name", 100, name));
accountId = tempList.get(0);
}
statementStatus = statement.getMoreResults();
}
System.out.println("Done");
*/
final int finalId = accountId;
final String uuidString = uuid.toString();
String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';";
// We can use a parallel stream because they will be in the correct order when we collect
loginString += loginProcessors.parallelStream().map(processor -> processor.getQuery(finalId, uuidString, name)).collect(Collectors.joining());
statement.execute(loginString);
statement.getUpdateCount();
statement.getMoreResults();
for (ILoginProcessor loginProcessor : loginProcessors.values())
{
loginProcessor.processLoginResultSet(name, accountId, statement.getResultSet());
statement.getMoreResults();
}
for (IQuerylessLoginProcessor loginProcessor : querylessLoginProcessors)
for (ILoginProcessor loginProcessor : loginProcessors)
{
loginProcessor.processLogin(name, accountId);
loginProcessor.processLoginResultSet(name, finalId, statement.getResultSet());
statement.getMoreResults();
}
}
catch (Exception exception)

View File

@ -917,7 +917,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (client.getHologram() == null)
{
double yAdd = 2.18;
double yAdd = 2.3;
hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), "");
hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST);
hologram.addPlayer(player);

View File

@ -5,6 +5,8 @@ import net.minecraft.server.v1_8_R3.EntityWither;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import mineplex.core.common.util.UtilMath;
public class DisguiseWither extends DisguiseMonster
{
public DisguiseWither(org.bukkit.entity.Entity entity)
@ -24,6 +26,7 @@ public class DisguiseWither extends DisguiseMonster
public void setInvulTime(int i)
{
DataWatcher.watch(17, Integer.valueOf(i), EntityWither.META_INVUL_TIME, i);
DataWatcher.watch(20, Integer.valueOf(i), EntityWither.META_INVUL_TIME, i);
}

View File

@ -21,6 +21,7 @@ public enum GameDisplay
Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.ARCADE, 13),
DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 14),
Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CLASSICS, 15),
ElytraRings("Elytra Rings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61),
Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.ARCADE, 16),
Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.EXTRA, 18),
Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 19),

View File

@ -131,7 +131,11 @@ public class PersonalServerManager extends MiniPlugin
}
if (eventServer)
{
ram = 4096;
cpu = 8;
createGroup(player, "EVENT", ram, cpu, 40, 80, "Event", eventServer);
}
else
createGroup(player, serverName, ram, cpu, 40, 80, "Smash", eventServer);
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
@ -101,12 +102,6 @@ public class TreasureLocation implements Listener
return;
}
if (!chargeAccount(player, treasureType))
{
player.sendMessage(F.main("Treasure", "You dont have any chests to open!"));
return;
}
TreasureStartEvent event = new TreasureStartEvent(player);
Bukkit.getPluginManager().callEvent(event);
@ -115,48 +110,73 @@ public class TreasureLocation implements Listener
return;
}
// Treasure is now being opened
setHoloChestVisible(false);
if (treasureType == TreasureType.ANCIENT)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening an " + treasureType.getName()));
if (treasureType == TreasureType.MYTHICAL)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName()));
if (treasureType == TreasureType.CHRISTMAS)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName()));
Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardPool(), treasureType.getRewardType());
Treasure treasure = new Treasure(player, rewards, treasureType.getRewardType(), _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager, _statusManager);
_currentTreasure = treasure;
UtilTextMiddle.display(treasureType.getName(), "Choose 4 Chests To Open", 20, 180, 20, player);
UtilPlayer.message(player, F.main("Treasure", "Choose 4 Chests To Open"));
Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5);
teleportLocation.setPitch(player.getLocation().getPitch());
teleportLocation.setYaw(player.getLocation().getYaw());
for (Entity entity : player.getNearbyEntities(3, 3, 3))
chargeAccount(player, treasureType, new Callback<Boolean>()
{
UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true);
}
@Override
public void run(Boolean success)
{
if (!success)
{
player.sendMessage(F.main("Treasure", "You dont have any chests to open!"));
}
else
{
if (isTreasureInProgress())
{
// Need to check again because of callback. Add item back
player.sendMessage(F.main("Treasure", "Please wait for the current chest to be opened"));
_inventoryManager.addItemToInventory(player, treasureType.getItemName(), 1);
return;
}
player.teleport(teleportLocation);
// Treasure is now being opened
setHoloChestVisible(false);
_treasureManager.addOpenStat(player, treasureType);
if (treasureType == TreasureType.ANCIENT)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening an " + treasureType.getName()));
if (treasureType == TreasureType.MYTHICAL)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName()));
if (treasureType == TreasureType.CHRISTMAS)
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName()));
Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardPool(), treasureType.getRewardType());
Treasure treasure = new Treasure(player, rewards, treasureType.getRewardType(), _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager, _statusManager);
_currentTreasure = treasure;
UtilTextMiddle.display(treasureType.getName(), "Choose 4 Chests To Open", 20, 180, 20, player);
UtilPlayer.message(player, F.main("Treasure", "Choose 4 Chests To Open"));
Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5);
teleportLocation.setPitch(player.getLocation().getPitch());
teleportLocation.setYaw(player.getLocation().getYaw());
for (Entity entity : player.getNearbyEntities(3, 3, 3))
{
UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true);
}
player.teleport(teleportLocation);
_treasureManager.addOpenStat(player, treasureType);
}
}
});
}
private boolean chargeAccount(Player player, TreasureType treasureType)
private void chargeAccount(Player player, TreasureType treasureType, Callback<Boolean> callback)
{
int itemCount = _inventoryManager.Get(player).getItemCount(treasureType.getItemName());
if (itemCount > 0)
{
_inventoryManager.addItemToInventory(player, treasureType.getItemName(), -1);
return true;
// Should always handle the callback for us
_inventoryManager.addItemToInventory(callback, player, treasureType.getItemName(), -1);
}
else
{
callback.run(false);
}
return false;
}
private void setHoloChestVisible(boolean visible)

View File

@ -216,7 +216,7 @@ public class Arcade extends JavaPlugin
for (String gameName : _serverConfiguration.getServerGroup().getGames().split(","))
{
try
{
{System.out.println(gameName);
GameType type = GameType.valueOf(gameName);
config.GameList.add(type);
}

View File

@ -105,6 +105,7 @@ import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.player.ArcadePlayer;
import nautilus.game.arcade.shop.ArcadeShop;
import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -871,6 +872,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
UtilInv.Clear(player);
UtilPlayer.setAutoDeploy(player, false);
UtilPlayer.setGlidableWithoutWings(player, false);
UtilPlayer.setGliding(player, false);
UtilPlayer.setAutoDeployDistance(player, 1.15F);
((CraftEntity) player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0), EntityLiving.META_ENTITYDATA, (byte) 0);
player.setCustomName("");

View File

@ -41,6 +41,7 @@ import nautilus.game.arcade.game.games.oldmineware.OldMineWare;
import nautilus.game.arcade.game.games.paintball.Paintball;
import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.QuiverTeams;
import nautilus.game.arcade.game.games.rings.ElytraRings;
import nautilus.game.arcade.game.games.runner.Runner;
import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy;
import nautilus.game.arcade.game.games.sheep.SheepGame;
@ -89,6 +90,7 @@ public enum GameType
Dragons(Dragons.class, GameDisplay.Dragons),
DragonsTeams(DragonsTeams.class, GameDisplay.DragonsTeams),
Draw(Draw.class, GameDisplay.Draw, "http://chivebox.com/mineplex/ResDrawMyThing.zip", true),
ElytraRings(ElytraRings.class, GameDisplay.ElytraRings),
Evolution(Evolution.class, GameDisplay.Evolution),
Gravity(Gravity.class, GameDisplay.Gravity),
Halloween(Halloween.class, GameDisplay.Halloween, "http://file.mineplex.com/ResHalloween.zip", true),

View File

@ -240,54 +240,45 @@ public class HideSeek extends TeamGame
for (Entry<Player, Form> entry : _forms.entrySet())
{
if (entry.getValue() instanceof BlockForm)
if (!(entry.getValue() instanceof BlockForm))
continue;
final BlockForm blockForm = (BlockForm) entry.getValue();
if (blockForm.Player.getEntityId() != id || blockForm.Player == packetInfo.getPlayer())
continue;
final Player player = packetInfo.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
final BlockForm blockForm = (BlockForm) entry
.getValue();
if (blockForm.Player.getEntityId() == id
&& blockForm.Player != packetInfo.getPlayer())
public void run()
{
final Player player = packetInfo.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(
Manager.getPlugin(), new Runnable()
{
public void run()
{
UtilPlayer
.sendPacket(
player,
blockForm
.getBlockPackets(UtilPlayer.is1_9(player)));
}
});
break;
UtilPlayer.sendPacket(player, blockForm.getBlockPackets(UtilPlayer.is1_9(player)));
}
}
});
break;
}
}
else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy)
{
for (int i : ((PacketPlayOutEntityDestroy) packetInfo
.getPacket()).a)
for (int i : ((PacketPlayOutEntityDestroy) packetInfo.getPacket()).a)
{
for (Entry<Player, Form> entry : _forms.entrySet())
{
if (entry.getValue() instanceof BlockForm)
{
BlockForm blockForm = (BlockForm) entry.getValue();
if (!(entry.getValue() instanceof BlockForm))
continue;
if (blockForm.Player.getEntityId() == i)
BlockForm blockForm = (BlockForm) entry.getValue();
if (blockForm.Player.getEntityId() != i)
continue;
UtilPlayer.sendPacket(packetInfo.getPlayer(), new PacketPlayOutEntityDestroy(new int[]
{
UtilPlayer.sendPacket(packetInfo.getPlayer(),
new PacketPlayOutEntityDestroy(
new int[]
{
blockForm.getBlockId()
}));
}
}
blockForm.getBlockId()
}));
}
}
}

View File

@ -54,8 +54,8 @@ public class BlockForm extends Form
private int _entityId;
private Location _loc;
private int _selfEntityId1;
private int _selfEntityId2;
private int _fakeSilverfishId;
private int _fakeBlockId;
private Vector _lastSaw;
private Vector _sawDiff = new Vector();
private int _blockId = UtilEnt.getNewEntityId();
@ -66,8 +66,8 @@ public class BlockForm extends Form
_mat = mat;
_loc = player.getLocation();
_selfEntityId1 = UtilEnt.getNewEntityId();
_selfEntityId2 = UtilEnt.getNewEntityId();
_fakeSilverfishId = UtilEnt.getNewEntityId();
_fakeBlockId = UtilEnt.getNewEntityId();
System.out.println("Block Form: " + _mat + " " + _mat.getId());
}
@ -100,7 +100,7 @@ public class BlockForm extends Form
Packet[] packets = new Packet[3];
PacketPlayOutSpawnEntityLiving packet1 = new PacketPlayOutSpawnEntityLiving();
packet1.a = _selfEntityId1;
packet1.a = _fakeSilverfishId;
packet1.b = EntityType.SILVERFISH.getTypeId();
packet1.c = (int) Math.floor(_lastSaw.getX() * 32);
packet1.d = (int) Math.floor(_lastSaw.getY() * 32);
@ -114,9 +114,9 @@ public class BlockForm extends Form
if (UtilPlayer.is1_9(Player))
{
packets[2] = new PacketPlayOutNewAttachEntity(_selfEntityId1, new int[]
packets[2] = new PacketPlayOutNewAttachEntity(_fakeSilverfishId, new int[]
{
_selfEntityId2
_fakeBlockId
});
}
@ -124,14 +124,14 @@ public class BlockForm extends Form
{
PacketPlayOutAttachEntity packet3 = new PacketPlayOutAttachEntity();
packet3.b = _selfEntityId2;
packet3.c = _selfEntityId1;
packet3.b = _fakeBlockId;
packet3.c = _fakeSilverfishId;
packets[2] = packet3;
}
PacketPlayOutSpawnEntity packet2 = new PacketPlayOutSpawnEntity(player, 70, _mat.getId());
packet2.a = _selfEntityId2;
packet2.a = _fakeBlockId;
packet2.uuid = UUID.randomUUID();
packets[1] = packet2;
@ -140,16 +140,11 @@ public class BlockForm extends Form
// Inform
String blockName = F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false));
if (!blockName.contains("Block"))
UtilPlayer.message(
Player,
F.main("Game",
C.cWhite + "You are now a "
+ F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!"));
UtilPlayer.message(Player, F.main("Game", C.cWhite + "You are now a "
+ F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!"));
else
UtilPlayer.message(
Player,
F.main("Game", C.cWhite + "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false))
+ "!"));
UtilPlayer.message(Player, F.main("Game",
C.cWhite + "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) + "!"));
// Give Item
Player.getInventory().setItem(8, new ItemStack(Host.GetItemEquivilent(_mat)));
@ -171,11 +166,11 @@ public class BlockForm extends Form
if (is19)
{
packets[2] = new PacketPlayOutNewAttachEntity(_blockId, new int[]
packets[1] = new PacketPlayOutNewAttachEntity(Player.getEntityId(), new int[]
{
Player.getEntityId()
});
_blockId
});
}
else
{
@ -203,8 +198,8 @@ public class BlockForm extends Form
UtilPlayer.sendPacket(Player, new PacketPlayOutEntityDestroy(new int[]
{
_selfEntityId1,
_selfEntityId2,
_fakeSilverfishId,
_fakeBlockId,
_blockId
}));
@ -214,8 +209,8 @@ public class BlockForm extends Form
public void SolidifyUpdate()
{
if (!Player.isSprinting())
((CraftEntity) Player).getHandle().getDataWatcher()
.watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32);
((CraftEntity) Player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA,
(byte) 32);
// Not a Block
if (_block == null)
@ -273,26 +268,26 @@ public class BlockForm extends Form
_sawDiff.add(blockLoc.clone().subtract(_lastSaw));
Packet packet = this.getPacket(_sawDiff, blockLoc);
Packet[] packet = this.getPacket(_sawDiff, blockLoc);
_lastSaw = Player.getLocation().toVector().subtract(new Vector(0, 0.15625, 0));
_sawDiff = _lastSaw.clone().subtract(blockLoc);
if (packet != null)
{
if (packet instanceof PacketPlayOutEntityTeleport)
if (packet[0] instanceof PacketPlayOutEntityTeleport)
{
_sawDiff = new Vector();
}
((CraftPlayer) Player).getHandle().playerConnection.sendPacket(packet);
UtilPlayer.sendPacket(Player, packet[UtilPlayer.is1_9(Player) ? 1 : 0]);
}
for (Player player : UtilServer.getPlayers())
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityDestroy(new int[]
{
getBlockId()
getBlockId()
}));
}
}
@ -321,8 +316,8 @@ public class BlockForm extends Form
MapUtil.QuickChangeBlockAt(_block.getLocation(), 0, (byte) 0);
_block = null;
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) Player).getHandle().world).tracker.trackedEntities
.get(Player.getEntityId());
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) Player)
.getHandle().world).tracker.trackedEntities.get(Player.getEntityId());
if (tracker != null)
{
@ -374,13 +369,13 @@ public class BlockForm extends Form
_lastSaw = Player.getLocation().subtract(0, 0.15625, 0).toVector();
Packet packet = this.getPacket(_sawDiff, _lastSaw);
Packet[] packet = this.getPacket(_sawDiff, _lastSaw);
if (packet != null)
{
if (packet instanceof PacketPlayOutRelEntityMove)
if (!UtilPlayer.is1_9(Player) && packet[0] instanceof PacketPlayOutRelEntityMove)
{
PacketPlayOutRelEntityMove relPacket = (PacketPlayOutRelEntityMove) packet;
PacketPlayOutRelEntityMove relPacket = (PacketPlayOutRelEntityMove) packet[0];
_sawDiff.subtract(new Vector(relPacket.b / 32D, relPacket.c / 32D, relPacket.d / 32D));
}
else
@ -388,12 +383,12 @@ public class BlockForm extends Form
_sawDiff = new Vector();
}
UtilPlayer.sendPacket(Player, packet);
UtilPlayer.sendPacket(Player, packet[UtilPlayer.is1_9(Player) ? 1 : 0]);
}
}
}
private Packet getPacket(Vector blocksFromNewPosition, Vector newPosition)
private Packet[] getPacket(Vector blocksFromNewPosition, Vector newPosition)
{
int x = (int) Math.floor(blocksFromNewPosition.getX() * 32);
int y = (int) Math.floor(blocksFromNewPosition.getY() * 32);
@ -401,26 +396,33 @@ public class BlockForm extends Form
if (x != 0 || y != 0 || z != 0)
{
Packet[] packets = new Packet[2];
if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127)
{
PacketPlayOutRelEntityMove relMove = new PacketPlayOutRelEntityMove();
relMove.a = this._selfEntityId1;
relMove.a = this._fakeSilverfishId;
relMove.b = (byte) x;
relMove.c = (byte) y;
relMove.d = (byte) z;
return relMove;
packets[0] = relMove;
}
else
{
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = _selfEntityId1;
teleportPacket.a = _fakeSilverfishId;
teleportPacket.b = (int) Math.floor(32 * newPosition.getX());
teleportPacket.c = (int) Math.floor(32 * newPosition.getY());
teleportPacket.d = (int) Math.floor(32 * newPosition.getZ());
return teleportPacket;
if (packets[0] == null)
packets[0] = teleportPacket;
packets[1] = teleportPacket;
}
return packets;
}
return null;

View File

@ -0,0 +1,253 @@
package nautilus.game.arcade.game.games.rings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.uhc.KitUHC;
import nautilus.game.arcade.kit.Kit;
public class ElytraRings extends SoloGame
{
private HashMap<Integer, Ring> _rings = new HashMap<Integer, Ring>();
private HashMap<UUID, Integer> _goneThrough = new HashMap<UUID, Integer>();
private HashMap<UUID, Location> _lastLocation = new HashMap<UUID, Location>();
public ElytraRings(ArcadeManager manager)
{
super(manager, GameType.ElytraRings, new Kit[]
{
// new KitElytraRings(manager)
}, new String[]
{
"Fly through the rings!"
});
DeathOut = false;
DeathMessages = false;
}
public void RespawnPlayer(final Player player)
{
player.eject();
if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId())))
{
Ring ring = _rings.get(_goneThrough.get(player.getUniqueId()));
player.teleport(ring.getCenter());
}
else if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1))
{
Ring ring = _rings.get(_goneThrough.get(player.getUniqueId()) + 1);
player.teleport(ring.getCenter());
}
else
{
player.teleport(GetTeam(player).GetSpawn());
}
Manager.Clear(player);
// Event
PlayerGameRespawnEvent event = new PlayerGameRespawnEvent(this, player);
UtilServer.getServer().getPluginManager().callEvent(event);
// Re-Give Kit
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
public void run()
{
GetKit(player).ApplyKit(player);
}
}, 0);
}
@Override
public void ParseData()
{
Location loc = UtilAlg.getAverageLocation(GetTeamList().get(0).GetSpawns());
BlockFace currentDirection = BlockFace.values()[UtilMath.r(4)];
while (_rings.size() < 30)
{
int dist = UtilMath.r(40);
loc = loc.getBlock().getRelative(currentDirection, 20).getLocation();
generateRing(loc, currentDirection, 2 + UtilMath.r(2) + UtilMath.r(2));
}
loc = loc.getBlock().getRelative(currentDirection, 20).getLocation();
Ring ring = generateRing(loc, currentDirection, 7);
for (Block b : ring.getRing())
{
b.setType(Material.GOLD_BLOCK);
}
}
@EventHandler
public void onGameStart(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
return;
for (Player player : this.GetPlayers(true))
{
player.getInventory().setChestplate(new ItemStack(Material.ELYTRA));
}
}
@EventHandler
public void onMove(PlayerMoveEvent event)
{
if (event.isCancelled())
return;
if (!IsAlive(event.getPlayer()))
return;
Player player = event.getPlayer();
int current = 1;
if (_goneThrough.containsKey(player.getUniqueId()))
{
current = _goneThrough.get(player.getUniqueId()) + 1;
}
if (!_rings.containsKey(current))
{
return;
}
Ring ring = _rings.get(current);
if (!ring.isMoveThroughRing(event.getFrom(), event.getTo()))
{
return;
}
_goneThrough.put(player.getUniqueId(), current + 1);
Announce(player.getName() + " has gone through ring " + current + "!");
}
@EventHandler
public void onSpeedBoost(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : GetPlayers(true))
{
float exp = player.getExp();
exp += 0.02;
if (exp > 0.05 && _lastLocation.containsKey(player.getUniqueId()))
{
UtilAction.velocity(player, player.getLocation().getDirection().multiply(0.3));
if (!_goneThrough.containsKey(player.getUniqueId())
|| _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1))
{
exp -= 0.05;
}
for (Location loc : UtilShapes.getLinesDistancedPoints(_lastLocation.get(player.getUniqueId()),
player.getLocation(), 0.3))
{
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, loc, 0.2F, 0.2F, 0.2F, 0, 3, ViewDist.LONGER);
}
_lastLocation.put(player.getUniqueId(), player.getLocation());
}
player.setExp(Math.min(exp, 1));
}
}
@EventHandler
public void onToggleSneak(PlayerToggleSneakEvent event)
{
if (!IsAlive(event.getPlayer()))
{
return;
}
Player player = event.getPlayer();
if (event.isSneaking() && UtilPlayer.isGliding(player))
{
_lastLocation.put(player.getUniqueId(), player.getLocation());
}
else
{
_lastLocation.remove(player.getUniqueId());
}
}
private Ring generateRing(Location center, BlockFace direction, int size)
{
ArrayList<Block> blocks = new ArrayList<Block>();
ArrayList<Block> hole = new ArrayList<Block>();
for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, true),
UtilShapes.getFacing(direction)))
{
blocks.add(loc.getBlock());
}
size--;
for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, false),
UtilShapes.getFacing(direction)))
{
hole.add(loc.getBlock());
}
center.setDirection(new Vector(direction.getModX(), direction.getModY(), direction.getModZ()));
Ring ring = new Ring(blocks, hole, center.clone());
for (Block b : ring.getRing())
{
b.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 4, false);
}
_rings.put(_rings.size() + 1, ring);
return ring;
}
}

View File

@ -0,0 +1,73 @@
package nautilus.game.arcade.game.games.rings;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
public class Ring
{
private ArrayList<Block> _core = new ArrayList<Block>();
private ArrayList<Block> _ring = new ArrayList<Block>();
private Location _center;
public Ring(ArrayList<Block> blocks, ArrayList<Block> inside, Location center)
{
_core = inside;
_ring = blocks;
_center = center;
}
public Location getCenter()
{
return _center;
}
public ArrayList<Block> getRing()
{
return _ring;
}
public boolean isMoveThroughRing(Location from, Location to)
{
from = from.clone();
to = to.clone();
from.setX(from.getBlockX() + 0.5);
from.setY(from.getBlockY() + 0.5);
from.setZ(from.getBlockZ() + 0.5);
to.setX(to.getBlockX() + 0.5);
to.setY(to.getBlockY() + 0.5);
to.setZ(to.getBlockZ() + 0.5);
Vector vec = UtilAlg.getTrajectory(from, to).multiply(0.5);
double dist = UtilMath.offset(from, to);
while (dist > 0)
{
dist -= 0.5;
Location loc = from.getBlock().getLocation().add(0.5, 0.5, 0.5);
if (_core.contains(loc.getBlock()))
return true;
if (_core.contains(loc.clone().add(loc.getX() == 0 ? 0 : loc.getX() > 0 ? 1 : -1, 0, 0)))
return true;
if (_core.contains(loc.clone().add(0, loc.getY() == 0 ? 0 : loc.getY() > 0 ? 1 : -1, 0)))
return true;
if (_core.contains(loc.clone().add(0, 0, loc.getZ() == 0 ? 0 : loc.getZ() > 0 ? 1 : -1)))
return true;
from.add(vec);
}
return false;
}
}