Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Wood dumptruckman

View GitHub Profile
@dumptruckman
dumptruckman / snake_case.py
Created Nov 18, 2020
Python class decorator for accessing lowerCamelCase attributes using snake_case.
View snake_case.py
from typing import Any
def snake_to_camel(name):
components = name.split('_')
return components[0] + ''.join(x.title() for x in components[1:])
def snake_case_attrs(klass):
"""A class decorator that enables getting and setting of attributes with lowerCamelCase names using snake_case."""
View SpawnLocationSharable.java
public class SpawnLocationSharable {
public static final Sharable<Location> SPAWN_LOCATION = new Sharable.Builder<Location>("spawn_location", Location.class,
new SharableHandler<Location>() {
@Override
public void updateProfile(PlayerProfile profile, Player player) {
profile.set(SPAWN_LOCATION, getPlayerSpawnLocation(player));
}
@Override
@dumptruckman
dumptruckman / ImmutableBlockLocation.java
Created Jul 11, 2019
A simple immutable block Location replacement for Bukkit that lacks references to Bukkit objects.
View ImmutableBlockLocation.java
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.LinkedHashMap;
@dumptruckman
dumptruckman / DebugLogHandler.java
Last active Jun 17, 2020
A simple option for enabling debug logging in your Bukkit plugin,
View DebugLogHandler.java
/**
* Copyright 2019 dumptruckman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
@dumptruckman
dumptruckman / core.clj
Last active Jul 27, 2018
A0A0 interp clojure
View core.clj
(require '[clojure.string :as s])
(use 'clojure.zip)
(defn vectorize-program [code]
(let [t #(read-string (.substring % 1))]
(mapv #(mapv (juxt first t) (into [] (re-seq #"\w-?\d+" %)))
(s/split-lines code))))
(defn prep-code [code]
(down (vector-zip (vectorize-program code))))
@dumptruckman
dumptruckman / Interpreter.kt
Created Jul 26, 2018
A0A0 Interpreter in Kotlin
View Interpreter.kt
package com.dumptruckman.a0a0
import java.util.LinkedList
import java.util.Scanner
fun main(args: Array<String>) {
// Example usage with cat program
Interpreter.interpret("A0 A0\n" +
"A0 C3 G1 G1 A0\n" +
"A0 I0 V0 P0 A0\n" +
View Messages_en.properties
cmd.set.unknown_prop=''{0}'' is not a valid chest property!
@dumptruckman
dumptruckman / build.gradle
Last active Feb 2, 2018
Basic Bukkit Gradle script
View build.gradle
// You need this to create an "uberjar"
plugins {
id "com.github.johnrengelman.shadow" version "2.0.2"
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow' // also needed for "uberjar"
group 'xyz.yourdomain'
version '0.0.1'
@dumptruckman
dumptruckman / DelayedTaskManager.java
Created Jan 30, 2018
A lightweight framework for scheduling one-off tasks.
View DelayedTaskManager.java
import javax.annotation.Nullable;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class DelayedTaskManager implements Runnable {
private static final long PRECISION_CHECK_TIME_MS = 10000;
private final DelayedTaskStore taskStore;
private final DelayedTaskRunner taskRunner;
@dumptruckman
dumptruckman / InventoryBuilder.kt
Last active Nov 10, 2017
A DSL for building Bukkit Inventory objects in Kotlin
View InventoryBuilder.kt
/**
* Copyright 2017 Jeremy Wood
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
You can’t perform that action at this time.