Skip to content

Instantly share code, notes, and snippets.

View dumptruckman's full-sized avatar
💭
I may be slow to respond.

Jeremy Wood dumptruckman

💭
I may be slow to respond.
View GitHub Profile
@dumptruckman
dumptruckman / snake_case.py
Created November 18, 2020 17:43
Python class decorator for accessing lowerCamelCase attributes using snake_case.
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."""
@dumptruckman
dumptruckman / SpawnLocationSharable.java
Created August 16, 2019 06:17
Spawn Location Sharable
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 July 11, 2019 19:22
A simple immutable block Location replacement for Bukkit that lacks references to Bukkit objects.
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 April 25, 2022 06:40
A simple option for enabling debug logging in your Bukkit plugin,
/**
* 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 July 27, 2018 23:48
A0A0 interp clojure
(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 July 26, 2018 23:41
A0A0 Interpreter in Kotlin
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" +
cmd.set.unknown_prop=''{0}'' is not a valid chest property!
@dumptruckman
dumptruckman / build.gradle
Last active February 2, 2018 04:44
Basic Bukkit Gradle script
// 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 January 30, 2018 21:28
A lightweight framework for scheduling one-off tasks.
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 November 10, 2017 22:01
A DSL for building Bukkit Inventory objects in Kotlin
/**
* 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.