Skip to content

Instantly share code, notes, and snippets.

@HaedHutner
HaedHutner / DummyQuest.kt
Created April 8, 2018 08:15
Improved Kotlin API
class DummyQuest {
class Simple() : SimpleQuest("simpleDummyQuest", 1) {
init {
this name Text.of("Dummy Quest")
this description Text.of("A dummy quest to prove that SimpleQuest works. Kill some things, reach a point, and get a magical anvil!")
val world = Sponge.getServer().getWorld(Sponge.getServer().defaultWorldName)
package com.atherys.addon
import com.atherys.quests.quest.SimpleQuest
import com.atherys.quests.quest.Stage
import com.atherys.quests.quest.StagedQuest
import com.atherys.quests.quest.objective.Objectives
import com.atherys.quests.quest.requirement.Requirements
import com.atherys.quests.quest.reward.Rewards
import com.atherys.quests.quester.Quester
import com.flowpowered.math.vector.Vector3d
@Listener
public void onKeyRegistration( GameRegistryEvent.Register<Key<?>> event ) {
QuestKeys.DIALOG = Key.builder()
.type( new TypeToken<Value<String>>() {} )
.id( "dialog" )
.name( "Dialog" )
.query( DataQuery.of( "atherysquests", "Dialog" ) )
.build();
}
@HaedHutner
HaedHutner / AbstractConfigurateAdapter.java
Created March 19, 2018 15:43
Abstract Gson TypeAdapter for Configurate + Implementation class
public abstract class AbstractConfigurateAdapter<T> extends TypeAdapter<T> {
private Class<T> clazz;
private JsonParser parser = new JsonParser();
protected AbstractConfigurateAdapter ( Class<T> clazz ) {
this.clazz = clazz;
}
@HaedHutner
HaedHutner / Main.java
Last active January 28, 2018 12:15
Method for solving De Casteljau's Algorithm using Java
import java.util.Arrays;
public class Main {
private static Point2D[] points = {
Point2D.of( 0.0, 4.0),
Point2D.of( 4.0, 0.0),
Point2D.of(-4.0, -4.0),
Point2D.of(-4.0, 0.0)
};
@HaedHutner
HaedHutner / YourPlugin.java
Last active January 18, 2018 18:37
[Sponge] Boilerplate code for starting a new Sponge plugin.
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartingServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin;
@Plugin( id = YourPlugin.ID, name = YourPlugin.NAME, description = YourPlugin.DESCRIPTION, version = YourPlugin.VERSION )
@HaedHutner
HaedHutner / ExampleConfig.java
Last active March 3, 2018 14:04
[Configurate/Sponge] An abstract utility class for creating quick and simple HOCON configuration classes using an object mapper with a Sponge GameInitializationEvent Listener as an example.
public final class ExampleConfig extends PluginConfig {
@Setting( value = "defaultConfig", comment = "Whether or not this is the default config. If this is set to true, the plugin will not start.")
public boolean DEFAULT = true;
@Setting( value = "database" )
public DatabaseConfig DATABASE = new DatabaseConfig();
@ConfigSerializable
public static class DatabaseConfig {
@HaedHutner
HaedHutner / Question.java
Last active December 17, 2017 14:02
[Sponge] A small utility class for polling players with a question.
/**
* A utility for polling players with arbitrary questions, and offering an arbitrary amount of answers with various actions attached.<br>
* The questions may be sent to the player either in the form of a chat message ( {@link #pollChat(Player)} ),
* a book view ( {@link #pollBook(Player)} ),
* or a combination of the two in the form of a chat-based view button ( {@link #pollViewButton(Player, Text)} ).
*/
public class Question {
public static Text QUESTION_DECORATION_TOP = Text.of(TextColors.DARK_AQUA, "{", TextColors.AQUA, "Question", TextColors.DARK_AQUA, "}\n");
public static Text QUESTION_DECORATION_BOT = Text.of(TextColors.DARK_AQUA, "\n");