org.inventivetalent.reflection.minecraft.Minecraft Java Examples
The following examples show how to use
org.inventivetalent.reflection.minecraft.Minecraft.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClickListener.java From AnimatedFrames with MIT License | 6 votes |
@EventHandler public void on(PlayerInteractEvent event) { if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) { if (event.getHand() != EquipmentSlot.HAND) { return; } } int actionId = 0; switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: actionId = 0; break; case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: actionId = 1; break; } handleInteract(event.getPlayer(), event, actionId); }
Example #2
Source File: PacketHandler.java From PacketListenerAPI with MIT License | 5 votes |
public void sendPacket(Player p, Object packet) { if (p == null || packet == null) { throw new NullPointerException(); } try { Object handle = Minecraft.getHandle(p); Object connection = EntityPlayerFieldResolver.resolve("playerConnection").get(handle); PlayerConnectionMethodResolver.resolve("sendPacket").invoke(connection, new Object[] { packet }); } catch (Exception e) { System.err.println("[PacketListenerAPI] Exception while sending " + packet + " to " + p); e.printStackTrace(); } }
Example #3
Source File: ClassBuilder.java From NickNamer with MIT License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Object buildPlayerInfoPacket(int action, Object profile, int ping, int gamemodeOrdinal, String name) { try { Object packet = PacketPlayOutPlayerInfo.newInstance(); if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) { PacketPlayOutPlayerInfoFieldResolver.resolve("action").set(packet, action); PacketPlayOutPlayerInfoFieldResolver.resolve("player").set(packet, profile); PacketPlayOutPlayerInfoFieldResolver.resolve("gamemode").set(packet, gamemodeOrdinal); PacketPlayOutPlayerInfoFieldResolver.resolve("ping").set(packet, ping); PacketPlayOutPlayerInfoFieldResolver.resolve("username").set(packet, name); } else { PacketPlayOutPlayerInfoFieldResolver.resolve("a").set(packet, EnumPlayerInfoAction.getEnumConstants()[action]); List list = (List) PacketPlayOutPlayerInfoFieldResolver.resolve("b").get(packet); Object data; // if (NPCLib.getServerVersion() <= 181) { data = PlayerInfoData.getConstructor(PacketPlayOutPlayerInfo, getNMUtilClass("com.mojang.authlib.GameProfile"), int.class, EnumGamemode, IChatBaseComponent).newInstance(packet, profile, ping, EnumGamemode.getEnumConstants()[gamemodeOrdinal], buildChatComponent(name)); // } else { // data = PlayerInfoData.getConstructor(getNMUtilClass("com.mojang.authlib.GameProfile"), int.class, EnumGamemode, // Reflection.getNMSClass("IChatBaseComponent")).newInstance(profile, ping, EnumGamemode.getEnumConstants()[gamemodeOrdinal], buildChatComponent(name)); // } list.add(data); } return packet; } catch (Exception e) { e.printStackTrace(); } return null; }
Example #4
Source File: ClassBuilder.java From NickNamer with MIT License | 5 votes |
public static Object getGameProfile(Player player) { try { return EntityHumanMethodResolver.resolve("getProfile").invoke(Minecraft.getHandle(player)); } catch (Exception e) { throw new RuntimeException(e); } }
Example #5
Source File: NMUChannel.java From PacketListenerAPI with MIT License | 4 votes |
net.minecraft.util.io.netty.channel.Channel getChannel(Player player) throws ReflectiveOperationException { final Object handle = Minecraft.getHandle(player); final Object connection = playerConnection.get(handle); return (net.minecraft.util.io.netty.channel.Channel) channelField.get(networkManager.get(connection)); }
Example #6
Source File: INCChannel.java From PacketListenerAPI with MIT License | 4 votes |
io.netty.channel.Channel getChannel(Player player) throws ReflectiveOperationException { final Object handle = Minecraft.getHandle(player); final Object connection = playerConnection.get(handle); return (io.netty.channel.Channel) channelField.get(networkManager.get(connection)); }
Example #7
Source File: ClassBuilder.java From NickNamer with MIT License | 4 votes |
public static Class<?> getNMUtilClass(String name) throws ClassNotFoundException { if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R1)) { return Class.forName("net.minecraft.util." + name); } else { return Class.forName(name); } }
Example #8
Source File: AnimatedFrame.java From AnimatedFrames with MIT License | 4 votes |
public void refreshFrames() { if (!plugin.isEnabled()) { return; } Bukkit.getScheduler().runTask(plugin, new Runnable() { @Override public void run() { TimingsHelper.startTiming("AnimatedFrames - [" + getName() + "] refreshItemFrames"); final World world = getWorld(); if (world == null || world.getPlayers().isEmpty()) { itemFrameIds = NULL_INT_ARRAY; } else { itemFrameIds = new int[width][height]; itemFrameUUIDs = new UUID[width][height]; Vector2DDouble startVector = minCorner2d; Collection<? extends Entity> entities; if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_8_R2)) { entities = world.getEntitiesByClass(ItemFrame.class); } else { int size = Math.max(width, height); entities = world.getNearbyEntities(baseVector.toBukkitLocation(world), size, size, size); } for (Entity entity : entities) { if (entity instanceof ItemFrame) { if (((ItemFrame) entity).getFacing() == facing.getFrameDirection()) { if (boundingBox.expand(0.1).contains(new Vector3DDouble(entity.getLocation()))) { for (int y1 = 0; y1 < getBlockHeight(); y1++) { for (int x1 = 0; x1 < getBlockWidth(); x1++) { int x = facing.isHorizontalModInverted() ? (getBlockWidth() - 1 - x1) : x1; int y = facing.isVerticalModInverted() ? (getBlockHeight() - 1 - y1) : y1; Vector3DDouble vector3d = facing.getPlane().to3D(startVector.add(x, y), baseVector.getX(), baseVector.getZ(), baseVector.getY()); if (entity.getLocation().getBlockZ() == vector3d.getZ().intValue()) { if (entity.getLocation().getBlockX() == vector3d.getX().intValue()) { if (entity.getLocation().getBlockY() == vector3d.getY().intValue()) { itemFrameIds[x1][y1] = entity.getEntityId(); itemFrameUUIDs[x1][y1] = entity.getUniqueId(); entity.setMetadata("ANIMATED_FRAMES_META", new FixedMetadataValue(plugin, AnimatedFrame.this)); } } } } } } } } } } TimingsHelper.stopTiming("AnimatedFrames - [" + getName() + "] refreshItemFrames"); } }); }