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 / Maze.java
Last active December 4, 2015 19:19
I don't even know what this is. :/ But I've got it.
public class Maze {
public static void main(String[] args){
int width = 100;
int height = 40;
Room[][] maze = new Maze().generateMaze(width, height);
for(int i = 0; i < width; i++){
System.out.print(" _");
@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'),
@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 / ActionBar.java
Last active August 7, 2016 13:49
Send messages to the player's action bar.
package com.justisroot.actionutil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public abstract class ActionBar {
public static Class<?> getNmsClass(String nmsClassName) throws ClassNotFoundException {
return Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "." + nmsClassName);
}
@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 / 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 / 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 / Unit.java
Created September 7, 2018 18:53
BigDecimal wrapper which prioritizes the re-use of existing instances and removes trailing zeros.
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ConcurrentMap;
import com.google.common.collect.MapMaker;
public class Unit {
private static ConcurrentMap<String, Unit> POOL = new MapMaker().weakValues().concurrencyLevel(1).initialCapacity(666).makeMap();
@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;