Skip to content

Instantly share code, notes, and snippets.

View WesJD's full-sized avatar

Wesley Smith WesJD

View GitHub Profile
@WesJD
WesJD / MainThreadExecutor.java
Created December 30, 2015 23:25
Execute things on the main thread easily.
public abstract class MainThreadExecutor {
public MainThreadExecutor() {
MinecraftServer.getServer().processQueue.add(new Runnable() {
@Override
public void run() {
call();
}
});
}
@WesJD
WesJD / Properties.java
Last active March 13, 2021 22:31
Simple class for changing Minecraft server properties easily.
public class Properties {
public static void savePropertiesFile() {
((DedicatedServer) MinecraftServer.getServer()).propertyManager.savePropertiesFile();
}
public static void setServerProperty(ServerProperty property, Object value) {
((DedicatedServer) MinecraftServer.getServer()).propertyManager.setProperty(property.getPropertyName(), value);
}
@WesJD
WesJD / Logging.java
Created March 12, 2016 02:29
Easy logging.
public class Logging {
private static final String PREFIX = "MyPrefix";
public static void logStatistic(String message) {
logWithExtra("Statistic", message);
}
public static void logDebug(String message) {
logWithExtra("Debug", message);
@WesJD
WesJD / Announcer.java
Created March 29, 2016 01:53
Easy announcements.
public class Announcer {
private final String[] announcements;
private final int secondsBetween;
private BukkitTask announcementTask;
public Announcer(int secondsBetween, String... announcements) {
this.secondsBetween = secondsBetween;
this.announcements = announcements;
@WesJD
WesJD / AbstractInventory.java
Last active November 8, 2016 16:05
Really easy Bukkit inventories.
public abstract class AbstractInventory {
private static final String SERVER_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
private static Method handleInventoryCloseEvent;
private static Method getHandle;
private static Field defaultContainer;
private static Field activeContainer;
static {
@WesJD
WesJD / delete_screen.sh
Created May 7, 2016 15:25
Delete screen sessions with ease.
echo "----------- [ DELETE SCREEN SESSION ] -----------"
screen -ls
read -p "Please supply the screen id you would like to delete: " id
read -p "Are you sure you want to delete screen $id? [y/N]: " des
if [[ $des =~ [yY](es)* ]]
then
echo "Deleting...."
screen -S $id -p 0 -X quit
echo "Done!"
fi
@WesJD
WesJD / spigot-install-file.sh
Last active March 20, 2019 02:10
Useful for AnvilGUI and its dependencies.
read -p "What is the file path? " path
read -p "What is the groupId? " groupId
read -p "What is the artifactId? " artifactId
read -p "What is the version? " version
mvn install:install-file -Dfile=$path -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=jar -DgeneratePom=true
@WesJD
WesJD / AbstractInventory4j8.java
Last active November 8, 2016 16:03
AbstractInventory that uses Java 8 BiConsumers rather than it's own Button class
public abstract class AbstractInventory {
private static final String SERVER_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
private static Method handleInventoryCloseEvent;
private static Method getHandle;
private static Field defaultContainer;
private static Field activeContainer;
static {
@WesJD
WesJD / InstanceManager.java
Last active August 8, 2016 00:49
Dynamic instance manager with Reflections
public class InstanceManager<T> {
private final List<T> instances = new ArrayList<>();
public InstanceManager(Class<T> superclass, String packageSearch) {
new Reflections(packageSearch).getSubTypesOf(superclass).forEach(clazz -> {
try {
instances.add(clazz.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
@WesJD
WesJD / RandomTeleporter.java
Created August 3, 2016 03:27
Teleport players to random locations with efficiency from Guava
public class RandomTeleporter {
private final LoadingCache<Pair<Location, Location>, List<Pair<Integer, Integer>>> locationCache = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.maximumSize(5)
.build(new CacheLoader<Pair<Location, Location>, List<Pair<Integer, Integer>>>() {
@Override
public List<Pair<Integer, Integer>> load(Pair<Location, Location> bounds) throws Exception {
final List<Pair<Integer, Integer>> ret = new ArrayList<>();
final Location bounds1 = bounds.getLeft();