Skip to content

Instantly share code, notes, and snippets.

@Cryptite
Cryptite / ArenaPlayer.java
Last active December 20, 2015 22:38
ArenaPlayer class for Loka's custom Elo Rated Arena system
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@Cryptite
Cryptite / StringBlock.java
Created March 14, 2016 16:34
StringBlock utility class for storing Blocks safely
public class StringBlock extends StringLocation {
public Material material;
public Byte data;
public RegenerateType regenerateType = RegenerateType.READY;
public StringBlock(Block b, RegenerateType regenerateType) {
super(b.getLocation());
material = b.getType();
data = b.getData();
this.regenerateType = regenerateType;
@Cryptite
Cryptite / StringLocation.java
Last active November 11, 2017 15:20
StringLocation class for safely storing Location data
import com.sk89q.worldedit.Vector;
import org.bukkit.*;
import org.bukkit.block.Block;
import java.util.Objects;
import static org.bukkit.util.NumberConversions.square;
public class StringLocation {
public String world;
@Cryptite
Cryptite / StringChunk.java
Created November 11, 2017 15:19
StringChunk
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import java.util.Objects;
public class StringChunk {
public String world;
public int x, z;
public StringChunk(Chunk c) {
@Cryptite
Cryptite / HopperBurnout.java
Last active November 12, 2017 14:35
Hopper Burnout - Proof of Concept for turning off Hoppers when they try to move too many items
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
@Cryptite
Cryptite / ConfigFile.java
Created February 24, 2018 20:42
Threaded ConfigFile
package com.n9works.bukkit;
import com.google.common.collect.Iterables;
import com.n9works.bukkit.towns.Generator;
import com.n9works.bukkit.utils.StringLocation;
import com.n9works.bukkit.utils.blocks.StringBlock;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.configuration.PropertyConverter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@Cryptite
Cryptite / gist:e0f23aec3cbb5ab32c7b144f537bec8f
Created April 12, 2018 00:15
Spoof Health Packets with ProtocolLib
//Spoof Health Packets
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(plugin, ENTITY_METADATA) {
public void onPacketSending(PacketEvent event) {
try {
Player observer = event.getPlayer();
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
org.bukkit.entity.Entity entity = entityModifer.read(0);
if (entity != null && observer != entity && entity instanceof Player
&& (entity.getPassenger() == null || entity.getPassenger() != observer)) {
event.setPacket(event.getPacket().deepClone());
@Cryptite
Cryptite / CachedObject.java
Last active June 3, 2018 21:48
Cached Object - A very simple caching class that will use the supplied update function whenever dirty to refresh its value.
import java.util.function.Supplier;
public class CachedObject<T> {
private final Supplier<T> updateFunction;
private T cachedValue;
private boolean dirty = true;
public CachedObject(Supplier<T> updateFunction) {
this.updateFunction = updateFunction;
}
@Cryptite
Cryptite / BlockQueue.java
Last active February 24, 2019 15:09
Basic Queue which spreads out block changes over a series of ticks.
public class BlockQueue implements Runnable {
private final TheArtifact plugin;
private PriorityBlockingQueue<StringBlock> queue;
public BlockQueue(TheArtifact plugin) {
this.plugin = plugin;
queue = new PriorityBlockingQueue<>(20000, Comparator.comparing(o1 -> o1.priority));
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 0, 2);
}
@Cryptite
Cryptite / getEntitiesWithinRegion.java
Last active November 28, 2018 22:24
Get Entities in a Cuboid Region Async with PaperLib
public static void getEntitiesWithinRegion(Location p1, Location p2, Consumer<List<Entity>> entitiesConsumer) {
int minX = Math.min(p1.getBlockX(), p2.getBlockX()) >> 4;
int maxX = Math.max(p1.getBlockX(), p2.getBlockX()) >> 4;
int minZ = Math.min(p1.getBlockZ(), p2.getBlockZ()) >> 4;
int maxZ = Math.max(p1.getBlockZ(), p2.getBlockZ()) >> 4;
List<CompletableFuture> futures = new ArrayList<>();
List<Entity> entities = new ArrayList<>();
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {