diff options
author | Luck <git@lucko.me> | 2018-05-26 22:52:58 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2018-05-27 00:02:02 +0100 |
commit | 429eeb35876576d861404cd199b6e9763fc4e5b0 (patch) | |
tree | 624e1c05433e8ab5775a0177ecf5d5982de54805 /sponge | |
parent | 3fe5e5517b1c529d95cf9f43fd8420c66db0092a (diff) | |
download | spark-429eeb35876576d861404cd199b6e9763fc4e5b0.tar.gz spark-429eeb35876576d861404cd199b6e9763fc4e5b0.tar.bz2 spark-429eeb35876576d861404cd199b6e9763fc4e5b0.zip |
Initial commit for spark
Diffstat (limited to 'sponge')
-rw-r--r-- | sponge/pom.xml | 103 | ||||
-rw-r--r-- | sponge/src/main/java-templates/me/lucko/spark/sponge/utils/PomData.java | 8 | ||||
-rw-r--r-- | sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java | 97 |
3 files changed, 208 insertions, 0 deletions
diff --git a/sponge/pom.xml b/sponge/pom.xml new file mode 100644 index 0000000..44cfa6f --- /dev/null +++ b/sponge/pom.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>spark-parent</artifactId> + <groupId>me.lucko</groupId> + <version>1.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>spark-sponge</artifactId> + <packaging>jar</packaging> + + <build> + <defaultGoal>clean package</defaultGoal> + <finalName>spark-sponge</finalName> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${compiler.version}</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>${shade.version}</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <minimizeJar>false</minimizeJar> + <createDependencyReducedPom>false</createDependencyReducedPom> + <relocations> + <!-- shaded dependencies --> + <relocation> + <pattern>okio</pattern> + <shadedPattern>me.lucko.spark.lib.okio</shadedPattern> + </relocation> + <relocation> + <pattern>okhttp3</pattern> + <shadedPattern>me.lucko.spark.lib.okhttp3</shadedPattern> + </relocation> + </relocations> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>templating-maven-plugin</artifactId> + <version>1.0.0</version> + <executions> + <execution> + <id>filter-src</id> + <goals> + <goal>filter-sources</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <!-- common --> + <dependency> + <groupId>me.lucko</groupId> + <artifactId>spark-common</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <!-- Sponge --> + <dependency> + <groupId>org.spongepowered</groupId> + <artifactId>spongeapi</artifactId> + <version>8.0.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>sponge-repo</id> + <url>https://repo.spongepowered.org/maven</url> + </repository> + </repositories> + +</project> diff --git a/sponge/src/main/java-templates/me/lucko/spark/sponge/utils/PomData.java b/sponge/src/main/java-templates/me/lucko/spark/sponge/utils/PomData.java new file mode 100644 index 0000000..d81e8f5 --- /dev/null +++ b/sponge/src/main/java-templates/me/lucko/spark/sponge/utils/PomData.java @@ -0,0 +1,8 @@ +package me.lucko.spark.sponge.utils; + +public class PomData { + + public static final String DESCRIPTION = "${project.description}"; + public static final String VERSION = "${project.version}"; + +} diff --git a/sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java b/sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java new file mode 100644 index 0000000..b763549 --- /dev/null +++ b/sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java @@ -0,0 +1,97 @@ +package me.lucko.spark.sponge; + +import com.google.inject.Inject; + +import me.lucko.spark.common.CommandHandler; +import me.lucko.spark.sponge.utils.PomData; + +import org.spongepowered.api.Game; +import org.spongepowered.api.command.CommandCallable; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.game.state.GameStartedServerEvent; +import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.scheduler.AsynchronousExecutor; +import org.spongepowered.api.scheduler.SpongeExecutorService; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.format.TextColors; +import org.spongepowered.api.text.serializer.TextSerializers; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import javax.annotation.Nullable; + +@Plugin( + id = "spark", + name = "spark", + version = PomData.VERSION, + description = PomData.DESCRIPTION, + authors = {"Luck", "sk89q"} +) +public class SparkSpongePlugin implements CommandCallable { + + private final CommandHandler<CommandSource> commandHandler = new CommandHandler<CommandSource>() { + @Override + protected void sendMessage(CommandSource sender, String message) { + sender.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(message)); + } + + @Override + protected void runAsync(Runnable r) { + asyncExecutor.execute(r); + } + }; + + @Inject + @AsynchronousExecutor + private SpongeExecutorService asyncExecutor; + + @Inject + private Game game; + + @Listener + public void onServerStart(GameStartedServerEvent event) { + game.getCommandManager().register(this, this, "profiler"); + } + + @Override + public CommandResult process(CommandSource source, String arguments) { + if (!testPermission(source)) { + source.sendMessage(Text.builder("You do not have permission to use this command.").color(TextColors.RED).build()); + return CommandResult.empty(); + } + + commandHandler.handleCommand(source, arguments.split(" ")); + return CommandResult.empty(); + } + + @Override + public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) { + return Collections.emptyList(); + } + + @Override + public boolean testPermission(CommandSource source) { + return source.hasPermission("spark.profiler"); + } + + @Override + public Optional<Text> getShortDescription(CommandSource source) { + return Optional.of(Text.of("Main spark plugin command")); + } + + @Override + public Optional<Text> getHelp(CommandSource source) { + return Optional.of(Text.of("Run '/profiler' to view usage.")); + } + + @Override + public Text getUsage(CommandSource source) { + return Text.of("Run '/profiler' to view usage."); + } +} |