Skip to content

Instantly share code, notes, and snippets.

View hugo4715's full-sized avatar
😁
Always coding

hugo4715

😁
Always coding
View GitHub Profile
@hugo4715
hugo4715 / ItemSerialization.java
Created December 30, 2015 14:30 — forked from aadnk/ItemSerialization.java
Only use this version if you've used ItemSerialization before, and want backwards compatibility. This Bukkit-only version is far superior: https://gist.github.com/aadnk/8138186
package com.comphenix.example;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.lang.reflect.Method;
private static Object minecraftServer;
private static Field recentTps;
public static double[] getRecentTps() {
try {
if (minecraftServer == null) {
Server server = Bukkit.getServer();
Field consoleField = server.getClass().getDeclaredField("console");
consoleField.setAccessible(true);
minecraftServer = consoleField.get(server);
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class AIUtils {
private static Field fromMobSpawner;
private static Method getHandle;
private static Method getHandleMethod;
private static Field pingField;
private static int getPing(Player player) {
try {
if (getHandleMethod == null) {
getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
getHandleMethod.setAccessible(true);
}
Object entityPlayer = getHandleMethod.invoke(player);
import com.google.common.base.Charsets;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;
import java.lang.reflect.Constructor;
package fr.hugo4715.paytoprotect.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
package fr.hugo4715.paytoprotect.utils;
import java.util.Arrays;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class ItemFactory {
package fr.hugo4715.paytoprotect;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@hugo4715
hugo4715 / HotbarMessage.java
Created February 14, 2016 14:38
An easy way to send over-hotbar-messages to players!
// package tld.domain.project.name;
import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.HashMap;
/*********************IMPORTANT*********************************************
* Need to figure out how to remove the fakePlayer's name in the tab list.**
***************************************************************************/
public class NPCUtils {
private static List<Integer> npcs = new ArrayList<Integer>();
public static void despawnAll(){
for(ForcePlayer cur : PlayerManager.getPlayers()){
for(Integer i : npcs){
if(!cur.getPlayer().isOnline())continue;