Skip to content

Instantly share code, notes, and snippets.

View DarkSeraphim's full-sized avatar

Mark Hendriks DarkSeraphim

View GitHub Profile
@DarkSeraphim
DarkSeraphim / KVTreeMap.java
Last active August 29, 2015 14:06
TreeMap that allows you to sort based on key AND value :3. Validate is for the gorgeous InvalidArgumentException, replacing them should be a breeze.
import lombok.Delegate;
import org.apache.commons.lang.Validate;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
@DarkSeraphim
DarkSeraphim / Facing.java
Created September 8, 2014 21:45
Function to acquire the BlockFace from the Location's yaw/pitch
public BlockFace getFacing(Location loc)
{
float pitch = loc.getPitch();
for(;pitch < 0; pitch += 360F);
pitch %= 360F;
int pitchdir = Math.round(pitch/90F) % 4;
switch(pitchdir)
{
case 1:
@DarkSeraphim
DarkSeraphim / ItemStackSerializerUtil.java
Created September 11, 2014 16:24
ItemStack serializer utility - with ease (why do it hard and sloppy anyway :P)
package net.darkseraphim.serialization;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.*;
import java.lang.reflect.Method;
import java.util.Map;
@DarkSeraphim
DarkSeraphim / config.json
Created September 12, 2014 18:05
ShareX for Linux config
{
# Here you can add multiple image uploaders
# They go in the format as shown below
# Btw I added a 'comment'
"apis":
[
# As JSON requires us to create a new 'object' each API
{
# A name is just a name for the GUI, all it should do
# is tell you where it will upload.
@DarkSeraphim
DarkSeraphim / InventoryUtil.java
Last active July 12, 2016 23:46
Utility to rename custom Bukkit inventories without opening a new inventory (only works with Inventories created by Bukkit.createInventory!)
package net.darkseraphim.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@DarkSeraphim
DarkSeraphim / Economy.java
Created September 20, 2014 10:52
Happy hour! Easily multiply Vault income through a single command
package net.darkseraphim.happyhour;
import net.milkbowl.vault.economy.EconomyResponse;
import java.util.List;
/**
* @author DarkSeraphim
*/
public class Economy implements net.milkbowl.vault.economy.Economy
@DarkSeraphim
DarkSeraphim / ActionBarExample.java
Last active November 5, 2015 16:07
Using the ActionBar in 1.8 MC clients (currently written for the Spigot protocol hack). Explanation here: http://www.spigotmc.org/threads/news-bar-over-the-hotbar.30394/#post-345167
package net.darkseraphim.actionbar;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import net.minecraft.server.v1_7_R4.EnumProtocol;
import net.minecraft.server.v1_7_R4.NetworkManager;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import net.minecraft.util.com.google.common.collect.BiMap;
import net.minecraft.util.io.netty.channel.Channel;
@DarkSeraphim
DarkSeraphim / WrappedArrayList.java
Created October 1, 2014 19:25
It's... so pwetty - forwarding the Iterator removal for wrapped object Lists to the unwrapped object variant
List<Trade> trades = new ArrayList<Trade>()
{
public Iterator<Trade> iterator()
{
final Iterator<Trade> s = super.iterator();
return new Iterator<Trade>()
{
private final List<?> nmsList = list;
private final Iterator<Trade> delegate = s;
@DarkSeraphim
DarkSeraphim / index.js
Created October 14, 2014 21:06
organized socket.io
var express = require('express');
// ...
var app = express();
// ...
var server = app.listen(80, function()
{
console.log("Listening on port ", (server.address().port));
});
// Early binding:
@DarkSeraphim
DarkSeraphim / Delaying Effect.POTION_BREAK.java
Created November 12, 2014 20:22
Not sure how well this would work, but it should when there are no manual effect triggers (so every effect should be triggered by an actual Potion entity)
// Check the thread. It might not be thread safe, in which case
// you should be fine with a Collections.synchronizedList() wrap
LinkedHashSet<PacketContainer> queue = new LinkedHashSet<PacketContainer>();
// Same for this, though ConcurrentHashMap instead of a HashMap
Map<PacketContainer, List<Player>> receivers = new HashMap<PacketContainer, List<Player>>();
private class ContainerWrapper
{
private final PacketContainer container;