diff options
author | Luck <git@lucko.me> | 2018-06-06 15:39:16 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2018-06-06 15:39:16 +0100 |
commit | 7d6808cbcfbb0f61f93e536d36968eeda5bd302c (patch) | |
tree | 3271db1ffa6e4d6c1fa5ea4ccc1335b1ac746f46 /sponge/src/main | |
parent | 38f0c12483e6eda79ca36dc829ef678a736d2cef (diff) | |
download | spark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.tar.gz spark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.tar.bz2 spark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.zip |
Convert to Gradle
Diffstat (limited to 'sponge/src/main')
3 files changed, 0 insertions, 208 deletions
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 deleted file mode 100644 index d81e8f5..0000000 --- a/sponge/src/main/java-templates/me/lucko/spark/sponge/utils/PomData.java +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index c6e1e18..0000000 --- a/sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java +++ /dev/null @@ -1,146 +0,0 @@ -package me.lucko.spark.sponge; - -import com.google.inject.Inject; - -import me.lucko.spark.common.CommandHandler; -import me.lucko.spark.profiler.ThreadDumper; -import me.lucko.spark.profiler.TickCounter; -import me.lucko.spark.sponge.utils.PomData; - -import org.spongepowered.api.Game; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.command.CommandCallable; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.entity.living.player.Player; -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.action.TextActions; -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.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import javax.annotation.Nullable; - -@Plugin( - id = "spark", - name = "spark", - version = "1.0.4", - description = PomData.DESCRIPTION, - authors = {"Luck", "sk89q"} -) -public class SparkSpongePlugin implements CommandCallable { - - private final CommandHandler<CommandSource> commandHandler = new CommandHandler<CommandSource>() { - private Text colorize(String message) { - return TextSerializers.FORMATTING_CODE.deserialize(message); - } - - private void broadcast(Text msg) { - Sponge.getServer().getConsole().sendMessage(msg); - for (Player player : Sponge.getServer().getOnlinePlayers()) { - if (player.hasPermission("spark.profiler")) { - player.sendMessage(msg); - } - } - } - - @Override - protected void sendMessage(CommandSource sender, String message) { - sender.sendMessage(colorize(message)); - } - - @Override - protected void sendMessage(String message) { - Text msg = colorize(message); - broadcast(msg); - } - - @Override - protected void sendLink(String url) { - try { - Text msg = Text.builder(url) - .color(TextColors.GRAY) - .onClick(TextActions.openUrl(new URL(url))) - .build(); - broadcast(msg); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - } - - @Override - protected void runAsync(Runnable r) { - asyncExecutor.execute(r); - } - - @Override - protected ThreadDumper getDefaultThreadDumper() { - return new ThreadDumper.Specific(new long[]{Thread.currentThread().getId()}); - } - - @Override - protected TickCounter newTickCounter() { - return new SpongeTickCounter(SparkSpongePlugin.this); - } - }; - - @Inject - @AsynchronousExecutor - private SpongeExecutorService asyncExecutor; - - @Inject - private Game game; - - @Listener - public void onServerStart(GameStartedServerEvent event) { - game.getCommandManager().register(this, this, "spark", "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."); - } -} diff --git a/sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java b/sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java deleted file mode 100644 index bda2a69..0000000 --- a/sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.lucko.spark.sponge; - -import me.lucko.spark.profiler.TickCounter; - -import org.spongepowered.api.scheduler.Task; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.LongAdder; - -public class SpongeTickCounter implements TickCounter, Runnable { - private final SparkSpongePlugin plugin; - private Task task; - - private final Set<Runnable> tasks = new HashSet<>(); - private final LongAdder tick = new LongAdder(); - - public SpongeTickCounter(SparkSpongePlugin plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - this.tick.increment(); - for (Runnable r : this.tasks){ - r.run(); - } - } - - @Override - public void start() { - this.task = Task.builder().intervalTicks(1).name("spark-ticker").execute(this).submit(this.plugin); - } - - @Override - public void close() { - this.task.cancel(); - } - - @Override - public long getCurrentTick() { - return this.tick.longValue(); - } - - @Override - public void addTickTask(Runnable runnable) { - this.tasks.add(runnable); - } - - @Override - public void removeTickTask(Runnable runnable) { - this.tasks.remove(runnable); - } -} |