Skip to content

Instantly share code, notes, and snippets.

@aadnk
aadnk / Protocol.java
Created November 7, 2013 02:15
The original source code of ek.java (probably)
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import net.minecraft.server.Packet;
@aadnk
aadnk / FakePumpinHelmets.java
Created October 24, 2013 01:04
Display a fake pumkin helmet for all users. DEPRECIATED: Use https://gist.github.com/aadnk/11323369 instead.
package com.comphenix.example;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@aadnk
aadnk / AABB.java
Created October 23, 2013 18:25
A simple AABB intersection algorithm for Bukkit. Returns the intersection point as well.
/**
* Represents an axix-aligned bounding box.
*
* @author Kristian
*/
public class AABB {
public static class Vec3D {
/**
* Point with the coordinate (1, 1, 1).
*/
@aadnk
aadnk / ExampleMod.java
Last active December 25, 2022 22:47
Intercept the TAB packet without ProtocolLib. Disallow tab completion of command names, but not parameters.
package com.comphenix.example;
import org.bukkit.plugin.java.JavaPlugin;
public class ExampleMod extends JavaPlugin {
private TabInterceptor interceptor;
@Override
public void onEnable() {
// Use ProtocolLib if its present
@aadnk
aadnk / GlowPlugn.java
Created October 15, 2013 23:53
Demonstrate the use of ItemRenamer's new API.
package com.comphenix.example;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@aadnk
aadnk / ChangingUnknownCommand.java
Created October 11, 2013 18:49
How to change the "unknown command" error message with ProtocolLib. Updated for Minecraft 1.6.4.
package com.comphenix.example;
import org.bukkit.ChatColor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.comphenix.protocol.Packets;
@aadnk
aadnk / ExtendedLogoutTime2.java
Created October 10, 2013 02:47
Second attempt at extending the logout time of players. This time we also handle players that simply quit the application.
package com.comphenix.example;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
@aadnk
aadnk / ExtendLogoutTime.java
Last active December 25, 2015 01:09
Extend the time player's stay logged on on the server when they log out. This prevents PvP'ers from logging out in the middle of a fight.
package com.comphenix.example;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@aadnk
aadnk / AttributeStorage.java
Created September 29, 2013 17:12
Store arbitrary data on an ItemStack safely by using attributes. Use the following attribute class: https://gist.github.com/aadnk/6754159
package com.comphenix.example;
import java.util.UUID;
import org.bukkit.inventory.ItemStack;
import com.comphenix.example.Attributes.Attribute;
import com.comphenix.example.Attributes.AttributeType;
import com.comphenix.example.Attributes.Operation;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
@aadnk
aadnk / Attributes.java
Last active August 7, 2019 00:30
An attribute API that uses the following NbtFactory library: https://gist.github.com/aadnk/6753244
package com.comphenix.example;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.inventory.ItemStack;