Skip to content

Instantly share code, notes, and snippets.

View justisr's full-sized avatar
💭
Processing

Justis R justisr

💭
Processing
  • BuiltByBit
  • United States
View GitHub Profile
@justisr
justisr / EventProvider.java
Last active September 11, 2018 18:44
Quickly support all of your listeners in an efficient and reload safe way
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@justisr
justisr / UUIDProvider.java
Last active August 29, 2022 11:39
Get the real UUID from a player name. Requires internet connection.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@justisr
justisr / Rows.java
Created August 11, 2018 22:57
Enum to prevent illegal arguments when creating an inventory
/**
* A quick enum for getting the amount of slots in an inventory row.
* Used to prevent illegal arguments when creating an inventory.
*
* @author Justis
*
*/
public enum Rows {
@justisr
justisr / MathEval.java
Last active February 24, 2017 14:23
Evaluate algebraic equations from a string
// Created by Lawrence PC Dol. Released into the public domain.
// http://tech.dolhub.com
//
// Contributions by Carlos Gómez of Asturias, Spain, in the area of unary operators
// and right-to-left evaluations proved invaluable to implementing these features.
// Thanks Carlos!
//
// Source is licensed for any use, provided this copyright notice is retained.
// No warranty for any purpose whatsoever is implied or expressed. The author
//Created by Justis Root. Released into the public domain.
//https://gist.github.com/justisr
//
//Source is licensed for any use, provided that this copyright notice is retained.
//Modifications not expressly accepted by the author should be noted in the license of any forks.
//No warranty for any purpose whatsoever is implied or expressed,
//and the author shall not be held liable for any losses, direct or indirect as a result of using this software.
import java.io.File;
@justisr
justisr / TitleUpdater.java
Last active July 6, 2023 03:26
Update an inventory name while opened without NMS
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.gmail.justisroot.autoecon.data.ServerSpecs;
@justisr
justisr / PotionResults.java
Last active August 7, 2016 14:02
A single method util for getting the resulting potion from a potion brew
@EventHandler
public void brew(BrewEvent e) {
ItemStack[] contents = e.getContents().getContents();
for (int i = 2; i >= 0; i--) {
PotionType type = result(contents[i], contents[3]);
if (type == null) continue;
}
}
private static PotionType result(ItemStack potion, ItemStack ing) {
@justisr
justisr / BungeeCom.java
Last active April 14, 2021 20:37
Bungee communications wrapper util
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@justisr
justisr / Pane.java
Last active December 26, 2015 23:32
Simple stained glass pain enum for all the available colors.
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum Pane {
WHITE(0),
ORANGE(1),
LIGHT_PURPLE(2),
LIGHT_BLUE(3),
YELLOW(4),
LIGHT_GREEN(5),
@justisr
justisr / TimeUnit.java
Last active December 16, 2015 13:37
Convert a single number into a readable, formatted time stamp, and back again.
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public enum TimeUnit {
SEC("second", 1, 's'),
MIN("minute", 60, 'm'),
HOUR("hour", 3600, 'h'),