Skip to content

Instantly share code, notes, and snippets.

Kristian S. Stangeland aadnk

View GitHub Profile
@aadnk
aadnk / SquareSpiral.java
Last active Jan 25, 2019
Trapped Knight Problem
View SquareSpiral.java
import java.util.*;
public class SquareSpiral {
// Starting point of the spiral
private final int startX;
private final int startY;
private SquareSpiral(int startX, int startY) {
this.startX = startX;
this.startY = startY;
View TimeMap.java
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);
@aadnk
aadnk / PatternMatchingTest.java
Last active Aug 3, 2017
Test of the pattern matching pseudo code in "Pattern Matching with Brian Goetz @briangoetz"
View PatternMatchingTest.java
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: ");
@aadnk
aadnk / gist:4e2064d17f54970c1d4c
Created May 14, 2015
Amaz Boombot Simulation
View gist:4e2064d17f54970c1d4c
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 / Test.java
Created Dec 19, 2014
Test of MagicAccessorImpl to speed up access of private packet fields
View Test.java
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 / ChangingUnknownCommand.java
Created Sep 11, 2014
Change the "unknown command message" with TinyProtocol.
View ChangingUnknownCommand.java
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 / GlowInCreativeMode.java
Created Aug 11, 2014
Add enchantment glow to items in creative mode. Requires AttributeStorage and TinyProtocol (can be added directly to your plugin).
View GlowInCreativeMode.java
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 / ItemSerialization.java
Created Jul 8, 2014
AttributeStorage example (required) - store the content of a chest directly in its item stack.
View ItemSerialization.java
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 / SimpleMinecraftClient.java
Created May 30, 2014
Testing sending custom data through ping packets.
View SimpleMinecraftClient.java
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 / CustomPingData.java
Last active Aug 29, 2015
Recieve custom data through ping packets. See https://gist.github.com/aadnk/59756145619d076ccd04 in order to test this.
View CustomPingData.java
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;
You can’t perform that action at this time.