Skip to content

Instantly share code, notes, and snippets.

@aadnk
aadnk / CustomPingData.java
Created May 30, 2014 20:50
Send custom ping data.
package com.comphenix.example;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@aadnk
aadnk / CustomPingData.java
Last active August 29, 2015 14:02
Recieve custom data through ping packets. See https://gist.github.com/aadnk/59756145619d076ccd04 in order to test this.
package com.comphenix.example;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ConcurrentMap;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@aadnk
aadnk / SimpleMinecraftClient.java
Created May 30, 2014 23:39
Testing sending custom data through ping packets.
package com.comphenix.test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
@aadnk
aadnk / ItemSerialization.java
Created July 8, 2014 17:07
AttributeStorage example (required) - store the content of a chest directly in its item stack.
package com.comphenix.example;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
@aadnk
aadnk / GlowInCreativeMode.java
Created August 11, 2014 23:13
Add enchantment glow to items in creative mode. Requires AttributeStorage and TinyProtocol (can be added directly to your plugin).
package com.comphenix.example;
import java.sql.Ref;
import java.util.Collections;
import java.util.UUID;
import net.minecraft.util.io.netty.channel.Channel;
import org.bukkit.Material;
import org.bukkit.command.Command;
@aadnk
aadnk / ChangingUnknownCommand.java
Created September 11, 2014 02:17
Change the "unknown command message" with TinyProtocol.
package com.comphenix.example;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject;
public class ChangingUnknownCommand extends JavaPlugin implements Listener {
private MessageTransformer transformer;
@aadnk
aadnk / Test.java
Created December 19, 2014 17:30
Test of MagicAccessorImpl to speed up access of private packet fields
package com.comphenix.example;
import java.util.concurrent.ConcurrentMap;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.injector.StructureCache;
import com.comphenix.protocol.reflect.FieldUtils;
@aadnk
aadnk / gist:4e2064d17f54970c1d4c
Created May 14, 2015 23:33
Amaz Boombot Simulation
package com.comphenix.testing;
import java.util.Random;
public class Test {
private static final int SIMULATION_COUNT = 1_000_000_000;
public static void main(String[] args) throws Exception {
Random rnd = new Random();
int amazWin = 0;
@aadnk
aadnk / PatternMatchingTest.java
Last active August 3, 2017 17:16
Test of the pattern matching pseudo code in "Pattern Matching with Brian Goetz @briangoetz"
package com.comphenix.test;
import java.util.Objects;
public class PatternMatchingTest {
public static void main(String[] args) throws Exception {
AddNode zeroPlusOne = new AddNode(IntNode.ZERO, IntNode.ONE);
AddNode onePlusOne = new AddNode(IntNode.ONE, IntNode.ONE);
System.out.println("Testing our proposed fix: ");
import java.util.*;
public class TimeMap<TKey extends Comparable<TKey>, TValue> {
public static void main(String[] args) {
TimeMap<Integer, Integer> map = new TimeMap<>();
map.set(1, 1, 0);
map.set(1, 2, 2);
map.remove(1, 3);
map.set(2, 100, 0);