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 / PbExample.java
Last active August 29, 2015 13:56
PluginBase usage example
public interface MyInterface { }
public class SomePlugin extends JavaPlugin implements MyInterface {
static {
SerializationRegistrar.registerClass(Config.class);
SerializationRegistrar.registerClass(Config.Time.class);
}
private JdbcAgent jdbcAgent;
public class PlayerDamageHistory {
public static PlayerDamageHistory createDamageHistory(String attacker) {
return new PlayerDamageHistory(attacker);
}
private final String attacker;
private final long time;
private PlayerDamageHistory(String attacker) {
@dumptruckman
dumptruckman / ArgumentJoiner.java
Last active December 21, 2015 17:59
A utility class that will take an array of string arguments and return an array where any arguments surrounded in quotes (single or double) are joined into single strings.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A utility which will join together arguments based on the use of quotations.
*/
public class ArgumentJoiner {
/**
@dumptruckman
dumptruckman / SingleWordFilter.java
Last active December 21, 2015 01:09
A method to create a regex string that will catch a given word hidden within non-alphanumeric characters.
public class SingleWordFilter {
private static final String OBSCURING_CHARACTERS_REGEX = "[\\W_]*";
public static SingleWorldFilter getSingleWordFilter(String singleWord) {
return new SingleWordFilter(singleWord);
}
private final String wordToFilter;
@dumptruckman
dumptruckman / TicksPerSecondTask.java
Created August 6, 2013 17:31
Calculates a rolling average for ticks per second.
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.text.DecimalFormat;
import java.util.LinkedList;
import java.util.ListIterator;
public class TicksPerSecondTask extends BukkitRunnable {
private static final long NUM_TICKS = 20L;
protected void checkGameEnd() {
Set<GamePlayer> onlinePlayers = getOnlinePlayers();
List<GamePlayer> onlineZombies = new LinkedList<GamePlayer>();
List<GamePlayer> onlineHumans = new LinkedList<GamePlayer>();
for (GamePlayer player : onlinePlayers) {
if (player.isZombie()) {
onlineZombies.add(player);
} else {
onlineHumans.add(player);
}
public abstract class QueryGen {
public abstract String createXTable();
public String selectPlayerData(String playerName) {
return "SELECT...";
}
}
public class MySqlQueryGen extends QueryGen {
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>non-aggregate</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
@dumptruckman
dumptruckman / InventoryTools.java
Created October 10, 2012 19:44
Useful tools for dealing with Bukkit Inventory objects.
/* Copyright (C) dumptruckman 2012
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@dumptruckman
dumptruckman / TestModeListener.java
Created July 31, 2012 20:43
A bukkit Listener for multi-boxing with same username. Useful for testing.
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;