Skip to content

Instantly share code, notes, and snippets.

View A248's full-sized avatar
💭
Nonblocking is worth the effort

A248 🇵🇸 A248

💭
Nonblocking is worth the effort
  • Washington, D.C.
View GitHub Profile

Synchronised. You probably hear that word a lot. However, be careful, because it can mean different things depending on the context.

First, "synchronized" is a Java keyword, which relates to "synchronized blocks." This is what online tutorials will tell you about and it is mostly what synchronized means in Java. The synchronised keyword is a means of achieving mutual exclusion, that is, preventing concurrent access to shared data.

Second, "synchronised" can refer to a "main thread." In this regard, "synchronise to the main thread" and "execute a synchronised task" both mean "execute a task on the main thread".

Third, "sync" means "synchronised" - sync is just an abbreviation of synchronised. However, in casual Bukkit speak, "sync" also means "on the main thread." To run something "sync" means to run it on the main thread, to run something "async" means off the main thread.

@A248
A248 / Using JDBC.md
Last active October 31, 2020 18:12

This is a basic tutorial intended to showcase best practices for connecting to a SQL database. It will not tell you everything, but it is a good start.

Another assumption is that you will be using HikariCP. A connection pooling library will handle recreating Connections for you in a proper manner, while respecting network timeouts and max lifetime settings.

Setup the HikariDataSource

First make a class to wrap your HikariDataSource:

Using CompletableFuture

CompletableFuture is a plain Java class. It represents the result of an asynchronous computation. A future object is something which will become attainable in the future. When the asynchronous computation finishes, the future is completed.

Introduced in Java 8, CompletableFuture implements the older Future and adds support for callbacks, mapping operations, and cleaner awaiting of completion. If you are using Java 9 or later, you can also use delays and timeouts, subclass CompletableFuture to change the default executor, and take advantage of more utility methods.

Callbacks and operations

What are callbacks?

@A248
A248 / Velocity-Docs_creating_your_first_plugin.md
Last active July 17, 2020 22:17
Ported Velocity documentation to markdown

Creating Your First Plugin

So you've decided to take the plunge and create your first Velocity plugin? That's awesome! This page will help you get you going

Set up your environment

You're going to need the JDK and an IDE

I know how to do this. Give me what I need!

@A248
A248 / getServer.getPluginCommand-bad.md
Last active June 26, 2020 17:21
Plugin Developers: Don't use Server#getPluginCommand

Registering commands in the Bukkit API is one of the most basic things plugin developers do. The procedure is fairly straightforward: add the command in the plugin.yml, set the executor, implement the command.

However, if you are not careful, you might end up registering your executors in the wrong way. There are a few ways you might see this done:

plugin.getCommand("cmd").setExecutor(new CmdExecutor());

plugin.getServer().getPluginCommand("cmd").setExecutor(new CmdExecutor());
@A248
A248 / reload_command_DontUseIt.md
Last active June 19, 2020 23:45
Don't use /reload. Just don't do it. Forget about it. Restart the server instead.

One of the most common problems beginners run into is that of /reload. New server owners will use the command thinking that it will simply reload all of their plugins, cleanly and nicely. The lure of /reload is enticing – it offers to reload plugins without having to restart the server. Particularly on servers with long startup times, reloading with /reload appears a useful shortcut.

But it is actually one of the most dangerous commands known to Minecraft.

A Peculiar Case

A user on discord, jiggey, once came to me on a support channel for a plugin I was helping out with.

@A248
A248 / QuickPerms.sk
Created April 22, 2020 23:49
A simple Skript script to make permissions faster using LuckPerms
Command /user [<text>] [<text>] [<text>]:
Executable by: console
Trigger:
if arg 2 != "add":
if arg 2 != "remove":
send "&6Arim>> &cUsage: /user &e<player> <add|remove> <group>&c."
stop
execute console command "/lp user %arg 1% parent %arg 2% %arg 3%"
Command /group [<text>] [<text>] [<text>] [<text>]:
@A248
A248 / Minecraft Servers: Managing Permissions.md
Last active May 3, 2024 14:42
What are permissions in Minecraft? How do I use them on Spigot, BungeeCord, or Sponge?

Introduction

You probably know you can give yourself and your friends OP status on your server. OPs can use any commands; they can change gamemodes, broadcast messages, and generally do whatever is possible with the plugins you have installed. They're basically super-administrators, with no checks on their capabilities.

If you're only running a small server for friends, using OP is perfectly fine. If you only give OP to trusted friends, it's all fine.

@A248
A248 / NamelessManualUpdater_v2.0.0-pr6.sh
Last active January 6, 2020 18:04
Manual updater script for NamelessMC v2.0.0-pr6 -> v2.0.0-pr7
#!/bin/bash
OUTPUT_FILE="NamelessManualUpdater_v2.0.0-pr6.txt"
printf "\n"
echo -n "NamelessMC Manual Updater by A248"
printf "\n\n\n"
echo "This script will generate a series of queries for you to execute on your MySQL database. You will have to login using \"mysql -u root -p\" or similar. You should copy and paste the statements in the output file, $OUTPUT_FILE, and execute them."
printf "\n\n\n"
echo -n "Version 2.0.0pr6 -> 2.0.0pr7"