file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
ProtocolLegacyImpl.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/manager/ProtocolLegacyImpl.java | package gyurix.protocol.manager;
import gyurix.protocol.Protocol;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInEvent;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.event.PacketOutEvent;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.EntityUtils;
import net.minecraft.util.com.google.common.collect.MapMaker;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import net.minecraft.util.io.netty.channel.*;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static gyurix.protocol.Reflection.*;
import static gyurix.spigotlib.Main.pl;
public final class ProtocolLegacyImpl extends Protocol {
static final Field getGameProfile = getFirstFieldOfType(getNMSClass("PacketLoginInStart"), GameProfile.class),
playerConnectionF = getField(getNMSClass("EntityPlayer"), "playerConnection"),
networkManagerF = getField(getNMSClass("PlayerConnection"), "networkManager"),
channelF = getField(getNMSClass("NetworkManager"), "channel");
private static final Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
private static final Class minecraftServerClass = getNMSClass("MinecraftServer");
private static final Class serverConnectionClass = getNMSClass("ServerConnection");
private static Object oldH;
private static Field oldHChildF;
private ChannelFuture cf;
public ProtocolLegacyImpl() {
}
@Override
public Channel getChannel(Player plr) {
Channel c = channelLookup.get(plr.getName());
if (c == null)
try {
Object nmsPlayer = EntityUtils.getNMSEntity(plr);
Object playerConnection = playerConnectionF.get(nmsPlayer);
Object networkManager = networkManagerF.get(playerConnection);
Channel channel = (Channel) channelF.get(networkManager);
channelLookup.put(plr.getName(), c = channel);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return c;
}
@Override
public Player getPlayer(Object channel) {
ClientChannelHook ch = ((Channel) channel).pipeline().get(ClientChannelHook.class);
if (ch == null)
return null;
return ch.player;
}
@Override
public void init() throws Throwable {
Object minecraftServer = getFirstFieldOfType(Reflection.getOBCClass("CraftServer"), minecraftServerClass).get(SU.srv);
Object serverConnection = getFirstFieldOfType(minecraftServerClass, serverConnectionClass).get(minecraftServer);
cf = (ChannelFuture) ((List) getFirstFieldOfType(serverConnectionClass, List.class).get(serverConnection)).iterator().next();
registerServerChannelHook();
SU.srv.getOnlinePlayers().forEach(this::injectPlayer);
}
@Override
public void injectPlayer(final Player plr) {
getChannel(plr).pipeline().get(ClientChannelHook.class).player = plr;
}
@Override
public void printPipeline(Iterable<Map.Entry<String, ?>> pipeline) {
ArrayList<String> list = new ArrayList<>();
pipeline.forEach((e) -> list.add(e.getKey()));
SU.cs.sendMessage("§ePipeline: §f" + StringUtils.join(list, ", "));
}
@Override
public void receivePacket(Object channel, Object packet) {
if (packet instanceof WrappedPacket)
packet = ((WrappedPacket) packet).getVanillaPacket();
((Channel) channel).pipeline().context("encoder").fireChannelRead(packet);
}
@Override
public void registerServerChannelHook() throws Throwable {
Channel serverCh = cf.channel();
oldH = serverCh.pipeline().get(Reflection.getUtilClass("io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor"));
oldHChildF = Reflection.getField(oldH.getClass(), "childHandler");
serverCh.pipeline().addFirst("SpigotLibServer", new ServerChannelHook((ChannelHandler) oldHChildF.get(oldH)));
}
@Override
public void removeHandler(Object ch, String handler) {
try {
((Channel) ch).pipeline().remove(handler);
} catch (Throwable ignored) {
}
}
@Override
public void sendPacket(Object channel, Object packet) {
if (channel == null || packet == null) {
SU.error(SU.cs, new RuntimeException("§cFailed to send packet " + packet + " to channel " + channel), "SpigotLib", "gyurix");
return;
}
if (packet instanceof WrappedPacket)
packet = ((WrappedPacket) packet).getVanillaPacket();
((Channel) channel).pipeline().writeAndFlush(packet);
}
@Override
public void unregisterServerChannelHandler() throws IllegalAccessException {
removeHandler(cf.channel(), "SpigotLibServer");
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent e) {
injectPlayer(e.getPlayer());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin(PlayerLoginEvent e) {
injectPlayer(e.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(final PlayerQuitEvent e) {
final String pln = e.getPlayer().getName();
SU.sch.scheduleSyncDelayedTask(pl, () -> {
Player p = Bukkit.getPlayer(pln);
if (p == null)
channelLookup.remove(pln);
});
}
public class ClientChannelHook extends ChannelDuplexHandler {
public Player player;
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
try {
Channel channel = ctx.channel();
PacketInEvent e = new PacketInEvent(channel, player, packet);
if (e.getType() == PacketInType.LoginInStart) {
GameProfile profile = (GameProfile) getGameProfile.get(packet);
channelLookup.put(profile.getName(), channel);
}
dispatchPacketInEvent(e);
packet = e.getPacket();
if (!e.isCancelled())
ctx.fireChannelRead(packet);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
try {
PacketOutEvent e = new PacketOutEvent(ctx.channel(), player, packet);
dispatchPacketOutEvent(e);
packet = e.getPacket();
if (!e.isCancelled())
ctx.write(packet, promise);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
}
public class ServerChannelHook extends ChannelInboundHandlerAdapter {
public final ChannelHandler childHandler;
public ServerChannelHook(ChannelHandler childHandler) {
this.childHandler = childHandler;
}
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (childHandler.getClass().getName().equals("lilypad.bukkit.connect.injector.NettyChannelInitializer"))
Reflection.getField(childHandler.getClass(), "oldChildHandler").set(childHandler, oldHChildF.get(oldH));
Channel c = (Channel) msg;
c.pipeline().addLast("SpigotLibInit", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object o) throws Exception {
ChannelPipeline pipeline = ctx.pipeline();
pipeline.remove("SpigotLibInit");
pipeline.addBefore("packet_handler", "SpigotLib", new ClientChannelHook());
ctx.fireChannelRead(o);
}
});
ctx.fireChannelRead(msg);
}
}
}
| 7,778 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
WrappedPacket.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/WrappedPacket.java | package gyurix.protocol.wrappers;
import gyurix.protocol.utils.WrappedData;
/**
* Represents a wrapped (user friendly) form of a Vanilla/NMS packet.
*/
public abstract class WrappedPacket implements WrappedData {
/**
* Converts this wrapped packet to a Vanilla/NMS packet
*
* @return The conversion result, NMS packet
*/
public abstract Object getVanillaPacket();
/**
* Loads a Vanilla/NMS packet to this wrapper
*
* @param packet - The loadable packet
*/
public abstract void loadVanillaPacket(Object packet);
@Override
public Object toNMS() {
return getVanillaPacket();
}
}
| 625 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutBlockChange.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutBlockChange.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.BlockData;
import gyurix.spigotutils.BlockUtils;
/**
* Created by GyuriX, on 2017. 02. 05..
*/
public class PacketPlayOutBlockChange extends WrappedPacket {
public BlockData bd;
public BlockLocation loc;
public PacketPlayOutBlockChange() {
}
public PacketPlayOutBlockChange(BlockLocation loc, BlockData bd) {
this.loc = loc;
this.bd = bd;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.BlockChange.newPacket(loc.toNMS(), BlockUtils.combinedIdToNMSBlockData(BlockUtils.getCombinedId(bd)));
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.BlockChange.getPacketData(packet);
loc = new BlockLocation(d[0]);
bd = BlockUtils.combinedIdToBlockData(BlockUtils.getCombinedId(d[1]));
System.out.println(d[1] + " == " + BlockUtils.getCombinedId(d[1]) + " == " + bd);
}
}
| 1,085 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnEntityLiving.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnEntityLiving.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.DataWatcher;
import gyurix.protocol.utils.Vector;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.LocationData;
import gyurix.spigotutils.ServerVersion;
import org.bukkit.Location;
import java.util.UUID;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutSpawnEntityLiving extends WrappedPacket {
public int entityId;
public UUID entityUUID;
public DataWatcher meta;
/**
* 48 - Mob 49 - Monster 50 - Creeper 51 - Skeleton 52 - Spider 53 - Giant Zombie 54 - Zombie 55 - Slime 56 - Ghast
* 57 - Zombie Pigman 58 - Enderman 59 - Cave Spider 60 - Silverfish 61 - Blaze 62 - Magma Cube 63 - Ender Dragon 64
* - Wither 65 - Bat 66 - Witch 67 - Endermite 68 - Guardian 69 - Shulker 90 - Pig 91 - Sheep 92 - Cow 93 - Chicken
* 94 - Squid 95 - Wolf 96 - Mooshroom 97 - Snowman 98 - Ocelot 99 - Iron Golem 100 - Horse 101 - Rabbit 120 -
* Villager
*/
public int type;
public int velX, velY, velZ;
public double x, y, z;
public float yaw, pitch, headPitch;
public PacketPlayOutSpawnEntityLiving() {
}
public PacketPlayOutSpawnEntityLiving(int entityId, UUID entityUUID, int type, LocationData loc, float headPitch, Vector velocity, DataWatcher meta) {
this.entityId = entityId;
this.entityUUID = entityUUID;
this.type = type;
setLocation(loc);
this.headPitch = headPitch;
if (velocity != null)
setVelocity(velocity);
this.meta = meta;
}
public Location getLocation() {
return new Location(null, x, y, z, yaw, pitch);
}
public void setLocation(LocationData loc) {
x = loc.x;
y = loc.y;
z = loc.z;
yaw = loc.yaw;
pitch = loc.pitch;
}
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ? PacketOutType.SpawnEntityLiving.newPacket(entityId, entityUUID, type, x, y, z, velX, velY, velZ,
(byte) (yaw * 256 / 360), (byte) (pitch * 256 / 360), (byte) (headPitch * 256 / 360), meta.toNMS()) :
PacketOutType.SpawnEntityLiving.newPacket(entityId, type, (int) x * 32, (int) y * 32, (int) z * 32, velX, velY, velZ,
(byte) (yaw * 256 / 360), (byte) (pitch * 256 / 360), (byte) (headPitch * 256 / 360), meta.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.SpawnEntityLiving.getPacketData(packet);
entityId = (int) d[0];
int add = 0;
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
entityUUID = (UUID) d[1];
add = 1;
}
type = (int) d[add + 1];
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
x = (double) d[add + 2];
y = (double) d[add + 3];
z = (double) d[add + 4];
} else {
x = ((int) d[add + 2]) / 32.0;
y = ((int) d[add + 3]) / 32.0;
z = ((int) d[add + 4]) / 32.0;
}
velX = (int) d[add + 5];
velY = (int) d[add + 6];
velZ = (int) d[add + 7];
yaw = (float) ((byte) d[add + 8] / 256.0 * 360);
pitch = (float) ((byte) d[add + 9] / 256.0 * 360);
headPitch = (float) ((byte) d[add + 10] / 256.0 * 360);
meta = new DataWatcher(d[add + 11]);
}
public Vector getVelocity() {
return new Vector(velX / 8000.0, velY / 8000.0, velZ / 8000.0);
}
public void setVelocity(Vector velocity) {
velX = (int) (velocity.x * 8000);
velY = (int) (velocity.y * 8000);
velZ = (int) (velocity.z * 8000);
}
}
| 3,569 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutLogin.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutLogin.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WorldType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutLogin extends WrappedPacket {
public Difficulty difficulty;
/**
* Dimension -1: Nether 0: Overworld 1: End
*/
public int dimension;
public int entityId;
public GameMode gameMode;
public boolean hardcore;
public WorldType levelType;
public int maxPlayers;
public boolean reducedDebugInfo;
@Override
public Object getVanillaPacket() {
return PacketOutType.Login.newPacket(entityId, hardcore, WorldType.toVanillaGameMode(gameMode), dimension, WorldType.toVanillaDifficulty(difficulty), maxPlayers, levelType.toNMS(), reducedDebugInfo);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Login.getPacketData(packet);
entityId = (int) d[0];
hardcore = (boolean) d[1];
gameMode = GameMode.valueOf(d[2].toString());
dimension = (int) d[3];
difficulty = Difficulty.valueOf(d[4].toString());
maxPlayers = (int) d[5];
levelType = WorldType.fromVanillaWorldType(d[6]);
if (Reflection.ver.isAbove(ServerVersion.v1_8))
reducedDebugInfo = (boolean) d[7];
}
}
| 1,447 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnPosition.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnPosition.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutSpawnPosition extends WrappedPacket {
public BlockLocation location;
@Override
public Object getVanillaPacket() {
return PacketOutType.SpawnPosition.newPacket(location.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
location = new BlockLocation(PacketOutType.SpawnPosition.getPacketData(packet)[0]);
}
}
| 604 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutUpdateEntityNBT.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutUpdateEntityNBT.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.nbt.NBTCompound;
import gyurix.nbt.NBTTagType;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutUpdateEntityNBT extends WrappedPacket {
public int entityId;
public NBTCompound nbt;
public PacketPlayOutUpdateEntityNBT() {
}
@Override
public Object getVanillaPacket() {
return PacketOutType.UpdateEntityNBT.newPacket(entityId, nbt.toNMS());
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.UpdateEntityNBT.getPacketData(obj);
entityId = (int) data[0];
nbt = (NBTCompound) NBTTagType.tag(data[1]);
}
}
| 748 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutRecipeUpdate.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutRecipeUpdate.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PacketPlayOutRecipeUpdate extends WrappedPacket {
public List<Recipe> recipes = new ArrayList<>();
public PacketPlayOutRecipeUpdate() {
}
public PacketPlayOutRecipeUpdate(Recipe... recipes) {
this.recipes.addAll(Arrays.asList(recipes));
}
public static Recipe fromNMSRecipe(Object r) {
//TODO
return null;
}
public static List<Recipe> fromNMSRecipeList(Iterable<Object> recipes) {
List<Recipe> out = new ArrayList<>();
recipes.forEach(r -> out.add(fromNMSRecipe(r)));
return out;
}
public static Object toNMSRecipe(Recipe r) {
//TODO
return null;
}
public static List<Object> toNMSRecipeList(Iterable<Recipe> recipes) {
List<Object> out = new ArrayList<>();
recipes.forEach(r -> out.add(toNMSRecipe(r)));
return out;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.RecipeUpdate.newPacket(toNMSRecipeList(recipes));
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.RecipeUpdate.getPacketData(obj);
recipes = fromNMSRecipeList((Iterable<Object>) data[0]);
}
}
| 1,381 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityStatus.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityStatus.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityStatus extends WrappedPacket {
public int entityId;
/**
* 1 Sent when resetting a mob spawn minecart's timer — appears to be unused by the client 2 Living Entity hurt 3
* Living Entity dead 4 Iron Golem throwing up arms 6 Wolf/Ocelot/Horse taming — Spawn “heart” particles 7
* Wolf/Ocelot/Horse tamed — Spawn “smoke” particles 8 Wolf shaking water — Trigger the shaking animation 9 (of
* self) Eating accepted by server 10 Sheep eating grass or play TNT ignite sound 11 Iron Golem handing over a
* rose 12 Villager mating — Spawn “heart” particles 13 Spawn particles indicating that a villager is angry and
* seeking revenge 14 Spawn happy particles near a villager 15 Witch animation — Spawn “magic” particles 16 Play
* zombie converting into a villager sound 17 Firework exploding 18 Animal in love (ready to mate) — Spawn “heart”
* particles 19 Reset squid rotation 20 Spawn explosion particle — works for some living entities 21 Play
* guardian sound — works for every entity 22 Enables reduced debug for players 23 Disables reduced debug for
* players 24–28 Sets op permission level 0–4 for players
*/
public byte status;
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityStatus.newPacket(entityId, status);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityStatus.getPacketData(packet);
entityId = (int) d[0];
status = (byte) d[1];
}
}
| 1,752 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutPosition.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutPosition.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import org.bukkit.Location;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import static gyurix.protocol.wrappers.outpackets.PacketPlayOutPosition.PlayerTeleportFlag.*;
/**
* Created by GyuriX on 2016.08.23..
*/
public class PacketPlayOutPosition extends WrappedPacket {
public static final HashSet<PlayerTeleportFlag> allFlags = new HashSet<>();
public static final HashSet<PlayerTeleportFlag> coordFlags = new HashSet<>();
public static final HashSet<PlayerTeleportFlag> rotationFlags = new HashSet<>();
static {
coordFlags.add(X);
coordFlags.add(Y);
coordFlags.add(Z);
rotationFlags.add(X_ROT);
rotationFlags.add(Y_ROT);
allFlags.addAll(coordFlags);
allFlags.addAll(rotationFlags);
}
public HashSet<PlayerTeleportFlag> flags;
public float pitch;
public int teleportId = 2147483647;
public double x;
public double y;
public float yaw;
public double z;
public PacketPlayOutPosition() {
}
public PacketPlayOutPosition(double x, double y, double z) {
flags = coordFlags;
this.x = x;
this.y = y;
this.z = z;
}
public PacketPlayOutPosition(float yaw, float pitch) {
flags = rotationFlags;
this.yaw = yaw;
this.pitch = pitch;
}
public PacketPlayOutPosition(Location loc) {
setLocation(loc);
}
public PacketPlayOutPosition(Object packet) {
loadVanillaPacket(packet);
}
public HashSet<Object> getVanillaFlags() {
HashSet<Object> out = new HashSet<>();
for (PlayerTeleportFlag f : flags)
out.add(f.toNMS());
return out;
}
private void setVanillaFlags(Set set) {
flags = new HashSet<>();
for (Object o : set)
flags.add(fromVanillaPTF(o));
}
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ? PacketOutType.Position.newPacket(x, y, z, yaw, pitch, getVanillaFlags(), teleportId) :
PacketOutType.Position.newPacket(x, y, z, yaw, pitch, getVanillaFlags());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Position.getPacketData(packet);
x = (double) d[0];
y = (double) d[1];
z = (double) d[2];
yaw = (float) d[3];
pitch = (float) d[4];
setVanillaFlags((Set) d[5]);
if (Reflection.ver.isAbove(ServerVersion.v1_9))
teleportId = (int) d[6];
}
public void setLocation(Location loc) {
flags = allFlags;
x = loc.getX();
y = loc.getY();
z = loc.getZ();
yaw = loc.getYaw();
pitch = loc.getPitch();
}
public enum PlayerTeleportFlag implements WrappedData {
X,
Y,
Z,
Y_ROT,
X_ROT;
private static final Class cl = Reflection.getNMSClass("PacketPlayOutPosition$EnumPlayerTeleportFlags");
private static final Method valueOf = Reflection.getMethod(cl, "valueOf", String.class);
public static PlayerTeleportFlag fromVanillaPTF(Object nms) {
return valueOf(nms.toString());
}
@Override
public Object toNMS() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 3,475 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutOpenSignEditor.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutOpenSignEditor.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutOpenSignEditor extends WrappedPacket {
public BlockLocation loc;
public PacketPlayOutOpenSignEditor() {
}
public PacketPlayOutOpenSignEditor(BlockLocation loc) {
this.loc = loc;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.OpenSignEditor.newPacket(loc.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.OpenSignEditor.getPacketData(packet);
loc = new BlockLocation(d[0]);
}
}
| 740 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutUpdateHealth.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutUpdateHealth.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutUpdateHealth extends WrappedPacket {
public int food;
public float health, saturation;
public PacketPlayOutUpdateHealth() {
}
public PacketPlayOutUpdateHealth(float health, int food, float saturation) {
this.health = health;
this.food = food;
this.saturation = saturation;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.UpdateHealth.newPacket(health, food, saturation);
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] d = PacketOutType.UpdateHealth.getPacketData(obj);
health = (float) d[0];
food = (int) d[1];
saturation = (float) d[2];
}
}
| 848 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutWorldBorder.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutWorldBorder.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import java.lang.reflect.Method;
public class PacketPlayOutWorldBorder
extends WrappedPacket {
public WorldBorderAction action;
public double centerX;
public double centerZ;
public double newRadius;
public double oldRadius;
public int portalTeleportBoundary;
public long time;
public int warningBlocks;
public int warningTime;
@Override
public Object getVanillaPacket() {
return PacketOutType.WorldBorder.newPacket(action.toNMS(), portalTeleportBoundary, centerX, centerZ, newRadius, oldRadius, time, warningTime, warningBlocks);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketOutType.WorldBorder.getPacketData(packet);
action = WorldBorderAction.valueOf(data[0].toString());
portalTeleportBoundary = (Integer) data[1];
centerX = (Double) data[2];
centerZ = (Double) data[3];
newRadius = (Double) data[4];
oldRadius = (Double) data[5];
time = (Long) data[6];
warningTime = (Integer) data[7];
warningBlocks = (Integer) data[8];
}
public enum WorldBorderAction implements WrappedData {
SET_SIZE,
LERP_SIZE,
SET_CENTER,
INITIALIZE,
SET_WARNING_TIME,
SET_WARNING_BLOCKS;
private static final Method valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayOutWorldBorder$EnumWorldBorderAction"), "valueOf", String.class);
public Object toNMS() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,780 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutScoreboardScore.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutScoreboardScore.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Method;
public class PacketPlayOutScoreboardScore extends WrappedPacket {
public ScoreAction action;
public String board;
public String player;
public int score;
public PacketPlayOutScoreboardScore() {
}
public PacketPlayOutScoreboardScore(ScoreAction action, String board, String player, int score) {
this.action = action;
this.board = board;
this.player = player;
this.score = score;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.ScoreboardScore.newPacket(player, board, score, Reflection.ver.isAbove(ServerVersion.v1_8) ? action.toNMS() : action.ordinal());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketOutType.ScoreboardScore.getPacketData(packet);
player = (String) data[0];
board = (String) data[1];
score = (Integer) data[2];
if (Reflection.ver.isAbove(ServerVersion.v1_8))
action = ScoreAction.valueOf(data[3].toString());
else
action = ScoreAction.values()[(Integer) data[3]];
}
public enum ScoreAction implements WrappedData {
CHANGE,
REMOVE;
private static final Method valueOf = Reflection.getMethod(Reflection.getNMSClass(
Reflection.ver.isAbove(ServerVersion.v1_13) ? "ScoreboardServer$Action" :
"PacketPlayOutScoreboardScore$EnumScoreboardAction"), "valueOf", String.class);
ScoreAction() {
}
public Object toNMS() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,881 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityMetadata.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityMetadata.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.DataWatcher;
import gyurix.protocol.utils.DataWatcher.WrappedItem;
import gyurix.protocol.wrappers.WrappedPacket;
import java.util.ArrayList;
import java.util.List;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityMetadata extends WrappedPacket {
public int entityId;
public ArrayList<WrappedItem> meta = new ArrayList<>();
public PacketPlayOutEntityMetadata() {
}
public PacketPlayOutEntityMetadata(int entityId, ArrayList<WrappedItem> meta) {
this.entityId = entityId;
this.meta = meta;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityMetadata.newPacket(entityId, DataWatcher.convertToNmsItems(meta));
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityMetadata.getPacketData(packet);
entityId = (int) d[0];
meta = DataWatcher.wrapNMSItems((List) d[1]);
}
}
| 1,030 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutTitle.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutTitle.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.ChatAPI;
import gyurix.spigotlib.SU;
import java.lang.reflect.Method;
import static gyurix.chat.ChatTag.fromICBC;
import static gyurix.protocol.Reflection.getMethod;
import static gyurix.protocol.Reflection.getNMSClass;
/**
* Created by gyurix on 11/17/2016.
*/
public class PacketPlayOutTitle extends WrappedPacket {
public TitleAction action;
public int fadeIn, showTime, fadeOut;
public ChatTag tag;
public PacketPlayOutTitle() {
}
public PacketPlayOutTitle(TitleAction action, ChatTag tag, int fadeIn, int showTime, int fadeOut) {
this.action = action;
this.tag = tag;
this.fadeIn = fadeIn;
this.showTime = showTime;
this.fadeOut = fadeOut;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.Title.newPacket(action.toNMS(), tag == null ? null : ChatAPI.toICBC(tag.toString()), fadeIn, showTime, fadeOut);
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] d = PacketOutType.Title.getPacketData(obj);
action = TitleAction.valueOf(d[0].toString());
tag = d[1] == null ? null : fromICBC(d[1]);
fadeIn = (int) d[2];
showTime = (int) d[3];
fadeOut = (int) d[4];
}
public enum TitleAction implements WrappedData {
TITLE,
SUBTITLE,
ACTIONBAR,
TIMES,
CLEAR,
RESET;
Method m = getMethod(getNMSClass("PacketPlayOutTitle$EnumTitleAction"), "valueOf", String.class);
public Object toNMS() {
try {
return m.invoke(null, name());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 1,836 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSetSlot.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSetSlot.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutSetSlot extends WrappedPacket {
public ItemStackWrapper item;
public int slot;
public int windowId;
public PacketPlayOutSetSlot() {
}
public PacketPlayOutSetSlot(int windowId, int slot, ItemStackWrapper item) {
this.windowId = windowId;
this.slot = slot;
this.item = item;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.SetSlot.newPacket(windowId, slot, item.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.SetSlot.getPacketData(packet);
windowId = (int) d[0];
slot = (int) d[1];
item = new ItemStackWrapper(d[2]);
}
}
| 907 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketStatusOutPong.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketStatusOutPong.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketStatusOutPong extends WrappedPacket {
public long id;
@Override
public Object getVanillaPacket() {
return PacketOutType.StatusOutPong.newPacket(id);
}
@Override
public void loadVanillaPacket(Object packet) {
id = (long) PacketOutType.StatusOutPong.getPacketData(packet)[0];
}
}
| 504 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutCustomPayload.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutCustomPayload.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import static gyurix.protocol.Reflection.*;
/**
* Created by gyurix on 25/03/2017.
*/
public class PacketPlayOutCustomPayload extends WrappedPacket {
private static final Constructor con = getConstructor(getNMSClass("PacketDataSerializer"), ByteBuf.class);
private static final Field f = getField(getNMSClass("PacketDataSerializer"), "a");
public String channel;
public byte[] data;
public PacketPlayOutCustomPayload() {
}
public PacketPlayOutCustomPayload(String channel, byte[] data) {
this.channel = channel;
this.data = data;
}
@Override
public Object getVanillaPacket() {
try {
if (ver.isAbove(ServerVersion.v1_8))
return PacketOutType.CustomPayload.newPacket(channel, con.newInstance(ByteBufAllocator.DEFAULT.buffer().writeBytes(data)));
else
return PacketOutType.CustomPayload.newPacket(channel, data);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] d = PacketOutType.CustomPayload.getPacketData(obj);
channel = (String) d[0];
try {
if (ver.isAbove(ServerVersion.v1_8)) {
ByteBuf buf = (ByteBuf) f.get(d[1]);
data = new byte[buf.writerIndex()];
buf.readBytes(this.data);
buf.resetReaderIndex();
} else
this.data = (byte[]) d[1];
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
}
| 1,832 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutBlockAction.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutBlockAction.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.BlockUtils;
/**
* Created by GyuriX, on 2017. 02. 05..
*/
public class PacketPlayOutBlockAction extends WrappedPacket {
public int actionId, actionData, blockId;
public BlockLocation loc;
public PacketPlayOutBlockAction() {
}
public PacketPlayOutBlockAction(BlockLocation loc, int actionId, int actionData, int blockId) {
this.loc = loc;
this.actionId = actionId;
this.actionData = actionData;
this.blockId = blockId;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.BlockAction.newPacket(loc.toNMS(), actionId, actionData, BlockUtils.getCombinedId(blockId));
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.BlockAction.getPacketData(packet);
loc = new BlockLocation(d[0]);
actionId = (int) d[1];
actionData = (int) d[2];
blockId = BlockUtils.getCombinedId(d[3]);
}
}
| 1,103 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutOpenWindow.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutOpenWindow.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayOutOpenWindow
extends WrappedPacket {
public int entityId;
public int slots;
public ChatTag title;
public String type;
/**
* In newer versions this type id is used instead of type
*/
public int typeId;
public int windowId;
public PacketPlayOutOpenWindow() {
}
public PacketPlayOutOpenWindow(int windowId, String type, ChatTag title, int slots) {
this.windowId = windowId;
this.type = type;
this.title = title;
this.slots = slots;
}
public PacketPlayOutOpenWindow(int windowId, String type, ChatTag title, int slots, int entityId) {
this.windowId = windowId;
this.type = type;
this.title = title;
this.slots = slots;
this.entityId = entityId;
}
public PacketPlayOutOpenWindow(int windowId, int typeId, ChatTag title) {
this.windowId = windowId;
this.typeId = typeId;
this.title = title;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.OpenWindow.newPacket(windowId, type, title.toICBC(), slots, entityId);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketOutType.OpenWindow.getPacketData(packet);
windowId = (Integer) o[0];
title = ChatTag.fromICBC(o[2]);
if (Reflection.ver.isBellow(ServerVersion.v1_13)) {
type = (String) o[1];
slots = (Integer) o[3];
entityId = (Integer) o[4];
} else
typeId = (int) o[1];
}
}
| 1,686 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutHeldItemSlot.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutHeldItemSlot.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.08.23..
*/
public class PacketPlayOutHeldItemSlot extends WrappedPacket {
public int slot;
public PacketPlayOutHeldItemSlot() {
}
public PacketPlayOutHeldItemSlot(int slot) {
this.slot = slot;
}
public PacketPlayOutHeldItemSlot(Object packet) {
loadVanillaPacket(packet);
}
@Override
public Object getVanillaPacket() {
return PacketOutType.HeldItemSlot.newPacket(slot);
}
@Override
public void loadVanillaPacket(Object packet) {
slot = (int) PacketOutType.HeldItemSlot.getPacketData(packet)[0];
}
}
| 719 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutRemoveEntityEffect.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutRemoveEntityEffect.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutRemoveEntityEffect extends WrappedPacket {
/**
* 1 - Speed 2 - Slowness 3 - Haste 4 - Mining Fatigue 5 - Strength 6 - Instant Health 7 - Instant Damage 8
* - Jump Boost 9 - Nausea 10 - Regeneration 11 - Resistance 12 - Fire Resistance 13 - Water Breathing 14 -
* Invisibility 15 - Blindness 16 - Night Vision 17 - Hunger 18 - Weakness 19 - Poison 20 - Wither 21 - Health Boost
* 22 - Absorption 23 - Saturation 24 - Glowing 25 - Levitation 26 - Luck 27 - Bad Luck
*/
public byte effectId;
public int entityId;
@Override
public Object getVanillaPacket() {
return PacketOutType.RemoveEntityEffect.newPacket(entityId, effectId);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.RemoveEntityEffect.getPacketData(packet);
entityId = (int) d[0];
effectId = (byte) (int) d[1];
}
}
| 1,079 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutChat.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutChat.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.json.JsonAPI;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.ChatAPI;
import gyurix.spigotutils.ServerVersion;
import net.md_5.bungee.api.chat.BaseComponent;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutChat extends WrappedPacket {
private static Object[] nmsValues;
static {
try {
nmsValues = (Object[]) Reflection.getMethod(Reflection.getNMSClass("ChatMessageType"), "values").invoke(null);
} catch (Throwable e) {
}
}
public ChatTag tag;
/**
* The type of this chat message 0: chat (chat box) 1: system message (chat box) 2: action bar
*/
public byte type;
public PacketPlayOutChat() {
}
public PacketPlayOutChat(byte type, ChatTag tag) {
this.type = type;
this.tag = tag;
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_8))
return PacketOutType.Chat.newPacket(ChatAPI.toICBC(tag.toString()), null, Reflection.ver.isAbove(ServerVersion.v1_12) ? nmsValues[type] : type);
return PacketOutType.Chat.newPacket(ChatAPI.toICBC(tag.toString()), null, true, 0);
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.Chat.getPacketData(obj);
if (data[1] != null) {
tag = ChatTag.fromBaseComponents((BaseComponent[]) data[1]);
} else
tag = JsonAPI.deserialize(ChatAPI.toJson(data[0]), ChatTag.class);
if (Reflection.ver.isAbove(ServerVersion.v1_8))
type = (byte) (Reflection.ver.isAbove(ServerVersion.v1_12) ? (byte) (int) ((Enum) data[2]).ordinal() : data[2]);
}
}
| 1,769 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutScoreboardDisplayObjective.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutScoreboardDisplayObjective.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayOutScoreboardDisplayObjective extends WrappedPacket {
/**
* Display slot of the scoreboard objective, possible values:
* 0 - list
* 1 - sidebar
* 2 - below name
*/
public int displaySlot;
public String name;
@Override
public Object getVanillaPacket() {
return PacketOutType.ScoreboardDisplayObjective.newPacket(displaySlot, name);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketOutType.ScoreboardDisplayObjective.getPacketData(packet);
displaySlot = (Integer) o[0];
name = (String) o[1];
}
}
| 736 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutMap.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutMap.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.json.JsonSettings;
import gyurix.map.MapData;
import gyurix.map.MapIcon;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import static gyurix.protocol.Reflection.ver;
import static gyurix.spigotutils.ServerVersion.v1_9;
/**
* Created by GyuriX on 2016. 07. 06..
*/
public class PacketPlayOutMap extends WrappedPacket {
@JsonSettings(serialize = false)
private static final Constructor con;
@JsonSettings(serialize = false)
private static final Class[] newer = new Class[]{int.class, byte.class, boolean.class, Collection.class, byte[].class, int.class, int.class, int.class, int.class},
v1_8 = new Class[]{int.class, byte.class, Collection.class, byte[].class, int.class, int.class, int.class, int.class};
static {
con = Reflection.getConstructor(Reflection.getNMSClass("PacketPlayOutMap"), ver.isAbove(v1_9) ? newer : v1_8);
}
public int columns;
public byte[] data;
public ArrayList<MapIcon> icons = new ArrayList<>();
public int mapId;
public int rows;
/**
* From 0 to 4
* 0 - 1 x 1 blocks per pixel (fully zoomed-in map)
* 1 - 2 x 2 blocks per pixel
* 2 - 4 x 4 blocks per pixel
* 3 - 8 x 8 blocks per pixel
* 4 - 16 x 16 blocks per pixel
*/
public byte scale;
public boolean showIcons;
public int x;
public int z;
public PacketPlayOutMap() {
}
public PacketPlayOutMap(MapData mapData) {
mapId = mapData.getMapId();
scale = mapData.getScale().getValue();
showIcons = mapData.isShowIcons();
icons = mapData.getIcons();
columns = 0;
rows = 0;
x = 128;
z = 128;
data = mapData.cloneColors();
}
public ArrayList<Object> getNMSIcons() {
ArrayList<Object> out = new ArrayList<>();
if (icons == null)
return out;
for (MapIcon ic : icons) {
out.add(ic.toNMS());
}
return out;
}
@Override
public Object getVanillaPacket() {
try {
return ver.isAbove(v1_9) ? con.newInstance(mapId, scale, showIcons, getNMSIcons(), data, columns, rows, x, z)
: con.newInstance(mapId, scale, getNMSIcons(), data, columns, rows, x, z);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Map.getPacketData(packet);
mapId = (int) d[0];
scale = (byte) d[1];
int st = 2;
if (ver.isAbove(v1_9))
showIcons = (boolean) d[st++];
Object[] nmsIcons = (Object[]) d[st++];
icons.clear();
for (Object nmsIcon : nmsIcons) icons.add(new MapIcon(nmsIcon));
columns = (int) d[st++];
rows = (int) d[st++];
x = (int) d[st++];
z = (int) d[st++];
data = (byte[]) d[st++];
}
}
| 2,979 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutExplosion.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutExplosion.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import java.util.ArrayList;
import java.util.List;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutExplosion extends WrappedPacket {
public ArrayList<BlockLocation> blocks = new ArrayList<>();
public float pushX;
public float pushY;
public float pushZ;
public float radius;
public double x;
public double y;
public double z;
public void fromVanillaBlockLocations(List l) {
blocks = new ArrayList<>();
for (Object o : l) {
blocks.add(new BlockLocation(o));
}
}
@Override
public Object getVanillaPacket() {
return PacketOutType.Explosion.newPacket(x, y, z, radius, toVanillaBlockLocations(), pushX, pushY, pushZ);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Explosion.getPacketData(packet);
x = (double) d[0];
y = (double) d[1];
z = (double) d[2];
radius = (float) d[3];
fromVanillaBlockLocations((List) d[4]);
pushX = (float) d[5];
pushY = (float) d[6];
pushZ = (float) d[7];
}
public List toVanillaBlockLocations() {
List out = new ArrayList();
for (BlockLocation bl : blocks)
out.add(bl.toNMS());
return out;
}
}
| 1,378 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutTileEntityData.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutTileEntityData.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.nbt.NBTCompound;
import gyurix.nbt.NBTTagType;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayOutTileEntityData extends WrappedPacket {
public int action;
public BlockLocation block;
public NBTCompound nbt;
public PacketPlayOutTileEntityData() {
}
public PacketPlayOutTileEntityData(BlockLocation block, int action, NBTCompound nbt) {
this.block = block;
this.action = action;
this.nbt = nbt;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.TileEntityData.newPacket(block.toNMS(), action, nbt.toNMS());
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.TileEntityData.getPacketData(obj);
block = new BlockLocation(data[0]);
action = (int) data[1];
nbt = (NBTCompound) NBTTagType.tag(data[2]);
}
}
| 987 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutTabComplete.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutTabComplete.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayOutTabComplete extends WrappedPacket {
public String[] complete;
public PacketPlayOutTabComplete() {
}
public PacketPlayOutTabComplete(Object nms) {
loadVanillaPacket(nms);
}
public PacketPlayOutTabComplete(String[] complete) {
this.complete = complete;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.TabComplete.newPacket(new Object[]{complete});
}
@Override
public void loadVanillaPacket(Object obj) {
complete = (String[]) PacketOutType.TabComplete.getPacketData(obj)[0];
}
}
| 709 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityLook.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityLook.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import java.lang.reflect.Constructor;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityLook extends WrappedPacket {
public int entityId;
public boolean onGround;
public byte pitch;
public byte yaw;
private static final Constructor con = Reflection.getConstructor(Reflection.getNMSClass(
"PacketPlayOutEntity$PacketPlayOutEntityLook"), int.class, byte.class, byte.class, boolean.class);
public PacketPlayOutEntityLook() {
}
public PacketPlayOutEntityLook(int eid, float yaw, float pitch, boolean onGround) {
entityId = eid;
this.yaw = (byte) (yaw * 256.0 / 360.0);
this.pitch = (byte) (pitch * 256.0 / 360.0);
this.onGround = onGround;
}
@Override
public Object getVanillaPacket() {
try {
return con.newInstance(entityId, yaw, pitch, onGround);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityLook.getPacketData(packet);
entityId = (int) d[0];
yaw = (byte) d[1];
pitch = (byte) d[2];
onGround = (boolean) d[3];
}
}
| 1,381 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutNamedSoundEffect.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutNamedSoundEffect.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutNamedSoundEffect extends WrappedPacket {
public float pitch;
public String soundName;
public float volume;
public double x;
public double y;
public double z;
public PacketPlayOutNamedSoundEffect() {
}
public PacketPlayOutNamedSoundEffect(String soundName, double x, double y, double z, float volume, float pitch) {
this.soundName = soundName;
this.x = x;
this.y = y;
this.z = z;
this.volume = volume;
this.pitch = pitch;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.NamedSoundEffect.newPacket(soundName, (int) (x * 8), (int) (y * 8), (int) (z * 8), volume, (int) (pitch * 64));
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.NamedSoundEffect.getPacketData(obj);
soundName = (String) data[0];
x = ((int) data[1]) / 8.0;
y = ((int) data[2]) / 8.0;
z = ((int) data[3]) / 8.0;
volume = (float) data[4];
pitch = ((int) data[5]) / 64.0f;
}
}
| 1,199 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityDestroy.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityDestroy.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityDestroy extends WrappedPacket {
public int[] entityIds;
public PacketPlayOutEntityDestroy() {
}
public PacketPlayOutEntityDestroy(int... eids) {
entityIds = eids;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityDestroy.newPacket(entityIds);
}
@Override
public void loadVanillaPacket(Object packet) {
entityIds = (int[]) PacketOutType.EntityDestroy.getPacketData(packet)[0];
}
}
| 658 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutScoreboardObjective.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutScoreboardObjective.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.scoreboard.ScoreboardDisplayMode;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayOutScoreboardObjective extends WrappedPacket {
/**
* Possible values:
* 0 - create the scoreboard
* 1 - remove the scoreboard
* 2 - update title
*/
public int action;
public ScoreboardDisplayMode displayMode;
public String name, title;
public PacketPlayOutScoreboardObjective() {
}
public PacketPlayOutScoreboardObjective(Object packet) {
loadVanillaPacket(packet);
}
public PacketPlayOutScoreboardObjective(String name, String title, ScoreboardDisplayMode displayMode, int action) {
this.name = name;
this.title = title;
this.displayMode = displayMode;
this.action = action;
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
if (Reflection.ver.isAbove(ServerVersion.v1_13))
return PacketOutType.ScoreboardObjective.newPacket(name, ChatTag.fromColoredText(title).toICBC(),
displayMode == null ? null : displayMode.toNMS(), action);
return PacketOutType.ScoreboardObjective.newPacket(name, title, displayMode == null ? null : displayMode.toNMS(), action);
}
return PacketOutType.ScoreboardObjective.newPacket(name, title, action);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketOutType.ScoreboardObjective.getPacketData(packet);
name = (String) o[0];
if (Reflection.ver.isAbove(ServerVersion.v1_13))
title = ChatTag.fromICBC(o[1]).toColoredString();
else
title = (String) o[1];
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
displayMode = o[2] == null ? null : ScoreboardDisplayMode.valueOf(o[2].toString());
action = (int) o[3];
} else
action = (int) o[2];
}
}
| 2,032 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutAttachEntity.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutAttachEntity.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
/**
* Created by GyuriX, on 2017. 02. 05..
*/
public class PacketPlayOutAttachEntity extends WrappedPacket {
public int entity1, entity2;
public PacketPlayOutAttachEntity() {
}
public PacketPlayOutAttachEntity(int entity1, int entity2) {
this.entity1 = entity1;
this.entity2 = entity2;
}
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ? PacketOutType.AttachEntity.newPacket(entity1, entity2) : PacketOutType.AttachEntity.newPacket(0, entity1, entity2);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.AttachEntity.getPacketData(packet);
entity1 = (int) d[0];
entity2 = (int) d[1];
}
}
| 938 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityEquipment.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityEquipment.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
import lombok.NoArgsConstructor;
/**
* Created by GyuriX on 2016.02.28..
*/
@NoArgsConstructor
public class PacketPlayOutEntityEquipment extends WrappedPacket {
public int entityId;
public ItemStackWrapper item;
/**
* Slot number: 0 - held 1 - boots 2 - leggings 3 - chestplate 4 - helmet
*/
public int slot;
public PacketPlayOutEntityEquipment(int entityId, int slot, ItemStackWrapper item) {
this.entityId = entityId;
this.slot = slot;
this.item = item;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityEquipment.newPacket(entityId, slot, item.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityEquipment.getPacketData(packet);
entityId = (int) d[0];
slot = (int) d[1];
item = new ItemStackWrapper(d[2]);
}
}
| 1,039 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutNamedEntitySpawn.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutNamedEntitySpawn.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.DataWatcher;
import gyurix.protocol.utils.GameProfile;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.LocationData;
import java.util.UUID;
import static gyurix.spigotutils.ServerVersion.*;
/**
* Created by GyuriX on 2016.03.06..
*/
public class PacketPlayOutNamedEntitySpawn extends WrappedPacket {
public int entityId, handItemId;
public UUID entityUUID;
public DataWatcher meta;
public GameProfile profile;
public double x, y, z;
public byte yaw, pitch;
public PacketPlayOutNamedEntitySpawn() {
}
public PacketPlayOutNamedEntitySpawn(int eid, GameProfile profile, LocationData loc, DataWatcher data) {
entityId = eid;
entityUUID = profile.id;
this.profile = profile;
setLocation(loc);
meta = data;
}
public PacketPlayOutNamedEntitySpawn(int eid, UUID eUUID, LocationData loc, DataWatcher data) {
entityId = eid;
entityUUID = eUUID;
setLocation(loc);
meta = data;
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(v1_9))
return PacketOutType.NamedEntitySpawn.newPacket(entityId, entityUUID, x, y, z, yaw, pitch, meta.toNMS());
else if (Reflection.ver.isAbove(v1_8))
return PacketOutType.NamedEntitySpawn.newPacket(entityId, entityUUID,
(int) (x * 32), (int) (y * 32), (int) (z * 32), yaw, pitch, meta.toNMS());
else
return PacketOutType.NamedEntitySpawn.newPacket(entityId, profile.toNMS(),
(int) (x * 32), (int) (y * 32), (int) (z * 32), yaw, pitch, meta.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.NamedEntitySpawn.getPacketData(packet);
entityId = (int) d[0];
if (Reflection.ver.isBellow(v1_7)) {
profile = new GameProfile(d[1]);
entityUUID = profile.id;
} else
entityUUID = (UUID) d[1];
if (Reflection.ver.isAbove(v1_9)) {
x = (double) d[2];
y = (double) d[3];
z = (double) d[4];
} else {
x = (int) d[2] / 32.0;
y = (int) d[3] / 32.0;
z = (int) d[4] / 32.0;
handItemId = (int) d[7];
}
yaw = (byte) d[5];
pitch = (byte) d[6];
meta = new DataWatcher(d[d.length - 2]);
}
public void setLocation(LocationData loc) {
x = loc.x;
y = loc.y;
z = loc.z;
while (loc.yaw <= -180)
loc.yaw += 360;
while (loc.yaw >= 180)
loc.yaw -= 360;
yaw = (byte) (loc.yaw * 256 / 360);
pitch = (byte) (loc.pitch * 256 / 360);
}
}
| 2,652 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutScoreboardTeam.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutScoreboardTeam.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatColor;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.scoreboard.team.CollisionRule;
import gyurix.scoreboard.team.NameTagVisibility;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static gyurix.protocol.event.PacketOutType.ScoreboardTeam;
/**
* Created by GyuriX on 11/15/2016.
*/
public class PacketPlayOutScoreboardTeam extends WrappedPacket {
private static final Class enumChatFormatCl = Reflection.getNMSClass("EnumChatFormat");
private static final Field enumChatFormatF = Reflection.getFirstFieldOfType(enumChatFormatCl, char.class);
private static final Method enumChatFormatM = Reflection.getMethod(enumChatFormatCl, "valueOf", String.class);
/**
* 0: create team
* 1: remove team
* 2: update team info
* 3: add players to team
* 4: remove players from team
*/
public int action;
public CollisionRule collisionRule;
public int color;
public String displayName = "";
/**
* 0x01: Allow friendly fire
* 0x02: Can see invisible players on same team
*/
public int friendFlags;
public String name = "";
public NameTagVisibility nameTagVisibility;
public List<String> players;
public String prefix = "";
public String suffix = "";
public PacketPlayOutScoreboardTeam(String name, String displayName,
String prefix, String suffix,
NameTagVisibility nameTagVisibility, CollisionRule collisionRule,
int color, List<String> players,
int action, int friendFlags) {
this.name = name;
this.displayName = displayName;
this.prefix = prefix;
this.suffix = suffix;
this.nameTagVisibility = nameTagVisibility;
this.collisionRule = collisionRule;
this.color = color;
this.players = players;
this.action = action;
this.friendFlags = friendFlags;
}
public PacketPlayOutScoreboardTeam() {
}
public PacketPlayOutScoreboardTeam(String name, int action) {
this.name = name;
this.action = action;
}
public PacketPlayOutScoreboardTeam(String name, int action, ArrayList<String> players) {
this.name = name;
this.action = action;
this.players = players;
}
public Object getEnumChatFormat(char c) {
try {
return enumChatFormatM.invoke(null, ChatColor.forId(c).name().toUpperCase());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_13))
return ScoreboardTeam.newPacket(name,
ChatTag.fromColoredText(displayName).toICBC(),
ChatTag.fromColoredText(prefix).toICBC(),
ChatTag.fromColoredText(suffix).toICBC(),
nameTagVisibility == null ? null : nameTagVisibility.name(),
collisionRule == null ? null : collisionRule.name(),
getEnumChatFormat((char) color),
players == null ? new ArrayList<>() : new ArrayList<>(players),
action,
friendFlags);
if (Reflection.ver.isAbove(ServerVersion.v1_9))
return ScoreboardTeam.newPacket(name, displayName, prefix, suffix, nameTagVisibility == null ? null : nameTagVisibility.name(), collisionRule == null ? null : collisionRule.name(), color, players == null ? new ArrayList<>() : new ArrayList<>(players), action, friendFlags);
else if (Reflection.ver.isAbove(ServerVersion.v1_8))
return ScoreboardTeam.newPacket(name, displayName, prefix, suffix, nameTagVisibility == null ? null : nameTagVisibility.name(), color, players == null ? new ArrayList<>() : new ArrayList<>(players), action, friendFlags);
else
return ScoreboardTeam.newPacket(name, displayName, prefix, suffix, players == null ? new ArrayList<>() : new ArrayList<>(players), action, friendFlags);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = ScoreboardTeam.getPacketData(packet);
name = (String) d[0];
if (Reflection.ver.isAbove(ServerVersion.v1_13)) {
displayName = ChatTag.fromICBC(d[1]).toColoredString();
prefix = ChatTag.fromICBC(d[2]).toColoredString();
suffix = ChatTag.fromICBC(d[3]).toColoredString();
} else {
displayName = (String) d[1];
prefix = (String) d[2];
suffix = (String) d[3];
}
int from = 3;
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
String name = (String) d[++from];
nameTagVisibility = name == null ? null : NameTagVisibility.valueOf(name);
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
name = (String) d[++from];
collisionRule = name == null ? null : CollisionRule.valueOf(name);
}
if (Reflection.ver.isAbove(ServerVersion.v1_13))
try {
color = (int) (char) enumChatFormatF.get(d[++from]);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
else
color = (int) d[++from];
}
players = new ArrayList<>((Collection<String>) d[++from]);
action = (int) d[++from];
friendFlags = (int) d[++from];
}
}
| 5,481 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutWorldEvent.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutWorldEvent.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutWorldEvent extends WrappedPacket {
public int data;
public boolean disableRelVolume;
public int effectId;
public BlockLocation loc;
public PacketPlayOutWorldEvent() {
}
public PacketPlayOutWorldEvent(int effectId, BlockLocation loc, int data, boolean disableRelVolume) {
this.effectId = effectId;
this.loc = loc;
this.data = data;
this.disableRelVolume = disableRelVolume;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.WorldEvent.newPacket(effectId, loc.toNMS(), data, disableRelVolume);
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] d = PacketOutType.WorldEvent.getPacketData(obj);
effectId = (int) d[0];
loc = new BlockLocation(d[1]);
data = (int) d[2];
disableRelVolume = (boolean) d[3];
}
}
| 1,062 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnEntityWeather.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnEntityWeather.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutSpawnEntityWeather extends WrappedPacket {
public int entityId;
/**
* 1 - thunderbolt
*/
public int type;
public double x;
public double y;
public double z;
@Override
public Object getVanillaPacket() {
return PacketOutType.SpawnEntityWeather.newPacket(entityId, x, y, z, type);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.SpawnEntityWeather.getPacketData(packet);
entityId = (int) d[0];
x = (double) d[1];
y = (double) d[2];
z = (double) d[3];
type = (int) d[4];
}
}
| 778 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutExperience.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutExperience.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutExperience extends WrappedPacket {
public float bar;
public int level;
public int totalExperience;
@Override
public Object getVanillaPacket() {
return PacketOutType.Experience.newPacket(bar, level, totalExperience);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Experience.getPacketData(packet);
bar = (float) d[0];
level = (int) d[1];
totalExperience = (int) d[2];
}
}
| 659 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnEntityExperienceOrb.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnEntityExperienceOrb.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutSpawnEntityExperienceOrb extends WrappedPacket {
public int count;
public int entityId;
public double x;
public double y;
public double z;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ?
PacketOutType.SpawnEntityExperienceOrb.newPacket(entityId, x, y, z, count) :
PacketOutType.SpawnEntityExperienceOrb.newPacket(entityId, (int) (x * 32), (int) (y * 32), (int) (z * 32), count);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.SpawnEntityExperienceOrb.getPacketData(packet);
entityId = (int) d[0];
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
x = (double) d[1];
y = (double) d[2];
z = (double) d[3];
} else {
x = ((int) d[1]) / 32.0;
y = ((int) d[2]) / 32.0;
z = ((int) d[3]) / 32.0;
}
count = (int) d[4];
}
}
| 1,200 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutRelEntityMoveLook.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutRelEntityMoveLook.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutRelEntityMoveLook extends WrappedPacket {
public byte deltaX, deltaY, deltaZ, yaw, pitch;
public int entityId;
public boolean onGround;
@Override
public Object getVanillaPacket() {
return PacketOutType.RelEntityMoveLook.newPacket(entityId, deltaX, deltaY, deltaZ, yaw, pitch, onGround);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.RelEntityMoveLook.getPacketData(packet);
entityId = (int) d[0];
deltaX = (byte) d[1];
deltaY = (byte) d[2];
deltaZ = (byte) d[3];
yaw = (byte) d[4];
pitch = (byte) d[5];
onGround = (boolean) d[6];
}
}
| 839 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutKeepAlive.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutKeepAlive.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutKeepAlive extends WrappedPacket {
public int id;
public PacketPlayOutKeepAlive() {
}
public PacketPlayOutKeepAlive(int id) {
this.id = id;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.KeepAlive.newPacket(id);
}
@Override
public void loadVanillaPacket(Object packet) {
id = (int) PacketOutType.KeepAlive.getPacketData(packet)[0];
}
}
| 604 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityEffect.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityEffect.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityEffect extends WrappedPacket {
public byte amplifier;
public int duration;
/**
* 1 - Speed 2 - Slowness 3 - Haste 4 - Mining Fatigue 5 - Strength 6 - Instant Health 7 - Instant Damage 8
* - Jump Boost 9 - Nausea 10 - Regeneration 11 - Resistance 12 - Fire Resistance 13 - Water Breathing 14 -
* Invisibility 15 - Blindness 16 - Night Vision 17 - Hunger 18 - Weakness 19 - Poison 20 - Wither 21 - Health Boost
* 22 - Absorption 23 - Saturation 24 - Glowing 25 - Levitation 26 - Luck 27 - Bad Luck
*/
public byte effectId;
public int entityId;
/**
* 0 - No particles, not ambient 1 - Ambient 2 - Particles 3 - Particles and ambient
*/
public byte particles;
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityEffect.newPacket(entityId, effectId, amplifier, duration, particles);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityEffect.getPacketData(packet);
entityId = (int) d[0];
effectId = (byte) d[1];
amplifier = (byte) d[2];
duration = (int) d[3];
particles = (byte) d[4];
}
}
| 1,344 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutUpdateAttributes.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutUpdateAttributes.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutUpdateAttributes extends WrappedPacket {
public ArrayList<Attribute> attributes;
public int entityId;
public PacketPlayOutUpdateAttributes() {
}
public ArrayList<Object> getNMSAttributes() {
ArrayList<Object> out = new ArrayList<>();
for (Attribute a : attributes)
out.add(a.toNMS());
return out;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.UpdateAttributes.newPacket(entityId, getNMSAttributes());
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] d = PacketOutType.UpdateAttributes.getPacketData(obj);
entityId = (int) d[0];
loadNMSAttributes((Iterable<Object>) d[1]);
}
public void loadNMSAttributes(Iterable<Object> nms) {
attributes = new ArrayList<>();
for (Object o : nms)
attributes.add(new Attribute(o));
}
public static class Attribute implements WrappedData {
private static final Class nmsClass = Reflection.getNMSClass("PacketPlayOutUpdateAttributes$AttributeSnapshot");
private static final Field nameField = Reflection.getFirstFieldOfType(nmsClass, String.class);
private static final Field modifierField = Reflection.getFirstFieldOfType(nmsClass, Collection.class);
private static final Field valueField = Reflection.getFirstFieldOfType(nmsClass, double.class);
public ArrayList<AttributeModifier> modifiers = new ArrayList<>();
public String name;
public double value;
public Attribute(String name, double value, ArrayList<AttributeModifier> modifiers) {
this.name = name;
this.value = value;
this.modifiers.addAll(modifiers);
}
public Attribute(Object nms) {
try {
name = (String) nameField.get(nms);
value = (double) valueField.get(nms);
Collection<Object> nmsModifiers = (Collection<Object>) modifierField.get(nms);
for (Object o : nmsModifiers)
modifiers.add(new AttributeModifier(o));
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
@Override
public Object toNMS() {
try {
Object nms = Reflection.newInstance(nmsClass);
nameField.set(nms, name);
valueField.set(nms, value);
ArrayList<Object> nmsModifiers = new ArrayList<>();
for (AttributeModifier m : modifiers)
nmsModifiers.add(m.toNMS());
modifierField.set(nms, nmsModifiers);
return nms;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
}
public static class AttributeModifier implements WrappedData {
private static final Class nmsClass = Reflection.getNMSClass("AttributeModifier");
private static final Field nameField = Reflection.getFirstFieldOfType(nmsClass, String.class);
private static final Field amountField = Reflection.getFirstFieldOfType(nmsClass, double.class);
private static final Field idField = Reflection.getFirstFieldOfType(nmsClass, UUID.class);
private static final Field operationField = Reflection.getFirstFieldOfType(nmsClass, int.class);
public double amount;
public UUID id;
public String name;
public int operation;
public AttributeModifier(Object nms) {
try {
amount = amountField.getDouble(nms);
id = (UUID) idField.get(nms);
name = (String) nameField.get(nms);
operation = operationField.getInt(nms);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
@Override
public Object toNMS() {
try {
Object nms = Reflection.newInstance(nmsClass);
amountField.set(nms, amount);
idField.set(nms, id);
nameField.set(nms, name);
operationField.set(nms, operation);
return nms;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
}
}
| 4,339 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnEntityPainting.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnEntityPainting.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.utils.Direction;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import java.util.UUID;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutSpawnEntityPainting extends WrappedPacket {
public int entityId;
public UUID entityUUID;
public Direction facing;
public BlockLocation location;
public String title;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ?
PacketOutType.SpawnEntityPainting.newPacket(entityId, entityUUID, location.toNMS(), facing.toNMS(), title) :
PacketOutType.SpawnEntityPainting.newPacket(entityId, location.toNMS(), facing.toNMS(), title);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.SpawnEntityPainting.getPacketData(packet);
entityId = (int) d[0];
int id = 1;
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
entityUUID = (UUID) d[1];
id = 2;
}
location = new BlockLocation(d[id]);
facing = Direction.valueOf(d[id + 1].toString().toUpperCase());
title = (String) d[id + 2];
}
}
| 1,340 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityHeadRotation.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityHeadRotation.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityHeadRotation extends WrappedPacket {
public int entityId;
public byte rotation;
public PacketPlayOutEntityHeadRotation() {
}
public PacketPlayOutEntityHeadRotation(int entityId, float rotation) {
this.entityId = entityId;
this.rotation = (byte) (rotation * 256.0 / 360.0);
}
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityHeadRotation.newPacket(entityId, rotation);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityHeadRotation.getPacketData(packet);
entityId = (int) d[0];
rotation = (byte) d[1];
}
}
| 838 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutPlayerInfo.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutPlayerInfo.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.GameProfile;
import gyurix.protocol.utils.WorldType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.ChatAPI;
import gyurix.spigotlib.SU;
import org.bukkit.GameMode;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class PacketPlayOutPlayerInfo extends WrappedPacket {
public PlayerInfoAction action = PlayerInfoAction.ADD_PLAYER;
public ArrayList<PlayerInfoData> players = new ArrayList<>();
public PacketPlayOutPlayerInfo() {
}
public PacketPlayOutPlayerInfo(PlayerInfoAction action, PlayerInfoData... pls) {
this.action = action;
for (PlayerInfoData pid : pls)
players.add(pid);
}
@Override
public Object getVanillaPacket() {
return PacketOutType.PlayerInfo.newPacket(action.toNMS(), toVanillaDataList());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.PlayerInfo.getPacketData(packet);
action = PlayerInfoAction.valueOf(d[0].toString());
loadVanillaDataList((List) d[1]);
}
private void loadVanillaDataList(List l) {
players = new ArrayList<>();
for (Object o : l) {
players.add(new PlayerInfoData(o));
}
}
private List toVanillaDataList() {
List l = new ArrayList();
for (PlayerInfoData p : players) {
l.add(p.toNMS());
}
return l;
}
public enum PlayerInfoAction implements WrappedData {
ADD_PLAYER,
UPDATE_GAME_MODE,
UPDATE_LATENCY,
UPDATE_DISPLAY_NAME,
REMOVE_PLAYER;
private static final Method valueOf = Reflection.getMethod(
Reflection.getNMSClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction"), "valueOf", String.class);
public Object toNMS() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
return null;
}
}
}
public static class PlayerInfoData implements WrappedData {
private static final Class vanillaParent = Reflection.getNMSClass("PacketPlayOutPlayerInfo");
private static final Class vanillaCl = Reflection.getInnerClass(vanillaParent, "PlayerInfoData");
private static final Field pingF = Reflection.getFirstFieldOfType(vanillaCl, int.class),
gpF = Reflection.getFirstFieldOfType(vanillaCl, com.mojang.authlib.GameProfile.class),
gmF = Reflection.getFirstFieldOfType(vanillaCl, WorldType.enumGmCl),
icbcF = Reflection.getFirstFieldOfType(vanillaCl, ChatAPI.icbcClass);
private static final Constructor vanillaConst = Reflection.getConstructor(vanillaCl,
vanillaParent, com.mojang.authlib.GameProfile.class, int.class, WorldType.enumGmCl, ChatAPI.icbcClass);
public ChatTag displayName;
public GameMode gameMode;
public GameProfile gameProfile;
public int ping;
public PlayerInfoData() {
}
public PlayerInfoData(int ping, GameMode gm, GameProfile gp, ChatTag dn) {
this.ping = ping;
gameMode = gm;
gameProfile = gp;
displayName = dn;
}
public PlayerInfoData(Object vd) {
try {
ping = pingF.getInt(vd);
Object nmsGm = gmF.get(vd);
gameMode = nmsGm == null ? null : GameMode.valueOf(nmsGm.toString());
gameProfile = new GameProfile(gpF.get(vd));
displayName = ChatTag.fromICBC(icbcF.get(vd));
} catch (Throwable e) {
e.printStackTrace();
}
}
public Object toNMS() {
try {
return vanillaConst.newInstance(null, gameProfile.toNMS(), ping,
WorldType.toVanillaGameMode(gameMode), displayName == null ? null : displayName.toICBC());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 4,015 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutSpawnEntity.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutSpawnEntity.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.Vector;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.LocationData;
import gyurix.spigotutils.ServerVersion;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.IRegistry;
import java.util.UUID;
public class PacketPlayOutSpawnEntity extends WrappedPacket {
public int entityId;
public int entityTypeId;
public UUID entityUUID;
public int objectData;
public float pitch;
public float speedX;
public float speedY;
public float speedZ;
public double x;
public double y;
public float yaw;
public double z;
public PacketPlayOutSpawnEntity() {
}
public PacketPlayOutSpawnEntity(int id, int type, UUID uid, LocationData loc, Vector vec) {
entityId = id;
entityTypeId = type;
entityUUID = uid;
setLocation(loc);
if (vec != null)
setVelocity(vec);
}
public int convertSpeed(float num) {
return (int) (((double) num < -3.9 ? -3.9 : Math.min(num, 3.9)) * 8000.0);
}
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_10) ? PacketOutType.SpawnEntity.newPacket(entityId, entityUUID, x, y, z,
convertSpeed(speedX), convertSpeed(speedY), convertSpeed(speedZ),
(int) ((double) (pitch * 256.0f) / 360.0), (int) ((double) (yaw * 256.0f) / 360.0), entityTypeId, objectData) :
PacketOutType.SpawnEntity.newPacket(entityId, (int) (x * 32), (int) (y * 32), (int) (z * 32),
convertSpeed(speedX), convertSpeed(speedY), convertSpeed(speedZ),
(int) ((double) (pitch * 256.0f) / 360.0), (int) ((double) (yaw * 256.0f) / 360.0),
Reflection.ver.isAbove(ServerVersion.v1_14) ? IRegistry.ENTITY_TYPE.fromId(entityTypeId) : entityTypeId, objectData);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketOutType.SpawnEntity.getPacketData(packet);
entityId = (int) o[0];
int st = 5;
if (Reflection.ver.isAbove(ServerVersion.v1_10)) {
entityUUID = (UUID) o[1];
x = (double) o[2];
y = (double) o[3];
z = (double) o[4];
} else {
x = (double) (int) o[1] / 32.0;
y = (double) (int) o[2] / 32.0;
z = (double) (int) o[3] / 32.0;
st = 4;
}
speedX = (float) (int) o[st] / 8000.0f;
speedY = (float) (int) o[st + 1] / 8000.0f;
speedZ = (float) (int) o[st + 2] / 8000.0f;
pitch = (float) (int) o[st + 3] / 256.0f * 360.0f;
yaw = (float) (int) o[st + 4] / 256.0f * 360.0f;
if (Reflection.ver.isAbove(ServerVersion.v1_14))
entityTypeId = IRegistry.ENTITY_TYPE.a((EntityTypes<?>) o[st + 5]);
else
entityTypeId = (int) o[st + 5];
objectData = (int) o[st + 6];
}
public void setLocation(LocationData loc) {
x = loc.x;
y = loc.y;
z = loc.z;
yaw = loc.yaw;
pitch = loc.pitch;
}
public void setVelocity(Vector vec) {
speedX = (float) vec.x;
speedY = (float) vec.y;
speedZ = (float) vec.z;
}
}
| 3,167 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutRelEntityMove.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutRelEntityMove.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutRelEntityMove extends WrappedPacket {
public byte deltaX, deltaY, deltaZ;
public int entityId;
public boolean onGround;
@Override
public Object getVanillaPacket() {
return PacketOutType.RelEntityMove.newPacket(entityId, deltaX, deltaY, deltaZ, onGround);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.RelEntityMove.getPacketData(packet);
entityId = (int) d[0];
deltaX = (byte) d[1];
deltaY = (byte) d[2];
deltaZ = (byte) d[3];
onGround = (boolean) d[4];
}
}
| 755 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutBlockBreakAnimation.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutBlockBreakAnimation.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutBlockBreakAnimation extends WrappedPacket {
public BlockLocation block;
/**
* 0-9, other value = remove effect
*/
public int destroyStage;
public int entityId;
public PacketPlayOutBlockBreakAnimation() {
}
public PacketPlayOutBlockBreakAnimation(int entityId, BlockLocation block, int destroyStage) {
this.entityId = entityId;
this.block = block;
this.destroyStage = destroyStage;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.BlockBreakAnimation.newPacket(entityId, block.toNMS(), destroyStage);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.BlockBreakAnimation.getPacketData(packet);
entityId = (int) d[0];
block = new BlockLocation(d[1]);
destroyStage = (int) d[2];
}
}
| 1,059 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutMapChunkBulk.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutMapChunkBulk.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.EntityUtils;
import org.bukkit.World;
import java.lang.reflect.Array;
/**
* Created by GyuriX, on 2017. 03. 29..
*/
public class PacketPlayOutMapChunkBulk extends WrappedPacket {
public PacketPlayOutMapChunk.ChunkMap[] chunkMaps;
public int[] chunkX;
public int[] chunkZ;
public boolean hasSkyLight;
public World world;
public Object[] getNMSChunkMapArray() {
Object[] out = (Object[]) Array.newInstance(PacketPlayOutMapChunk.ChunkMap.nmsChunkMap, chunkMaps.length);
for (int i = 0; i < chunkMaps.length; ++i)
out[i] = chunkMaps[i].toNMS();
return out;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.MapChunkBulk.newPacket(chunkX, chunkZ, getNMSChunkMapArray(), hasSkyLight, world == null ? null : EntityUtils.getNMSWorld(world));
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.MapChunkBulk.getPacketData(packet);
chunkX = (int[]) d[0];
chunkZ = (int[]) d[1];
chunkMaps = loadNMSChunkMapArray((Object[]) d[2]);
hasSkyLight = (boolean) d[3];
world = d[4] == null ? null : EntityUtils.getBukkitWorld(d[4]);
}
public PacketPlayOutMapChunk.ChunkMap[] loadNMSChunkMapArray(Object[] ar) {
PacketPlayOutMapChunk.ChunkMap[] out = new PacketPlayOutMapChunk.ChunkMap[ar.length];
for (int i = 0; i < ar.length; ++i)
out[i] = new PacketPlayOutMapChunk.ChunkMap(ar[i]);
return out;
}
}
| 1,598 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutUpdateTime.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutUpdateTime.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.02.28..
*/
public class PacketPlayOutUpdateTime extends WrappedPacket {
public long timeOfDay;
public long worldAge;
@Override
public Object getVanillaPacket() {
return PacketOutType.UpdateTime.newPacket(worldAge, timeOfDay);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.UpdateTime.getPacketData(packet);
worldAge = (long) d[0];
timeOfDay = (long) d[1];
}
}
| 605 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutBed.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutBed.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutBed extends WrappedPacket {
public BlockLocation bed;
public int entityId;
public PacketPlayOutBed() {
}
public PacketPlayOutBed(int entityId, BlockLocation bed) {
this.entityId = entityId;
this.bed = bed;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.Bed.newPacket(entityId, bed.toNMS());
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.Bed.getPacketData(obj);
entityId = (int) data[0];
bed = new BlockLocation(data[1]);
}
}
| 790 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutWindowData.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutWindowData.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayOutWindowData
extends WrappedPacket {
public int property;
public int value;
public int windowId;
public PacketPlayOutWindowData() {
}
public PacketPlayOutWindowData(int windowId, int property, int value) {
this.windowId = windowId;
this.property = property;
this.value = value;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.WindowData.newPacket(windowId, property, value);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketOutType.WindowData.getPacketData(packet);
windowId = (Integer) o[0];
property = (Integer) o[1];
value = (Integer) o[2];
}
}
| 830 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutMultiBlockChange.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutMultiBlockChange.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.BlockData;
import gyurix.spigotutils.BlockUtils;
import gyurix.spigotutils.XZ;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
/**
* Created by GyuriX, on 2017. 02. 05..
*/
public class PacketPlayOutMultiBlockChange extends WrappedPacket {
public MultiBlockChangeInfo[] infos;
public XZ xz;
public PacketPlayOutMultiBlockChange() {
}
public PacketPlayOutMultiBlockChange(XZ xz, MultiBlockChangeInfo... infos) {
this.xz = xz;
this.infos = infos;
}
public Object[] getNMSInfos() {
Object[] d = new Object[infos.length];
for (int i = 0; i < d.length; ++i)
d[i] = infos[i].toNMS();
return d;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.MultiBlockChange.newPacket(xz.toNMS(), getNMSInfos());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.MultiBlockChange.getPacketData(packet);
xz = new XZ(d[0]);
infos = loadNMSInfos((Object[]) d[1]);
}
public MultiBlockChangeInfo[] loadNMSInfos(Object[] infos) {
MultiBlockChangeInfo[] d = new MultiBlockChangeInfo[infos.length];
for (int i = 0; i < d.length; ++i)
d[i] = d[i] = new MultiBlockChangeInfo(infos[i]);
return d;
}
public static class MultiBlockChangeInfo implements WrappedData {
private static Class nmsClass = Reflection.getNMSClass("PacketPlayOutMultiBlockChange$MultiBlockChangeInfo");
private static Constructor nmsConst = Reflection.getConstructor(nmsClass, short.class, Reflection.getNMSClass("IBlockData"));
private static Field posF = Reflection.getFirstFieldOfType(nmsClass, short.class), blockDataF = Reflection.getFirstFieldOfType(nmsClass, Reflection.getNMSClass("IBlockData"));
public BlockData bd;
public short pos;
public MultiBlockChangeInfo() {
}
public MultiBlockChangeInfo(Object nms) {
try {
pos = posF.getShort(nms);
Object nmsBl = blockDataF.get(nms);
bd = BlockUtils.combinedIdToBlockData(BlockUtils.getCombinedId(nmsBl));
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public byte getRelX() {
return (byte) (pos >> 12 & 15);
}
public byte getRelZ() {
return (byte) (pos >> 8 & 15);
}
public int getY() {
return pos & 255;
}
@Override
public Object toNMS() {
try {
return nmsConst.newInstance(pos, BlockUtils.combinedIdToNMSBlockData(BlockUtils.getCombinedId(bd)));
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 2,894 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutWorldParticles.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutWorldParticles.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Method;
public class PacketPlayOutWorldParticles extends WrappedPacket {
private static final Method enumParticleValueOf = Reflection.getMethod(Reflection.getNMSClass("EnumParticle"), "valueOf", String.class);
public int count;
public int[] extraData;
public boolean longDistance;
public String particle;
public Object particleSettings1_14;
public float x, y, z, offsetX, offsetY, offsetZ, data;
public PacketPlayOutWorldParticles() {
}
public PacketPlayOutWorldParticles(String particle, float x, float y, float z, float offsetX, float offsetY, float offsetZ, int count, float data) {
this.particle = particle;
this.count = count;
this.x = x;
this.y = y;
this.z = z;
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.data = data;
}
public PacketPlayOutWorldParticles(String particle, float x, float y, float z, float offsetX, float offsetY, float offsetZ, int count, float data, int[] extraData, boolean longDistance) {
this.particle = particle;
this.count = count;
this.extraData = extraData;
this.longDistance = longDistance;
this.x = x;
this.y = y;
this.z = z;
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.data = data;
}
public PacketPlayOutWorldParticles(float x, float y, float z, float offsetX, float offsetY, float offsetZ, int count, float data, boolean longDistance, Object particleSettings1_14) {
this.count = count;
this.x = x;
this.y = y;
this.z = z;
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.data = data;
this.longDistance = longDistance;
this.particleSettings1_14 = particleSettings1_14;
}
@Override
public Object getVanillaPacket() {
try {
if (Reflection.ver.isAbove(ServerVersion.v1_14))
return PacketOutType.WorldParticles.newPacket(x, y, z, offsetX, offsetY, offsetZ, data, count, longDistance, particleSettings1_14);
return PacketOutType.WorldParticles.newPacket(enumParticleValueOf.invoke(null, particle), x, y, z, offsetX, offsetY, offsetZ, data, count, longDistance, extraData);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.WorldParticles.getPacketData(packet);
int from = 0;
if (Reflection.ver.isBellow(ServerVersion.v1_13))
particle = d[from++].toString();
x = (float) d[from++];
y = (float) d[from++];
z = (float) d[from++];
offsetX = (float) d[from++];
offsetY = (float) d[from++];
offsetZ = (float) d[from++];
data = (float) d[from++];
count = (int) d[from++];
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
longDistance = (boolean) d[from++];
if (Reflection.ver.isBellow(ServerVersion.v1_13))
extraData = (int[]) d[from++];
else {
particleSettings1_14 = d[from++];
}
}
}
}
| 3,302 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutRespawn.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutRespawn.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WorldType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.EntityUtils;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.World;
import static gyurix.protocol.utils.WorldType.*;
/**
* Created by GyuriX on 2016.08.22..
*/
public class PacketPlayOutRespawn extends WrappedPacket implements Cloneable {
public Difficulty difficulty;
public int dimension;
public GameMode gameMode;
public WorldType worldType;
public PacketPlayOutRespawn(int dimension, Difficulty difficulty, GameMode gameMode, WorldType worldType) {
this.dimension = dimension;
this.difficulty = difficulty;
this.gameMode = gameMode;
this.worldType = worldType;
}
public PacketPlayOutRespawn(World w) {
dimension = w.getEnvironment().getId();
difficulty = w.getDifficulty();
Object wd = EntityUtils.getWorldData(w);
gameMode = GameMode.ADVENTURE;
worldType = EntityUtils.getWorldType(wd);
}
public PacketPlayOutRespawn(int dimension, World w) {
this.dimension = dimension;
difficulty = w.getDifficulty();
Object wd = EntityUtils.getWorldData(w);
gameMode = GameMode.ADVENTURE;
worldType = EntityUtils.getWorldType(wd);
}
public PacketPlayOutRespawn() {
}
public PacketPlayOutRespawn(Object packet) {
loadVanillaPacket(packet);
}
@Override
public PacketPlayOutRespawn clone() {
return new PacketPlayOutRespawn(dimension, difficulty, gameMode, worldType);
}
@Override
public Object getVanillaPacket() {
return PacketOutType.Respawn.newPacket(dimension, toVanillaDifficulty(difficulty), toVanillaGameMode(gameMode), worldType.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.Respawn.getPacketData(packet);
dimension = (int) d[0];
difficulty = Difficulty.valueOf(d[1].toString());
gameMode = GameMode.valueOf(d[2].toString());
worldType = fromVanillaWorldType(d[3]);
}
}
| 2,094 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityVelocity.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityVelocity.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import org.bukkit.util.Vector;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityVelocity extends WrappedPacket {
public int entityId;
public int velX;
public int velY;
public int velZ;
public PacketPlayOutEntityVelocity() {
}
public PacketPlayOutEntityVelocity(int entityId, Vector velocity) {
this.entityId = entityId;
velX = (int) (velocity.getX() * 8000.0);
velY = (int) (velocity.getX() * 8000.0);
velZ = (int) (velocity.getX() * 8000.0);
}
@Override
public Object getVanillaPacket() {
return PacketOutType.EntityVelocity.newPacket(entityId, velX, velY, velZ);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityVelocity.getPacketData(packet);
entityId = (int) d[0];
velX = (int) d[1];
velY = (int) d[2];
velZ = (int) d[3];
}
public Vector getVelocity() {
return new Vector(velX / 8000.0, velY / 8000.0, velZ / 8000.0);
}
}
| 1,117 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntity.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntity.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntity extends WrappedPacket {
public int entityId;
@Override
public Object getVanillaPacket() {
return PacketOutType.Entity.newPacket(entityId);
}
@Override
public void loadVanillaPacket(Object packet) {
entityId = (int) PacketOutType.Entity.getPacketData(packet)[0];
}
}
| 506 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketStatusOutServerInfo.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketStatusOutServerInfo.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.GameProfile;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.ArrayList;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketStatusOutServerInfo extends WrappedPacket {
public ServerInfo info;
public PacketStatusOutServerInfo() {
}
public PacketStatusOutServerInfo(ServerInfo info) {
this.info = info;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.StatusOutServerInfo.newPacket(info.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
info = new ServerInfo(PacketOutType.StatusOutServerInfo.getPacketData(packet)[0]);
}
public static class PlayerList implements WrappedData {
private static Class nmsClass = Reflection.getNMSClass("ServerPing$ServerPingPlayerSample");
private static Field[] fields = nmsClass.getDeclaredFields();
static {
try {
for (int i = 0; i < 3; ++i)
fields[i].setAccessible(true);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public int max, online;
public ArrayList<GameProfile> sample = new ArrayList<>();
public PlayerList() {
}
public PlayerList(Object nms) {
try {
max = fields[0].getInt(nms);
online = fields[1].getInt(nms);
for (Object o : (Object[]) fields[2].get(nms)) {
sample.add(new GameProfile(o));
}
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public PlayerList clone() {
PlayerList out = new PlayerList();
out.max = max;
out.online = online;
for (GameProfile gp : sample) {
out.sample.add(gp.clone());
}
return out;
}
@Override
public Object toNMS() {
try {
Object nms = Reflection.newInstance(nmsClass);
fields[0].set(nms, max);
fields[1].set(nms, online);
Object[] nmsGPs = (Object[]) Array.newInstance(GameProfile.cl, sample.size());
for (int i = 0; i < sample.size(); ++i)
nmsGPs[i] = sample.get(i).toNMS();
fields[2].set(nms, nmsGPs);
return nms;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
public static class ServerData implements WrappedData {
private static Class nmsClass = Reflection.getNMSClass("ServerPing$ServerData");
private static Field nameField = Reflection.getFirstFieldOfType(nmsClass, String.class);
private static Field protocolField = Reflection.getFirstFieldOfType(nmsClass, int.class);
public String name;
public int protocol;
public ServerData() {
}
public ServerData(Object nms) {
try {
name = (String) nameField.get(nms);
protocol = protocolField.getInt(nms);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public ServerData(String name, int protocol) {
this.name = name;
this.protocol = protocol;
}
public ServerData clone() {
return new ServerData(name, protocol);
}
@Override
public Object toNMS() {
try {
Object nms = Reflection.newInstance(nmsClass);
nameField.set(nms, name);
protocolField.setInt(nms, protocol);
return nms;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
public static class ServerInfo implements WrappedData {
private static Class nmsClass = Reflection.getNMSClass("ServerPing");
private static Field[] fields = nmsClass.getDeclaredFields();
static {
try {
for (int i = 0; i < 4; ++i)
fields[i].setAccessible(true);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public String description;
public String favicon;
public PlayerList players;
public ServerData version;
public ServerInfo() {
}
public ServerInfo(Object nms) {
try {
description = ChatTag.fromICBC(fields[0].get(nms)).toColoredString();
players = new PlayerList(fields[1].get(nms));
version = new ServerData(fields[2].get(nms));
favicon = (String) fields[3].get(nms);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
public ServerInfo clone() {
ServerInfo out = new ServerInfo();
out.description = description;
out.favicon = favicon;
out.players = players.clone();
out.version = version.clone();
return out;
}
@Override
public Object toNMS() {
try {
Object nms = Reflection.newInstance(nmsClass);
fields[0].set(nms, ChatTag.fromColoredText(description).toICBC());
fields[1].set(nms, players.toNMS());
fields[2].set(nms, version.toNMS());
fields[3].set(nms, favicon);
return nms;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
} | 5,372 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutMapChunk.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutMapChunk.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.nbt.NBTCompound;
import gyurix.nbt.NBTTagType;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* Created by GyuriX, on 2017. 03. 29..
*/
public class PacketPlayOutMapChunk extends WrappedPacket {
public byte[] chunkData;
public ChunkMap chunkMap;
public int chunkX;
public int chunkZ;
public NBTCompound heightMaps = new NBTCompound();
public boolean groundUpContinuous;
public int primaryBitMask;
public List<NBTCompound> tileEntities = new ArrayList<>();
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_14))
return PacketOutType.MapChunk.newPacket(chunkX, chunkZ, primaryBitMask, heightMaps.toNMS(), chunkData, toNMSTileEntityList(), groundUpContinuous);
if (Reflection.ver.isAbove(ServerVersion.v1_13))
return PacketOutType.MapChunk.newPacket(chunkX, chunkZ, primaryBitMask, chunkData, toNMSTileEntityList(), groundUpContinuous);
return PacketOutType.MapChunk.newPacket(chunkX, chunkZ, chunkMap.toNMS(), groundUpContinuous);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.MapChunk.getPacketData(packet);
chunkX = (int) d[0];
chunkZ = (int) d[1];
if (Reflection.ver.isAbove(ServerVersion.v1_13)) {
primaryBitMask = (int) d[2];
int from = 3;
if (Reflection.ver.isAbove(ServerVersion.v1_14))
heightMaps = (NBTCompound) NBTTagType.Compound.makeTag(d[from++]);
chunkData = (byte[]) d[from++];
for (Object o : (List) d[from++])
tileEntities.add((NBTCompound) NBTTagType.tag(o));
groundUpContinuous = (boolean) d[from++];
} else {
chunkMap = new ChunkMap(d[2]);
groundUpContinuous = (boolean) d[3];
}
}
public List<Object> toNMSTileEntityList() {
List<Object> out = new ArrayList<>();
for (NBTCompound tag : tileEntities)
out.add(tag.toNMS());
return out;
}
public static class ChunkMap implements WrappedData {
public static final Class nmsChunkMap = Reflection.getNMSClass("PacketPlayOutMapChunk$ChunkMap");
private static final Field byteArrayF = Reflection.getFirstFieldOfType(nmsChunkMap, byte[].class);
private static final Field intF = Reflection.getFirstFieldOfType(nmsChunkMap, int.class);
public byte[] data;
public int primaryBitMask;
public ChunkMap() {
}
public ChunkMap(Object o) {
try {
primaryBitMask = intF.getInt(o);
data = (byte[]) byteArrayF.get(o);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
}
@Override
public Object toNMS() {
try {
Object out = nmsChunkMap.newInstance();
byteArrayF.set(out, data);
intF.set(out, primaryBitMask);
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 3,203 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutCollect.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutCollect.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutCollect extends WrappedPacket {
public int collectedID, collectorID;
public PacketPlayOutCollect() {
}
public PacketPlayOutCollect(int collectedID, int collectorID) {
this.collectedID = collectedID;
this.collectorID = collectorID;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.Collect.newPacket(collectedID, collectorID);
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.Collect.getPacketData(obj);
collectedID = (int) data[0];
collectorID = (int) data[1];
}
}
| 778 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutUpdateSign.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutUpdateSign.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.chat.ChatTag;
import gyurix.nbt.NBTCompound;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.ChatAPI;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Array;
import static gyurix.nbt.NBTTagType.tag;
public class PacketPlayOutUpdateSign extends WrappedPacket {
public BlockLocation block;
public ChatTag[] lines;
public PacketPlayOutUpdateSign(BlockLocation loc, ChatTag[] lines) {
block = loc;
this.lines = lines;
}
public PacketPlayOutUpdateSign() {
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
NBTCompound nbt = new NBTCompound();
for (int i = 0; i < 4; ++i)
nbt.put("Text" + (i + 1), tag(lines[i].toString()));
PacketPlayOutTileEntityData packet = new PacketPlayOutTileEntityData(block, 9, nbt);
return packet.getVanillaPacket();
}
Object[] lines = (Object[]) Array.newInstance(ChatAPI.icbcClass, 4);
for (int i = 0; i < 4; ++i)
lines[i] = this.lines[i].toICBC();
return PacketOutType.UpdateSign.newPacket(null, block.toNMS(), lines);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketOutType.UpdateSign.getPacketData(packet);
block = new BlockLocation(data[1]);
lines = new ChatTag[4];
Object[] packetLines = (Object[]) data[2];
for (int i = 0; i < 4; ++i) {
lines[i] = ChatTag.fromICBC(packetLines[i]);
}
}
}
| 1,649 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutWindowItems.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutWindowItems.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
import java.lang.reflect.Array;
import java.util.ArrayList;
/**
* Created by gyurix on 25/11/2015.
*/
public class PacketPlayOutWindowItems extends WrappedPacket {
private static final Class itemClass = Reflection.getNMSClass("ItemStack");
public int inventoryId;
public ArrayList<ItemStackWrapper> items = new ArrayList<>();
public PacketPlayOutWindowItems() {
}
public PacketPlayOutWindowItems(int inventoryId, ArrayList<ItemStackWrapper> items) {
this.inventoryId = inventoryId;
this.items = items;
}
@Override
public Object getVanillaPacket() {
return PacketOutType.WindowItems.newPacket(inventoryId, makeNMSItemList());
}
@Override
public void loadVanillaPacket(Object obj) {
Object[] data = PacketOutType.WindowItems.getPacketData(obj);
inventoryId = (int) data[0];
items = wrapItemList((Object[]) data[1]);
}
private Object[] makeNMSItemList() {
Object[] d = (Object[]) Array.newInstance(itemClass, items.size());
for (int i = 0; i < items.size(); i++)
d[i] = items.get(i).toNMS();
return d;
}
private ArrayList<ItemStackWrapper> wrapItemList(Object[] nms) {
ArrayList<ItemStackWrapper> items = new ArrayList<>();
for (Object o : nms)
items.add(new ItemStackWrapper(o));
return items;
}
}
| 1,519 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayOutEntityTeleport.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/outpackets/PacketPlayOutEntityTeleport.java | package gyurix.protocol.wrappers.outpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketOutType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.LocationData;
import gyurix.spigotutils.ServerVersion;
/**
* Created by GyuriX on 2016.03.08..
*/
public class PacketPlayOutEntityTeleport extends WrappedPacket {
public int entityId;
public boolean onGround;
public byte pitch;
public double x;
public double y;
public byte yaw;
public double z;
public PacketPlayOutEntityTeleport() {
}
public PacketPlayOutEntityTeleport(int entityId, LocationData loc) {
this.entityId = entityId;
setLocation(loc);
}
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_9))
return PacketOutType.EntityTeleport.newPacket(entityId, x, y, z, yaw, pitch, onGround);
else if (Reflection.ver == ServerVersion.v1_8)
return PacketOutType.EntityTeleport.newPacket(entityId, (int) (x * 32), (int) (y * 32), (int) (z * 32), yaw, pitch, onGround);
else
return PacketOutType.EntityTeleport.newPacket(entityId, (int) (x * 32), (int) (y * 32), (int) (z * 32), yaw, pitch);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketOutType.EntityTeleport.getPacketData(packet);
entityId = (int) d[0];
if (Reflection.ver.isAbove(ServerVersion.v1_9)) {
x = (double) d[1];
y = (double) d[2];
z = (double) d[3];
} else {
x = (int) d[1] / 32.0;
y = (int) d[2] / 32.0;
z = (int) d[3] / 32.0;
}
yaw = (byte) d[4];
pitch = (byte) d[5];
if (Reflection.ver.isAbove(ServerVersion.v1_8))
onGround = (boolean) d[6];
}
public void setLocation(LocationData loc) {
x = loc.x;
y = loc.y;
z = loc.z;
yaw = (byte) (loc.yaw / 360.0 * 256);
pitch = (byte) (loc.pitch / 360.0 * 256);
}
}
| 1,918 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInSpectate.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInSpectate.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import java.util.UUID;
public class PacketPlayInSpectate
extends WrappedPacket {
private UUID entityUUID;
@Override
public Object getVanillaPacket() {
return PacketInType.Spectate.newPacket(entityUUID);
}
@Override
public void loadVanillaPacket(Object packet) {
entityUUID = (UUID) PacketInType.Spectate.getPacketData(packet)[0];
}
}
| 504 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInBlockDig.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInBlockDig.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.utils.Direction;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Method;
public class PacketPlayInBlockDig extends WrappedPacket {
public BlockLocation block;
public DigType digType;
public Direction direction;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_8) ? PacketInType.BlockDig.newPacket(block.toNMS(), direction == null ? null : direction.toNMS(), digType.toVanillaDigType()) :
PacketInType.BlockDig.newPacket(block.x, block.y, block.z, direction.ordinal(), digType.ordinal());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.BlockDig.getPacketData(packet);
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
block = new BlockLocation(d[0]);
direction = d[1] == null ? null : Direction.valueOf(d[1].toString().toUpperCase());
digType = DigType.valueOf(d[2].toString());
return;
}
block = new BlockLocation((int) d[0], (int) d[1], (int) d[2]);
direction = Direction.values()[(int) d[3]];
digType = DigType.values()[(int) d[4]];
}
public enum DigType {
START_DESTROY_BLOCK,
ABORT_DESTROY_BLOCK,
STOP_DESTROY_BLOCK,
DROP_ALL_ITEMS,
DROP_ITEM,
RELEASE_USE_ITEM;
private static final Method valueOf;
static {
valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayInBlockDig$EnumPlayerDigType"), "valueOf", String.class);
}
DigType() {
}
public Object toVanillaDigType() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,928 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInEntityAction.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInEntityAction.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Method;
public class PacketPlayInEntityAction
extends WrappedPacket {
public PlayerAction action;
public int entityId;
public int jumpBoost;
@Override
public Object getVanillaPacket() {
return PacketInType.EntityAction.newPacket(entityId, action.toVanillaPlayerAction(), jumpBoost);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.EntityAction.getPacketData(packet);
entityId = (Integer) d[0];
action = Reflection.ver.isAbove(ServerVersion.v1_8) ? PlayerAction.valueOf(d[1].toString()) : PlayerAction.values()[((Integer) d[1]) - 1];
jumpBoost = (Integer) d[2];
}
public enum PlayerAction {
START_SNEAKING,
STOP_SNEAKING,
STOP_SLEEPING,
START_SPRINTING,
STOP_SPRINTING,
RIDING_JUMP,
OPEN_INVENTORY;
private static final Method valueOf;
static {
valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayInEntityAction$EnumPlayerAction"), "valueOf", String.class);
}
PlayerAction() {
}
public Object toVanillaPlayerAction() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
}
}
| 1,528 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInBlockPlace.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInBlockPlace.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.utils.Direction;
import gyurix.protocol.utils.HandType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayInBlockPlace extends WrappedPacket {
public float cursorX;
public float cursorY;
public float cursorZ;
public Direction face;
public HandType hand;
public ItemStackWrapper itemStack;
public BlockLocation location;
public long timestamp;
@Override
public Object getVanillaPacket() {
Object[] d;
if (Reflection.ver == ServerVersion.v1_7) {
d = new Object[8];
d[0] = location.x;
d[1] = location.y;
d[2] = location.z;
d[3] = face == null ? 255 : face.ordinal();
d[4] = itemStack == null ? null : itemStack.toNMS();
d[5] = cursorX;
d[6] = cursorY;
d[7] = cursorZ;
} else if (Reflection.ver == ServerVersion.v1_8) {
d = new Object[7];
d[0] = location.toNMS();
d[1] = face == null ? 255 : face.ordinal();
d[2] = itemStack == null ? null : itemStack.toNMS();
d[3] = cursorX;
d[4] = cursorY;
d[5] = cursorZ;
d[6] = timestamp;
} else {
d = new Object[2];
d[0] = hand.toNMS();
d[1] = timestamp;
}
return PacketInType.BlockPlace.newPacket(d);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.BlockPlace.getPacketData(packet);
if (Reflection.ver.isBellow(ServerVersion.v1_8)) {
int st = 1;
if (Reflection.ver == ServerVersion.v1_8) {
location = new BlockLocation(data[0]);
} else {
location = new BlockLocation((int) data[0], (int) data[1], (int) data[2]);
st = 3;
}
face = Direction.get((Integer) data[st]);
itemStack = data[st + 1] == null ? null : new ItemStackWrapper(data[st + 1]);
cursorX = (Float) data[st + 2];
cursorY = (Float) data[st + 3];
cursorZ = (Float) data[st + 4];
timestamp = Reflection.ver.isAbove(ServerVersion.v1_8) ? (Long) data[st + 5] : System.currentTimeMillis();
} else {
hand = HandType.valueOf(data[0].toString());
timestamp = (Long) data[1];
}
}
}
| 2,396 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInSettings.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInSettings.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import org.bukkit.Difficulty;
import java.lang.reflect.Method;
public class PacketPlayInSettings extends WrappedPacket {
public boolean chatColors;
public ChatVisibility chatVisibility;
public Difficulty difficulty;
public String locale;
public int skinParts;
public int viewDistance;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_8) ?
PacketInType.Settings.newPacket(locale, viewDistance, chatVisibility.toVanillaChatVisibility(), chatColors, skinParts) :
PacketInType.Settings.newPacket(locale, viewDistance, chatVisibility.toVanillaChatVisibility(), chatColors, difficulty, (skinParts & 1) == 1);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.Settings.getPacketData(packet);
locale = (String) data[0];
viewDistance = (Integer) data[1];
chatVisibility = data[2] == null ? ChatVisibility.FULL : ChatVisibility.valueOf(data[2].toString());
chatColors = (Boolean) data[3];
if (Reflection.ver.isAbove(ServerVersion.v1_8))
skinParts = (Integer) data[4];
else {
if (data[4] != null)
difficulty = Difficulty.valueOf(data[4].toString());
skinParts = ((Boolean) data[5]) ? 1 : 0;
}
}
public enum ChatVisibility {
FULL,
SYSTEM,
HIDDEN;
private static final Method valueOf;
static {
valueOf = Reflection.getMethod(Reflection.getNMSClass("EntityHuman$EnumChatVisibility"), "valueOf", String.class);
}
ChatVisibility() {
}
public Object toVanillaChatVisibility() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,975 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInClientCommand.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInClientCommand.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import java.lang.reflect.Method;
public class PacketPlayInClientCommand
extends WrappedPacket {
public ClientCommand command;
@Override
public Object getVanillaPacket() {
return PacketInType.ClientCommand.newPacket(command.toVanillaClientCommand());
}
@Override
public void loadVanillaPacket(Object packet) {
command = ClientCommand.valueOf(PacketInType.ClientCommand.getPacketData(packet)[0].toString());
}
public enum ClientCommand {
PERFORM_RESPAWN,
REQUEST_STATS,
OPEN_INVENTORY_ACHIEVEMENT;
private static final Method valueOf;
static {
valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayInClientCommand$EnumClientCommand"), "valueOf", String.class);
}
ClientCommand() {
}
public Object toVanillaClientCommand() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,145 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInResourcePackStatus.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInResourcePackStatus.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import java.lang.reflect.Method;
public class PacketPlayInResourcePackStatus
extends WrappedPacket {
public String hash;
public ResourcePackStatus status;
@Override
public Object getVanillaPacket() {
return PacketInType.ResourcePackStatus.newPacket(hash, status.toVanillaRPStatus());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.ResourcePackStatus.getPacketData(packet);
hash = (String) data[0];
status = ResourcePackStatus.valueOf(data[1].toString());
}
public enum ResourcePackStatus {
SUCCESSFULLY_LOADED,
DECLINED,
FAILED_DOWNLOAD,
ACCEPTED;
private static final Method valueOf;
static {
valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayInResourcePackStatus$EnumResourcePackStatus"), "valueOf", String.class);
}
ResourcePackStatus() {
}
public Object toVanillaRPStatus() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,262 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInEnchantItem.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInEnchantItem.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInEnchantItem
extends WrappedPacket {
public int enchantment;
public int window;
@Override
public Object getVanillaPacket() {
return PacketInType.EnchantItem.newPacket(window, enchantment);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.EnchantItem.getPacketData(packet);
window = (Integer) data[0];
enchantment = (Integer) data[1];
}
}
| 580 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInTransaction.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInTransaction.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInTransaction
extends WrappedPacket {
public boolean accepted;
public short actionId;
public int windowId;
@Override
public Object getVanillaPacket() {
return PacketInType.Transaction.newPacket(windowId, actionId, accepted);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.Transaction.getPacketData(packet);
windowId = (Integer) data[0];
actionId = (Short) data[1];
accepted = (Boolean) data[2];
}
}
| 648 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInUpdateSign.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInUpdateSign.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.chat.ChatTag;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.ChatAPI;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Array;
public class PacketPlayInUpdateSign extends WrappedPacket {
public BlockLocation block;
public ChatTag[] lines;
@Override
public Object getVanillaPacket() {
Object[] lines = (Object[]) Array.newInstance(ChatAPI.icbcClass, 4);
if (Reflection.ver.isAbove(ServerVersion.v1_9))
for (int i = 0; i < 4; ++i)
lines[i] = this.lines[i].toColoredString();
else
for (int i = 0; i < 4; ++i)
lines[i] = this.lines[i].toICBC();
return PacketInType.UpdateSign.newPacket(block.toNMS(), lines);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.UpdateSign.getPacketData(packet);
block = new BlockLocation(data[0]);
lines = new ChatTag[4];
Object[] packetLines = (Object[]) data[1];
if (Reflection.ver.isAbove(ServerVersion.v1_9))
for (int i = 0; i < 4; ++i)
lines[i] = ChatTag.fromColoredText((String) packetLines[i]);
else
for (int i = 0; i < 4; ++i)
lines[i] = ChatTag.fromICBC(packetLines[i]);
}
}
| 1,387 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInCloseWindow.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInCloseWindow.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInCloseWindow
extends WrappedPacket {
public int id;
@Override
public Object getVanillaPacket() {
return PacketInType.CloseWindow.newPacket(id);
}
@Override
public void loadVanillaPacket(Object packet) {
id = (Integer) PacketInType.CloseWindow.getPacketData(packet)[0];
}
}
| 466 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketLoginInStart.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketLoginInStart.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.GameProfile;
import gyurix.protocol.wrappers.WrappedPacket;
/**
* Created by GyuriX on 2016.03.03..
*/
public class PacketLoginInStart extends WrappedPacket {
public GameProfile gp;
@Override
public Object getVanillaPacket() {
return PacketInType.LoginInStart.newPacket(gp.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
gp = new GameProfile(PacketInType.LoginInStart.getPacketData(packet)[0]);
}
}
| 564 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInWindowClick.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInWindowClick.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.InventoryClickType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayInWindowClick
extends WrappedPacket {
public short actionNumber;
public int button;
public InventoryClickType clickType;
public ItemStackWrapper item;
public int slot;
public int windowId;
public PacketPlayInWindowClick() {
}
public PacketPlayInWindowClick(int windowId, int slot, int button, short actionNumber, ItemStackWrapper item, InventoryClickType clickType) {
this.windowId = windowId;
this.slot = slot;
this.button = button;
this.actionNumber = actionNumber;
this.item = item;
this.clickType = clickType;
}
@Override
public Object getVanillaPacket() {
return PacketInType.WindowClick.newPacket(windowId, slot, button, actionNumber, item == null ? null : item.toNMS(), clickType.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] o = PacketInType.WindowClick.getPacketData(packet);
windowId = (Integer) o[0];
slot = (Integer) o[1];
button = (Integer) o[2];
actionNumber = (Short) o[3];
item = new ItemStackWrapper(o[4]);
clickType = Reflection.ver.isAbove(ServerVersion.v1_9) ? InventoryClickType.valueOf(o[5].toString()) : InventoryClickType.values()[(int) o[5]];
}
}
| 1,537 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInTabComplete.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInTabComplete.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.BlockLocation;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayInTabComplete extends WrappedPacket {
public boolean assumeCommand;
public BlockLocation block;
public String text;
public int transactionId;
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_13))
return PacketInType.TabComplete.newPacket(transactionId, text);
if (Reflection.ver.isAbove(ServerVersion.v1_10))
return PacketInType.TabComplete.newPacket(text, assumeCommand, block == null ? null : block.toNMS());
return PacketInType.TabComplete.newPacket(text, block == null ? null : block.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.TabComplete.getPacketData(packet);
if (Reflection.ver.isAbove(ServerVersion.v1_13)) {
transactionId = (int) data[0];
text = (String) data[1];
return;
}
text = (String) data[0];
if (Reflection.ver.isAbove(ServerVersion.v1_10)) {
assumeCommand = (boolean) data[1];
block = data[2] == null ? null : new BlockLocation(data[2]);
} else if (Reflection.ver.isAbove(ServerVersion.v1_8))
block = data[1] == null ? null : new BlockLocation(data[1]);
}
}
| 1,456 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInKeepAlive.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInKeepAlive.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInKeepAlive
extends WrappedPacket {
public int id;
@Override
public Object getVanillaPacket() {
return PacketInType.KeepAlive.newPacket(id);
}
@Override
public void loadVanillaPacket(Object packet) {
id = (Integer) PacketInType.KeepAlive.getPacketData(packet)[0];
}
}
| 460 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInCustomPayload.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInCustomPayload.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.configfile.ConfigSerialization.StringSerializable;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
public class PacketPlayInCustomPayload extends WrappedPacket implements StringSerializable {
public String channel;
public byte[] data;
@Override
public Object getVanillaPacket() {
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(data.length);
buf.writeBytes(data);
return PacketInType.CustomPayload.newPacket(channel, buf);
}
return PacketInType.CustomPayload.newPacket(channel, data.length, data);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.CustomPayload.getPacketData(packet);
channel = (String) d[0];
if (Reflection.ver.isAbove(ServerVersion.v1_8)) {
ByteBuf buf = ((ByteBuf) d[d.length - 1]);
data = new byte[buf.writerIndex()];
buf.readBytes(data);
buf.resetReaderIndex();
return;
}
data = (byte[]) d[d.length - 1];
}
@Override
public String toString() {
return channel;
}
}
| 1,330 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInFlying.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInFlying.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
public class PacketPlayInFlying extends WrappedPacket {
public boolean hasLook;
public boolean hasPos;
public double headY;
public boolean onGround;
public float pitch;
public double x;
public double y;
public float yaw;
public double z;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_8) ?
PacketInType.Flying.newPacket(x, y, z, yaw, pitch, onGround, hasPos, hasLook) :
PacketInType.Flying.newPacket(x, y, z, headY, yaw, pitch, onGround, hasPos, hasLook);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.Flying.getPacketData(packet);
x = (Double) data[0];
y = (Double) data[1];
z = (Double) data[2];
int start = 2;
if (Reflection.ver.isBellow(ServerVersion.v1_7)) {
headY = (Double) data[++start];
}
yaw = (Float) data[start + 1];
pitch = (Float) data[start + 2];
onGround = (Boolean) data[start + 3];
hasPos = (Boolean) data[start + 4];
hasLook = (Boolean) data[start + 5];
}
}
| 1,291 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInHeldItemSlot.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInHeldItemSlot.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInHeldItemSlot
extends WrappedPacket {
public int itemInHandIndex;
@Override
public Object getVanillaPacket() {
return PacketInType.HeldItemSlot.newPacket(itemInHandIndex);
}
@Override
public void loadVanillaPacket(Object packet) {
itemInHandIndex = (Integer) PacketInType.HeldItemSlot.getPacketData(packet)[0];
}
}
| 508 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInUseEntity.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInUseEntity.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.HandType;
import gyurix.protocol.utils.Vector;
import gyurix.protocol.utils.WrappedData;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.SU;
import gyurix.spigotutils.ServerVersion;
import java.lang.reflect.Method;
public class PacketPlayInUseEntity extends WrappedPacket {
public EntityUseAction action;
public int entityId;
public HandType hand;
public Vector targetLocation;
@Override
public Object getVanillaPacket() {
return PacketInType.UseEntity.newPacket(entityId, action.toNMS(), targetLocation == null ? null : targetLocation.toNMS(), hand == null ? null : hand.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.UseEntity.getPacketData(packet);
entityId = (int) d[0];
action = d[1] == null ? EntityUseAction.INTERACT : EntityUseAction.valueOf(d[1].toString());
if (Reflection.ver.isAbove(ServerVersion.v1_8))
targetLocation = d[2] == null ? null : new Vector(d[2]);
if (Reflection.ver.isAbove(ServerVersion.v1_9))
hand = d[3] == null ? null : HandType.valueOf(d[3].toString());
}
public enum EntityUseAction implements WrappedData {
INTERACT,
ATTACK,
INTERACT_AT;
Method valueOf = Reflection.getMethod(Reflection.getNMSClass("PacketPlayInUseEntity$EnumEntityUseAction"), "valueOf", String.class);
@Override
public Object toNMS() {
try {
return valueOf.invoke(null, name());
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
}
}
| 1,729 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInChat.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInChat.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInChat
extends WrappedPacket {
public String message;
@Override
public Object getVanillaPacket() {
return PacketInType.Chat.newPacket(message);
}
@Override
public void loadVanillaPacket(Object packet) {
message = (String) PacketInType.Chat.getPacketData(packet)[0];
}
}
| 462 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInSteerVehicle.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInSteerVehicle.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInSteerVehicle
extends WrappedPacket {
public float forward;
public boolean jump;
public float sideways;
public boolean unmount;
@Override
public Object getVanillaPacket() {
return PacketInType.SteerVehicle.newPacket(Float.valueOf(sideways), Float.valueOf(forward), jump, unmount);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.SteerVehicle.getPacketData(packet);
sideways = ((Float) data[0]).floatValue();
forward = ((Float) data[1]).floatValue();
jump = (Boolean) data[2];
unmount = (Boolean) data[3];
}
}
| 764 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInAbilities.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInAbilities.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInAbilities
extends WrappedPacket {
public boolean canFly;
public boolean canInstantlyBuild;
public float flySpeed;
public boolean isFlying;
public boolean isInvulnerable;
public float walkSpeed;
@Override
public Object getVanillaPacket() {
return PacketInType.Abilities.newPacket(isInvulnerable, isFlying, canFly, canInstantlyBuild, Float.valueOf(flySpeed), Float.valueOf(walkSpeed));
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.Abilities.getPacketData(packet);
isInvulnerable = (Boolean) data[0];
isFlying = (Boolean) data[1];
canFly = (Boolean) data[2];
canInstantlyBuild = (Boolean) data[3];
flySpeed = ((Float) data[4]).floatValue();
walkSpeed = ((Float) data[5]).floatValue();
}
}
| 957 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInSetCreativeSlot.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInSetCreativeSlot.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.ItemStackWrapper;
import gyurix.protocol.wrappers.WrappedPacket;
public class PacketPlayInSetCreativeSlot extends WrappedPacket {
public ItemStackWrapper itemStack;
public int slot;
@Override
public Object getVanillaPacket() {
return PacketInType.SetCreativeSlot.newPacket(slot, itemStack == null ? null : itemStack.toNMS());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] data = PacketInType.SetCreativeSlot.getPacketData(packet);
slot = (Integer) data[0];
itemStack = new ItemStackWrapper(data[1]);
}
}
| 679 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketPlayInArmAnimation.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketPlayInArmAnimation.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.utils.HandType;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotutils.ServerVersion;
import java.util.HashMap;
public class PacketPlayInArmAnimation extends WrappedPacket {
public int entityId;
public HandType hand;
public long timestamp;
public AnimationType type;
@Override
public Object getVanillaPacket() {
return Reflection.ver.isAbove(ServerVersion.v1_9) ? PacketInType.ArmAnimation.newPacket(hand.toNMS()) : PacketInType.ArmAnimation.newPacket(timestamp);
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.ArmAnimation.getPacketData(packet);
entityId = 0;
hand = HandType.MAIN_HAND;
timestamp = System.currentTimeMillis();
type = AnimationType.DAMAGE_ANIMATION;
if (Reflection.ver.isAbove(ServerVersion.v1_9))
hand = HandType.valueOf(d[0].toString());
else if (Reflection.ver.isAbove(ServerVersion.v1_8))
timestamp = (long) d[0];
else if (Reflection.ver.isBellow(ServerVersion.v1_7)) {
entityId = (int) d[0];
type = AnimationType.getById((int) d[1]);
}
}
public enum AnimationType {
SWING_ARM(0), DAMAGE_ANIMATION(1), LEAVE_BED(2), EAT_FOOD(3), CRITICAL_EFFECT(4), MAGIC_CRITICAL_EFFECT(5), UNKNOWN(102), CROUCH(104), UNCROUCH(105);
private static final HashMap<Integer, AnimationType> idMap = new HashMap<>();
static {
for (AnimationType at : values())
idMap.put(at.id, at);
}
private int id;
AnimationType(int id) {
this.id = id;
}
public static AnimationType getById(int id) {
return idMap.get(id);
}
public int getId() {
return id;
}
}
}
| 1,825 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketHandshakingInSetProtocol.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/wrappers/inpackets/PacketHandshakingInSetProtocol.java | package gyurix.protocol.wrappers.inpackets;
import gyurix.protocol.Reflection;
import gyurix.protocol.event.PacketInType;
import gyurix.protocol.wrappers.WrappedPacket;
import java.lang.reflect.Method;
/**
* Created by GyuriX on 2016.02.21..
*/
public class PacketHandshakingInSetProtocol extends WrappedPacket {
public String hostName;
public EnumProtocol nextState;
public int port;
public int version;
@Override
public Object getVanillaPacket() {
return PacketInType.HandshakingInSetProtocol.newPacket(version, hostName, port, nextState.getVanillaEnumProtocol());
}
@Override
public void loadVanillaPacket(Object packet) {
Object[] d = PacketInType.HandshakingInSetProtocol.getPacketData(packet);
version = (int) d[0];
hostName = (String) d[1];
port = (int) d[2];
nextState = EnumProtocol.valueOf(d[3].toString());
}
public enum EnumProtocol {
HANDSHAKING(-1), PLAY(0), STATUS(1), LOGIN(2);
private static Method vanilla = Reflection.getMethod(Reflection.getNMSClass("EnumProtocol"), "valueOf", String.class);
public int id;
EnumProtocol(int id) {
this.id = id;
}
public Object getVanillaEnumProtocol() {
try {
return vanilla.invoke(null, name());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}
}
| 1,351 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketInType.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/event/PacketInType.java | package gyurix.protocol.event;
import com.google.common.collect.Lists;
import gyurix.protocol.Reflection;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.Main;
import gyurix.spigotlib.SU;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
public enum PacketInType {
HandshakingInSetProtocol,
LoginInEncryptionBegin,
LoginInStart,
Abilities,
Advancements,
AdvancementTab,
ArmAnimation,
AutoRecipe,
BlockDig,
BlockPlace,
BEdit,
BoatMove,
Chat,
ClientCommand,
CloseWindow,
CustomPayload,
EnchantItem,
EntityAction,
Flying,
HeldItemSlot,
ItemName,
KeepAlive,
RecipeDisplayed,
ResourcePackStatus,
SetCreativeSlot,
Settings,
Spectate,
SteerVehicle,
TabComplete,
TeleportAccept,
Transaction,
TrSel,
UpdateSign,
UseEntity,
UseItem,
VehicleMove,
WindowClick,
StatusInPing,
StatusInStart;
private static final HashMap<Class, PacketInType> packets = new HashMap<>();
public Class<? extends WrappedPacket> wrapper;
ArrayList<Field> fs = new ArrayList<>();
private Constructor emptyConst;
private boolean supported;
PacketInType() {
}
/**
* Get the type of an incoming packet
*
* @param packet - The incoming packet
* @return The type of the given packet
*/
public static PacketInType getType(Object packet) {
Class cl = packet.getClass();
while (cl != null && cl != Object.class) {
String cn = cl.getName();
while (cn.contains("$")) {
try {
cl = Class.forName(cn.substring(0, cn.indexOf("$")));
cn = cl.getName();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
PacketInType type = packets.get(cl);
if (type != null)
return type;
cl = cl.getSuperclass();
}
return null;
}
/**
* Initializes the PacketInType, DO NOT USE THIS METHOD
*/
public static void init() {
for (PacketInType t : PacketInType.values()) {
String name = t.name();
String cln = "Packet" + (name.startsWith("Login") || name.startsWith("Status") || name.startsWith("Handshaking") ? name : "PlayIn" + name);
try {
Class cl = Reflection.getNMSClass(cln);
if (cl == null)
continue;
packets.put(cl, t);
t.emptyConst = cl.getConstructor();
t.fs = new ArrayList();
for (Field f : cl.getDeclaredFields()) {
if ((f.getModifiers() & 8) != 0) continue;
Reflection.setFieldAccessible(f);
t.fs.add(f);
}
t.supported = true;
} catch (Throwable ignored) {
}
try {
t.wrapper = (Class<? extends WrappedPacket>) Class.forName("gyurix.protocol.wrappers.inpackets." + cln);
} catch (Throwable ignored) {
}
}
}
/**
* Fills the given packet with the given data
*
* @param packet - The fillable packet
* @param data - The filling data
*/
public void fillPacket(Object packet, Object... data) {
ArrayList<Field> fields = Lists.newArrayList(fs);
for (Object d : data) {
for (int f = 0; f < fields.size(); f++) {
try {
Field ff = fields.get(f);
ff.set(packet, d);
fields.remove(f--);
break;
} catch (Throwable ignored) {
}
}
}
}
/**
* Returns the packet data of a packet
*
* @param packet - The packet
* @return The contents of all the non static fields of the packet
*/
public Object[] getPacketData(Object packet) {
Object[] out = new Object[fs.size()];
try {
for (int i = 0; i < fs.size(); ++i) {
out[i] = fs.get(i).get(packet);
}
return out;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
/**
* Tells if this packet is supported or not by the current server version.
*
* @return True if it is supported, false otherwise
*/
public boolean isSupported() {
return supported;
}
/**
* Creates a new packet of this type and fills its fields with the given data
*
* @param data - Data to fill packet fields with
* @return The crafted packet
*/
public Object newPacket(Object... data) {
try {
Object out = emptyConst.newInstance();
fillPacket(out, data);
return out;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
/**
* Get the wrapper of the given NMS packet.
*
* @param nmsPacket - The NMS packet
* @return The wrapper of the given NMS packet
*/
public WrappedPacket wrap(Object nmsPacket) {
try {
WrappedPacket wp = wrapper.newInstance();
wp.loadVanillaPacket(nmsPacket);
return wp;
} catch (Throwable e) {
SU.log(Main.pl, "§4[§cPacketAPI§4] §eError on wrapping §c" + name() + "§e out packet.");
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
}
| 5,036 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketInEvent.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/event/PacketInEvent.java | package gyurix.protocol.event;
import org.bukkit.entity.Player;
public class PacketInEvent extends PacketEvent {
private final PacketInType type;
public PacketInEvent(Object channel, Player plr, Object packet) {
super(channel, plr, packet);
type = PacketInType.getType(packet);
}
@Override
public Object[] getPacketData() {
return type.getPacketData(packet);
}
@Override
public void setPacketData(Object... data) {
type.fillPacket(getPacket(), data);
}
@Override
public boolean setPacketData(int id, Object o) {
try {
type.fs.get(id).set(packet, o);
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
public PacketInType getType() {
return type;
}
}
| 767 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketEvent.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/event/PacketEvent.java | package gyurix.protocol.event;
import gyurix.protocol.wrappers.WrappedPacket;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public abstract class PacketEvent extends Event implements Cancellable {
private static final HandlerList hl = new HandlerList();
private final Object channel;
private final Player player;
protected Object packet;
private boolean cancelled;
public PacketEvent(Object channel, Player plr, Object packet) {
this.channel = channel;
this.packet = packet;
player = plr;
}
public static HandlerList getHandlerList() {
return hl;
}
public Object getChannel() {
return channel;
}
public HandlerList getHandlers() {
return hl;
}
public Object getPacket() {
return packet;
}
public void setPacket(WrappedPacket packet) {
this.packet = packet.getVanillaPacket();
}
public void setPacket(Object packet) {
this.packet = packet;
}
public abstract Object[] getPacketData();
public abstract void setPacketData(Object... var1);
public Player getPlayer() {
return player;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
public abstract boolean setPacketData(int var1, Object var2);
}
| 1,372 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketOutType.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/event/PacketOutType.java | package gyurix.protocol.event;
import com.google.common.collect.Lists;
import gyurix.protocol.Reflection;
import gyurix.protocol.wrappers.WrappedPacket;
import gyurix.spigotlib.Main;
import gyurix.spigotlib.SU;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import static gyurix.spigotlib.Config.debug;
public enum PacketOutType {
Abilities,
Advancements,
Animation,
AttachEntity,
Bed,
Boss,
BlockAction,
BlockBreak,
BlockBreakAnimation,
BlockChange,
Camera,
Chat,
CloseWindow,
Collect,
CombatEvent,
Commands,
CustomPayload,
CustomSoundEffect,
Entity,
EntityDestroy,
EntityEffect,
EntityEquipment,
EntityHeadRotation,
EntityLook,
EntityMetadata,
EntityStatus,
EntityTeleport,
EntityVelocity,
Experience,
Explosion,
GameStateChange,
HeldItemSlot,
KeepAlive,
KickDisconnect,
LightUpdate,
Login,
LoginOutDisconnect,
LoginOutEncryptionBegin,
LoginOutSetCompression,
LoginOutSuccess,
Map,
MapChunk,
MapChunkBulk,
Mount,
MultiBlockChange,
NamedEntitySpawn,
NamedSoundEffect,
OpenBook,
OpenSignEditor,
OpenWindow,
OpenWindowMerchant,
PlayerInfo,
PlayerListHeaderFooter,
Position,
RelEntityMove,
RelEntityMoveLook,
Recipes,
RecipeUpdate,
RemoveEntityEffect,
ResourcePackSend,
Respawn,
ScoreboardDisplayObjective,
ScoreboardObjective,
ScoreboardScore,
ScoreboardTeam,
SelectAdvancementTab,
ServerDifficulty,
SetCompression,
SetCooldown,
SetSlot,
SpawnEntity,
SpawnEntityExperienceOrb,
SpawnEntityLiving,
SpawnEntityPainting,
SpawnEntityWeather,
SpawnPosition,
Statistic,
TabComplete,
Tags,
TileEntityData,
Title,
Transaction,
UnloadChunk,
UpdateAttributes,
UpdateEntityNBT,
UpdateHealth,
UpdateSign,
UpdateTime,
VehicleMove,
ViewCentre,
ViewDistance,
WindowData,
WindowItems,
WorldBorder,
WorldEvent,
WorldParticles,
StatusOutPong,
StatusOutServerInfo;
private static final HashMap<Class, PacketOutType> packets = new HashMap<>();
public Class<? extends WrappedPacket> wrapper;
ArrayList<Field> fs;
private Constructor emptyConst;
private boolean supported;
PacketOutType() {
}
/**
* Get the type of an outgoing packet
*
* @param packet - The outgoing packet
* @return The type of the given packet
*/
public static PacketOutType getType(Object packet) {
Class cl = packet.getClass();
while (cl != null && cl != Object.class) {
String cn = cl.getName();
PacketOutType type = packets.get(cl);
if (type != null)
return type;
if (cl == null && cn.contains("$")) {
try {
cl = Class.forName(cn.substring(0, cn.indexOf("$")));
} catch (ClassNotFoundException ignored) {
}
}
type = packets.get(cl);
if (type != null)
return type;
cl = cl.getSuperclass();
}
return null;
}
/**
* Initializes the PacketOutType, DO NOT USE THIS METHOD
*/
public static void init() {
for (PacketOutType t : PacketOutType.values()) {
String name = t.name();
String cln = "Packet" + (name.startsWith("LoginOut") || name.startsWith("Status") ? name : "PlayOut" + name);
try {
Class cl = Reflection.getNMSClass(cln);
if (cl == null)
cl = Reflection.getNMSClass("PacketPlayOutEntity$" + cln);
if (cl == null)
continue;
packets.put(cl, t);
t.emptyConst = cl.getConstructor();
t.fs = new ArrayList();
for (Field f : cl.getDeclaredFields()) {
if ((f.getModifiers() & 8) != 0) continue;
f.setAccessible(true);
t.fs.add(f);
}
t.supported = true;
} catch (Throwable ignored) {
}
try {
t.wrapper = (Class<? extends WrappedPacket>) Class.forName("gyurix.protocol.wrappers.outpackets." + cln);
} catch (Throwable ignored) {
}
}
}
/**
* Fills the given packet with the given data
*
* @param packet - The fillable packet
* @param data - The filling data
*/
public void fillPacket(Object packet, Object... data) {
ArrayList<Field> fields = Lists.newArrayList(fs);
for (Object d : data) {
for (int f = 0; f < fields.size(); f++) {
try {
Field ff = fields.get(f);
ff.set(packet, d);
fields.remove(f--);
break;
} catch (Throwable e) {
debug.msg("Packet", e);
}
}
}
}
/**
* Returns the packet data of a packet
*
* @param packet - The packet
* @return The contents of all the non static fields of the packet
*/
public Object[] getPacketData(Object packet) {
Object[] out = new Object[fs.size()];
try {
for (int i = 0; i < fs.size(); ++i) {
out[i] = fs.get(i).get(packet);
}
return out;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
/**
* Tells if this packet is supported or not by the current server version.
*
* @return True if it is supported, false otherwise
*/
public boolean isSupported() {
return supported;
}
/**
* Creates a new packet of this type and fills its fields with the given data
*
* @param data - Data to fill packet fields with
* @return The crafted packet
*/
public Object newPacket(Object... data) {
try {
Object out = emptyConst.newInstance();
fillPacket(out, data);
return out;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
/**
* Get the wrapper of the given NMS packet.
*
* @param nmsPacket - The NMS packet
* @return The wrapper of the given NMS packet
*/
public WrappedPacket wrap(Object nmsPacket) {
try {
WrappedPacket wp = wrapper.newInstance();
wp.loadVanillaPacket(nmsPacket);
return wp;
} catch (Throwable e) {
SU.log(Main.pl, "§4[§cPacketAPI§4] §eError on wrapping §c" + name() + "§e out packet.");
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return null;
}
}
}
| 6,157 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
PacketOutEvent.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/protocol/event/PacketOutEvent.java | package gyurix.protocol.event;
import org.bukkit.entity.Player;
public class PacketOutEvent extends PacketEvent {
private final PacketOutType type;
public PacketOutEvent(Object channel, Player plr, Object packet) {
super(channel, plr, packet);
type = PacketOutType.getType(packet);
}
@Override
public Object[] getPacketData() {
return type.getPacketData(packet);
}
@Override
public void setPacketData(Object... data) {
type.fillPacket(packet, data);
}
@Override
public boolean setPacketData(int id, Object o) {
try {
type.fs.get(id).set(packet, o);
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
public PacketOutType getType() {
return type;
}
}
| 767 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
WebApi.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/mojang/WebApi.java | package gyurix.mojang;
import gyurix.spigotlib.SU;
import org.apache.logging.log4j.core.util.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import static gyurix.spigotlib.Config.debug;
/**
* Created by GyuriX on 2016. 06. 10..
*/
public class WebApi {
/**
* @param urlString - The URL to the file
* @param filename - The path to the downloaded file
* @return True if successful otherwise false
*/
public static boolean download(String urlString, String filename) {
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
File f = new File(filename).getAbsoluteFile();
f.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(filename);
SU.transloadStream(con.getInputStream(), fos);
fos.close();
return true;
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
return false;
}
}
public static String get(String urlString) {
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
return IOUtils.toString(new InputStreamReader(con.getInputStream()));
} catch (Throwable e) {
debug.msg("Web", e);
return null;
}
}
public static String post(String urlString, String req) {
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(req.getBytes(Charset.forName("UTF-8")));
return IOUtils.toString(new InputStreamReader(con.getInputStream()));
} catch (Throwable e) {
debug.msg("Web", e);
return null;
}
}
public static String postWithHeader(String urlString, String headerKey, String headerValue, String req) {
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Length", String.valueOf(req.length()));
con.setRequestProperty(headerKey, headerValue);
con.getOutputStream().write(req.getBytes(Charset.forName("UTF-8")));
return IOUtils.toString(new InputStreamReader(con.getInputStream()));
} catch (Throwable e) {
debug.msg("Web", e);
return null;
}
}
}
| 2,557 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
ClientSession.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/mojang/ClientSession.java | package gyurix.mojang;
import gyurix.json.JsonAPI;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import static gyurix.mojang.WebApi.post;
import static gyurix.mojang.WebApi.postWithHeader;
/**
* Created by GyuriX on 2016. 06. 10..
*/
public class ClientSession {
public String accessToken, clientToken, username, password;
public ArrayList<ClientProfile> availableProfiles;
public ClientProfile selectedProfile;
public void changeSkin(String newSkinURL, boolean slimModel) {
try {
postWithHeader("https://api.mojang.com/user/profile/" + selectedProfile.id + "/skin", "Authorization", "Bearer " + accessToken,
"model=" + (slimModel ? "slim&url=" : "&url=") + URLEncoder.encode(newSkinURL, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public boolean invalidate() {
try {
post("https://authserver.mojang.com/invalidate",
"{\"accessToken\": \"" + accessToken + "\"," +
"\"clientToken\": \"" + clientToken + "\"}");
return true;
} catch (Throwable e) {
return false;
}
}
public boolean refresh() {
try {
String s = post("https://authserver.mojang.com/refresh",
"{\"accessToken\": \"" + accessToken + "\"," +
"\"clientToken\": \"" + clientToken + "\"}");
ClientSession newClient = JsonAPI.deserialize(s, ClientSession.class);
accessToken = newClient.accessToken;
return true;
} catch (Throwable e) {
return false;
}
}
public boolean signOut() {
try {
post("https://authserver.mojang.com/signout",
"{\"username\": \"" + username + "\"," +
"\"password\": \"" + password + "\"}");
return true;
} catch (Throwable e) {
return false;
}
}
public boolean uploadSkin(File f, boolean slimModel) {
try {
MultipartUtility mu = new MultipartUtility("https://api.mojang.com/user/profile/" + selectedProfile.id + "/skin", "PUT");
mu.addHeaderField("Authorization", "Bearer " + accessToken);
mu.addFormField("model", slimModel ? "slim" : "alex");
mu.addFilePart("file", f);
mu.finish();
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
public boolean validate() {
try {
post("https://authserver.mojang.com/validate",
"{\"accessToken\": \"" + accessToken + "\"," +
"\"clientToken\": \"" + clientToken + "\"}");
return true;
} catch (Throwable e) {
return false;
}
}
}
| 2,699 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
SkinManager.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/mojang/SkinManager.java | package gyurix.mojang;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import gyurix.protocol.utils.GameProfile;
import gyurix.spigotlib.SU;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public final class SkinManager {
private static final Cache<String, GameProfile.Property> skinCache = CacheBuilder.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
.build();
public static GameProfile.Property getSkin(String name) {
try {
return skinCache.get(name, () -> MojangAPI.getProfileWithSkin(getUUID(name)).properties.get(0));
} catch (Throwable e) {
SU.error(SU.cs, e, "SpigotLib", "gyurix");
}
return null;
}
public static UUID getUUID(String name) {
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
if (op == null) {
System.out.println("[SpigotLib] [SkinManager] " + name + " player is NULL");
return MojangAPI.getProfile(name).id;
}
if (op.getUniqueId() == null) {
System.out.println("[SpigotLib] [SkinManager] " + name + " player.getUniqueId() is NULL");
return MojangAPI.getProfile(name).id;
}
return op.getUniqueId();
}
}
| 1,250 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
MultipartUtility.java | /FileExtraction/Java_unseen/gyurix_SpigotLib/src/main/java/gyurix/mojang/MultipartUtility.java | package gyurix.mojang;
import org.apache.logging.log4j.core.util.IOUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/**
* This utility class provides an abstraction layer for sending multipart HTTP
*/
public class MultipartUtility {
private static final String LINE_FEED = "\r\n";
private final String boundary;
private String charset = "UTF-8";
private HttpURLConnection con;
private ByteArrayOutputStream outputStream;
private PrintWriter writer;
/**
* This constructor initializes a new HTTP request with content type
* is set to multipart/form-data
*
* @param requestURL - The url to which the request should be sent
* @param method - The type of the HTTP request, usually POST
* @throws IOException - The type of the HTTP request
*/
public MultipartUtility(String requestURL, String method) throws IOException {
charset = charset;
// creates a unique boundary based on time stamp
boundary = "===" + System.currentTimeMillis() + "===";
URL url = new URL(requestURL);
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(method);
con.setDoOutput(true);
con.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" + boundary);
outputStream = new ByteArrayOutputStream();
writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), true);
}
/**
* Adds a upload file section to the request
*
* @param fieldName - Name attribute
* @param uploadFile - the uploadable File
* @throws IOException - The error what can happen during the operation
*/
public void addFilePart(String fieldName, File uploadFile) throws IOException {
String fileName = uploadFile.getName();
writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"").append(fieldName).append("\"; filename=\"").append(fileName).append("\"")
.append(LINE_FEED);
writer.append("Content-Type: ").append(URLConnection.guessContentTypeFromName(fileName))
.append(LINE_FEED);
writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
writer.append(LINE_FEED);
FileInputStream inputStream = new FileInputStream(uploadFile);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
inputStream.close();
writer.append(LINE_FEED);
writer.flush();
}
/**
* Adds a form field to the request
*
* @param name field name
* @param value field value
*/
public void addFormField(String name, String value) {
writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"").append(name).append("\"")
.append(LINE_FEED);
writer.append("Content-Type: text/plain; charset=").append(charset).append(
LINE_FEED);
writer.append(LINE_FEED);
writer.append(value).append(LINE_FEED);
}
/**
* Adds a header field to the request.
*
* @param name - name of the header field
* @param value - value of the header field
*/
public void addHeaderField(String name, String value) {
writer.append(name).append(": ").append(value).append(LINE_FEED);
writer.flush();
}
/**
* Completes the request and receives response from the server.
*
* @return A list of Strings as response in case the server returned
* status OK, otherwise an exception is thrown.
* @throws IOException - The ewrror what can happen during the operation
*/
public String finish() throws IOException {
writer.append(LINE_FEED).append("--").append(boundary).append("--").append(LINE_FEED);
writer.close();
byte[] data = outputStream.toByteArray();
con.setRequestProperty("Content-Length", String.valueOf(data.length));
con.getOutputStream().write(data);
con.getOutputStream().flush();
return IOUtils.toString(new InputStreamReader(con.getInputStream()));
}
} | 4,145 | Java | .java | gyurix/SpigotLib | 53 | 6 | 3 | 2018-03-14T22:12:00Z | 2020-10-05T05:01:38Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.