From c3f0818bcb505fb20f12df26e0d00d9532ce2ed5 Mon Sep 17 00:00:00 2001 From: Time6628 Date: Sun, 11 Dec 2016 20:03:49 -0500 Subject: [PATCH] Update 0.5: - Removing entities with commands will now display how many where removed - Configuration is finally done - Various other changes. --- ...radle__com_flowpowered_flow_math_1_0_2.xml | 11 - ...ing_configurate_configurate_core_3_1_1.xml | 11 - ...ing_configurate_configurate_gson_3_1_1.xml | 11 - ...ng_configurate_configurate_hocon_3_1_1.xml | 11 - ...ing_configurate_configurate_yaml_3_1_1.xml | 11 - ...epowered_event_gen_core_2_0_0_SNAPSHOT.xml | 9 - ...e__org_spongepowered_plugin_meta_0_1_1.xml | 11 - ...spongepowered_spongeapi_5_0_0_SNAPSHOT.xml | 11 - .idea/misc.xml | 12 +- .idea/modules/CatClearLag.iml | 2 +- .idea/modules/CatClearLag_main.iml | 20 +- .idea/modules/CatClearLag_test.iml | 20 +- .idea/workspace.xml | 741 ++++++++---------- build.gradle | 2 +- .../me/time6628/clag/sponge/CatClearLag.java | 121 ++- .../sponge/commands/RemoveAllCommand.java | 6 +- .../commands/RemoveHostilesCommand.java | 6 +- 17 files changed, 461 insertions(+), 555 deletions(-) delete mode 100644 .idea/libraries/Gradle__com_flowpowered_flow_math_1_0_2.xml delete mode 100644 .idea/libraries/Gradle__ninja_leaping_configurate_configurate_core_3_1_1.xml delete mode 100644 .idea/libraries/Gradle__ninja_leaping_configurate_configurate_gson_3_1_1.xml delete mode 100644 .idea/libraries/Gradle__ninja_leaping_configurate_configurate_hocon_3_1_1.xml delete mode 100644 .idea/libraries/Gradle__ninja_leaping_configurate_configurate_yaml_3_1_1.xml delete mode 100644 .idea/libraries/Gradle__org_spongepowered_event_gen_core_2_0_0_SNAPSHOT.xml delete mode 100644 .idea/libraries/Gradle__org_spongepowered_plugin_meta_0_1_1.xml delete mode 100644 .idea/libraries/Gradle__org_spongepowered_spongeapi_5_0_0_SNAPSHOT.xml diff --git a/.idea/libraries/Gradle__com_flowpowered_flow_math_1_0_2.xml b/.idea/libraries/Gradle__com_flowpowered_flow_math_1_0_2.xml deleted file mode 100644 index dd3101b..0000000 --- a/.idea/libraries/Gradle__com_flowpowered_flow_math_1_0_2.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_core_3_1_1.xml b/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_core_3_1_1.xml deleted file mode 100644 index ada8c35..0000000 --- a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_core_3_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_gson_3_1_1.xml b/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_gson_3_1_1.xml deleted file mode 100644 index 9252d0c..0000000 --- a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_gson_3_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_hocon_3_1_1.xml b/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_hocon_3_1_1.xml deleted file mode 100644 index 8914a29..0000000 --- a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_hocon_3_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_yaml_3_1_1.xml b/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_yaml_3_1_1.xml deleted file mode 100644 index f597225..0000000 --- a/.idea/libraries/Gradle__ninja_leaping_configurate_configurate_yaml_3_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_spongepowered_event_gen_core_2_0_0_SNAPSHOT.xml b/.idea/libraries/Gradle__org_spongepowered_event_gen_core_2_0_0_SNAPSHOT.xml deleted file mode 100644 index 3743d44..0000000 --- a/.idea/libraries/Gradle__org_spongepowered_event_gen_core_2_0_0_SNAPSHOT.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_spongepowered_plugin_meta_0_1_1.xml b/.idea/libraries/Gradle__org_spongepowered_plugin_meta_0_1_1.xml deleted file mode 100644 index b5d4381..0000000 --- a/.idea/libraries/Gradle__org_spongepowered_plugin_meta_0_1_1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_spongepowered_spongeapi_5_0_0_SNAPSHOT.xml b/.idea/libraries/Gradle__org_spongepowered_spongeapi_5_0_0_SNAPSHOT.xml deleted file mode 100644 index e26c7b8..0000000 --- a/.idea/libraries/Gradle__org_spongepowered_spongeapi_5_0_0_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3a99fa2..85dc194 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,17 +3,7 @@ - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/modules/CatClearLag.iml b/.idea/modules/CatClearLag.iml index cc93445..165cc1f 100644 --- a/.idea/modules/CatClearLag.iml +++ b/.idea/modules/CatClearLag.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/CatClearLag_main.iml b/.idea/modules/CatClearLag_main.iml index 84f43c2..03b4c61 100644 --- a/.idea/modules/CatClearLag_main.iml +++ b/.idea/modules/CatClearLag_main.iml @@ -1,5 +1,5 @@ - + @@ -9,25 +9,27 @@ - + - - - - - + + + + + + + - + - + \ No newline at end of file diff --git a/.idea/modules/CatClearLag_test.iml b/.idea/modules/CatClearLag_test.iml index bc5d6e4..7b6e2da 100644 --- a/.idea/modules/CatClearLag_test.iml +++ b/.idea/modules/CatClearLag_test.iml @@ -1,5 +1,5 @@ - + @@ -10,25 +10,27 @@ - + - - - - - + + + + + + + - + - + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9b966e3..e7eb78b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,24 @@ - - + + + + + + + + + + + + + + + @@ -54,20 +67,6 @@ - + - - - - - - - - - - - - - - + + - - + + + + + + @@ -143,8 +116,8 @@ - - + + @@ -154,56 +127,47 @@ - - - - + + - - + + - - - - - - - + + + - - + + - - - - - - + + + - - + + - - + + - - + + - - + + @@ -213,12 +177,8 @@ - - - - - - + + @@ -227,10 +187,8 @@ - - - - + + @@ -360,7 +318,7 @@ @@ -504,28 +463,11 @@ true DEFINITION_ORDER - - - - - - - - - - - - - + @@ -533,7 +475,7 @@ - + @@ -542,9 +484,6 @@ - - - @@ -552,6 +491,10 @@ @@ -562,6 +505,22 @@ + + + + + + + + @@ -588,6 +547,10 @@ + + @@ -653,10 +616,13 @@ + + + - + @@ -665,15 +631,17 @@ + + - - - - + + + + @@ -698,9 +666,10 @@ - + @@ -746,7 +716,11 @@ - - - - - - - - @@ -994,6 +948,12 @@ + + + + + + @@ -1030,36 +990,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1094,34 +1024,6 @@ - - - - - project @@ -1132,7 +1034,7 @@ - + @@ -1144,21 +1046,6 @@ - - - - - - - - - - - - - - - @@ -1167,9 +1054,36 @@ + + + - @@ -1202,7 +1116,12 @@ - + + + + + + 1469054265735 @@ -1281,34 +1200,59 @@ - - - - + + + + - + + - + - + + @@ -1319,6 +1263,9 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + @@ -1466,7 +1344,7 @@ - + @@ -1474,7 +1352,7 @@ - + @@ -1482,21 +1360,23 @@ - - - - - - + + - + + + + + + + @@ -1504,7 +1384,7 @@ - + @@ -1512,7 +1392,7 @@ - + @@ -1520,21 +1400,23 @@ - - - - - - + + - + + + + + + + @@ -1542,12 +1424,8 @@ - - - - - - + + @@ -1558,221 +1436,264 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + - - - + + - + - - - - - - - + + + - - - - + + - + - - - - - - - + + + - - + - - - - - + + + - + - - - - - - + + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle index f4fc0f6..9d944dd 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'java' sourceCompatibility = '1.8' targetCompatibility = '1.8' -version = '0.4.2' +version = '0.5' repositories { mavenCentral() diff --git a/src/main/java/me/time6628/clag/sponge/CatClearLag.java b/src/main/java/me/time6628/clag/sponge/CatClearLag.java index 647278c..ffeac7c 100644 --- a/src/main/java/me/time6628/clag/sponge/CatClearLag.java +++ b/src/main/java/me/time6628/clag/sponge/CatClearLag.java @@ -1,26 +1,41 @@ package me.time6628.clag.sponge; +import com.google.common.reflect.TypeToken; +import com.google.inject.Inject; import me.time6628.clag.sponge.commands.*; import me.time6628.clag.sponge.runnables.ItemClearer; import me.time6628.clag.sponge.runnables.ItemClearingWarning; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import org.slf4j.Logger; import org.spongepowered.api.Game; import org.spongepowered.api.Sponge; import org.spongepowered.api.command.spec.CommandSpec; +import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.Item; import org.spongepowered.api.entity.living.Hostile; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.game.state.GameInitializationEvent; +import org.spongepowered.api.event.game.state.GamePreInitializationEvent; import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.scheduler.Scheduler; import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.format.TextColors; +import org.spongepowered.api.text.serializer.TextSerializer; +import org.spongepowered.api.text.serializer.TextSerializerFactory; +import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.world.World; +import java.io.File; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; +import java.util.function.Function; /** * Created by TimeTheCat on 7/2/2016. @@ -28,37 +43,84 @@ @Plugin(name = "CatClearLag", id = "catclearlag", version = "0.4.2", description = "DIE LAG, DIE!") public class CatClearLag { - public static Logger cclLogger = Logger.getLogger("CCL"); - public Game game = Sponge.getGame(); + @Inject + static + org.slf4j.Logger logger; - private Scheduler scheduler = Sponge.getScheduler(); + //config stuff + private ConfigurationNode cfg; - public Text prefix = Text.builder().color(TextColors.DARK_PURPLE).append(Text.of("[KKMCClearLag] ")).build(); + @Inject + PluginContainer pluginContainer; + + @Inject + @DefaultConfig(sharedRoot = false) + private File defaultCfg; + + @Inject + @DefaultConfig(sharedRoot = false) + private ConfigurationLoader cfgMgr; + + @Inject + public Game game; + + @Inject + private Scheduler scheduler; + + public Text prefix; + + private int interval = 0; + private List warning; + + @Listener + public void onPreInit(GamePreInitializationEvent event) { + logger.info("Making config..."); + try { + if (!defaultCfg.exists()) { + defaultCfg.createNewFile(); + + this.cfg = getCfgMgr().load(); + + this.cfg.getNode("Version").setValue(0.1); + + this.cfg.getNode("interval").setValue(10); + this.cfg.getNode("warnings").setValue(Arrays.asList(new int[]{540, 570})); + this.cfg.getNode("prefix").setValue("&5[ClearLag]"); + getLogger().info("Config created."); + getCfgMgr().save(cfg); + } + + this.cfg = getCfgMgr().load(); + + this.prefix = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(cfg.getNode("prefix").getString()); + this.interval = cfg.getNode("interval").getInt(); + this.warning = cfg.getNode("warnings").getList(o -> (Integer) o); + + + } catch (Exception e) { + e.printStackTrace(); + } + } @Listener public void onInit(GameInitializationEvent event) { - CatClearLag.cclLogger.info("Starting plugin..."); + logger.info("Starting plugin..."); registerCommands(); //registerEvents(); Task.Builder builder = scheduler.createTaskBuilder(); Task task = builder.execute(new ItemClearer(this)) .async() .delay(10, TimeUnit.MINUTES) - .interval(10, TimeUnit.MINUTES) + .interval(interval, TimeUnit.MINUTES) .name("CatClearLag Item Remover") .submit(this); - Task warningTaskOne = builder.execute(new ItemClearingWarning(60, this)) - .async() - .delay(540, TimeUnit.SECONDS) - .interval(10, TimeUnit.MINUTES) - .name("CatClearLag Removal warning 1") - .submit(this); - Task warningTaskTwo = builder.execute(new ItemClearingWarning(30, this)) - .async() - .delay(570, TimeUnit.SECONDS) - .interval(10, TimeUnit.MINUTES) - .name("CatClearLag Removal warning 1") - .submit(this); + warning.forEach((d) -> + builder.execute(new ItemClearingWarning(((interval * 60) - d), this)) + .async() + .delay(d, TimeUnit.SECONDS) + .interval(interval, TimeUnit.MINUTES) + .name("CatClearLag Removal Warnings") + .submit(this)); } private void registerEvents() { @@ -67,7 +129,7 @@ private void registerEvents() { private void registerCommands() { - CatClearLag.cclLogger.info("Registering commands..."); + logger.info("Registering commands..."); CommandSpec cSpec = CommandSpec.builder() .description(Text.of("Remove all hostile entities from the server.")) @@ -111,7 +173,8 @@ public void clearGoundItems() { }); } - public void removeHostile() { + public Integer removeHostile() { + final int[] i = {0}; //get all worlds Collection worlds = Sponge.getServer().getWorlds(); //for each world @@ -122,12 +185,15 @@ public void removeHostile() { entities.forEach((entity) -> { if (entity instanceof Hostile && !entity.getType().getId().equals("minecraft:player")) { entity.remove(); + i[0]++; } }); }); + return i[0]; } - public void removeAll() { + public Integer removeAll() { + final int[] i = {0}; //get all the worlds Collection worlds = Sponge.getServer().getWorlds(); //for each world @@ -138,8 +204,19 @@ public void removeAll() { entities.forEach(entity -> { if (!entity.getType().getId().equals("minecraft:player")) { entity.remove(); + i[0]++; } }); }); + return i[0]; + } + + + public ConfigurationLoader getCfgMgr() { + return cfgMgr; + } + + public static Logger getLogger() { + return logger; } } \ No newline at end of file diff --git a/src/main/java/me/time6628/clag/sponge/commands/RemoveAllCommand.java b/src/main/java/me/time6628/clag/sponge/commands/RemoveAllCommand.java index 8b1f0db..bd32a51 100644 --- a/src/main/java/me/time6628/clag/sponge/commands/RemoveAllCommand.java +++ b/src/main/java/me/time6628/clag/sponge/commands/RemoveAllCommand.java @@ -21,8 +21,8 @@ public RemoveAllCommand(CatClearLag catClearLag) { @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of("Removing all entities...")).build()); - plugin.removeAll(); - src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of("All entities removed.")).build()); - return CommandResult.success(); + int affectedEnts = plugin.removeAll(); + src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of(affectedEnts + " entities removed.")).build()); + return CommandResult.builder().affectedEntities(affectedEnts).build(); } } diff --git a/src/main/java/me/time6628/clag/sponge/commands/RemoveHostilesCommand.java b/src/main/java/me/time6628/clag/sponge/commands/RemoveHostilesCommand.java index d8dc6dd..d4e78c4 100644 --- a/src/main/java/me/time6628/clag/sponge/commands/RemoveHostilesCommand.java +++ b/src/main/java/me/time6628/clag/sponge/commands/RemoveHostilesCommand.java @@ -21,8 +21,8 @@ public RemoveHostilesCommand(CatClearLag catClearLag) { @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of("Removing hostiles...")).build()); - plugin.removeHostile(); - src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of("Hostiles removed...")).build()); - return CommandResult.success(); + int affectedEnts = plugin.removeHostile(); + src.sendMessage(Text.builder().append(plugin.prefix).color(TextColors.LIGHT_PURPLE).append(Text.of(affectedEnts + "hostiles removed...")).build()); + return CommandResult.builder().affectedEntities(affectedEnts).build(); } }