Skip to content

Instantly share code, notes, and snippets.

@aadnk
aadnk / GhostManager.java
Last active July 13, 2019 21:22
Second version of GhostManager
package com.comphenix.example;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@aadnk
aadnk / GhostManager.java
Created May 25, 2013 02:06
Ghosts in Minecraft
// Based on lenis0012's GhostFactory
package com.comphenix.example;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
@aadnk
aadnk / BlockChangeArray.java
Created May 17, 2013 04:42
Disguise a block (like a chest) as an arbitrary block.
package com.comphenix.example;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import org.bukkit.Location;
import org.bukkit.World;
/**
* Utility class for creating arrays of block changes.
@aadnk
aadnk / Ability.java
Last active November 6, 2024 14:25
A simple cooldown system with charges.
package com.comphenix.example;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.bukkit.entity.Player;
public class Ability {
/**
@aadnk
aadnk / DetectFireworks.java
Created May 15, 2013 04:25
Detect when fireworks explode.
package com.comphenix.example;
import org.bukkit.World;
import org.bukkit.entity.Firework;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ConnectionSide;
@aadnk
aadnk / CancellationDetector.java
Last active April 23, 2025 02:06
A class that allows you to detect which plugin cancelled a given event.
package com.comphenix.example;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import org.bukkit.event.Cancellable;
@aadnk
aadnk / ShootingMod.java
Last active December 26, 2022 18:53
A simple demonstration of how to implement guns in Bukkit.
public class ExampleMod extends JavaPlugin implements Listener {
final int ATTACK_REACH = 100; // meters
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onInteract(PlayerInteractEvent evt) {
@aadnk
aadnk / REPLBukkit.java
Last active December 17, 2015 00:38
Read-eval-print loop in CraftBukkit.
package com.comphenix.example;
import java.util.concurrent.TimeUnit;
import javax.script.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.*;
import org.bukkit.conversations.*;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@aadnk
aadnk / REP.java
Created May 3, 2013 03:39
A read-eval print loop in Java using Rhino.
package com.comphenix.testing;
import java.io.PrintStream;
import java.util.Scanner;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class REP {
@aadnk
aadnk / Cooldowns.java
Last active September 11, 2024 07:04
A very simple cooldown library.
package com.comphenix.example;
import org.bukkit.entity.Player;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
public class Cooldowns {
private static Table<String, String, Long> cooldowns = HashBasedTable.create();