From e41d4e507c356811971b8c2c97e85a7e47e647fb Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 2 May 2017 21:41:38 -0400 Subject: [PATCH] v.0.5.0: Move Timings Impl to external lib, resolve Timings v2 Paper 1.8 support This likely wouldn't of broke anyones code, only if they used the Timings method in ACFUtil, but bumping just to be 'good' since it is an API break. If you did not use the Timings in ACFUtil, then you can just bump the version without breakages. Timings is now handled over at https://github.com/aikar/minecraft-timings --- acf.iml | 1 + example/acf-example.iml | 1 + example/pom.xml | 2 +- pom.xml | 7 ++- src/main/java/co/aikar/commands/ACFUtil.java | 39 +--------------- .../java/co/aikar/commands/BaseCommand.java | 1 + .../aikar/commands/BukkitCommandManager.java | 8 ++++ .../co/aikar/commands/CommandManager.java | 5 +- .../java/co/aikar/commands/CommandTiming.java | 34 -------------- .../java/co/aikar/commands/EmptyTiming.java | 40 ---------------- .../co/aikar/commands/MinecraftTiming.java | 46 ------------------- .../co/aikar/commands/RegisteredCommand.java | 3 +- .../java/co/aikar/commands/SpigotTiming.java | 46 ------------------- 13 files changed, 24 insertions(+), 209 deletions(-) delete mode 100644 src/main/java/co/aikar/commands/CommandTiming.java delete mode 100644 src/main/java/co/aikar/commands/EmptyTiming.java delete mode 100644 src/main/java/co/aikar/commands/MinecraftTiming.java delete mode 100644 src/main/java/co/aikar/commands/SpigotTiming.java diff --git a/acf.iml b/acf.iml index 893e318a..0847f3b4 100644 --- a/acf.iml +++ b/acf.iml @@ -21,6 +21,7 @@ + diff --git a/example/acf-example.iml b/example/acf-example.iml index c4d04c3e..44c4c304 100644 --- a/example/acf-example.iml +++ b/example/acf-example.iml @@ -36,5 +36,6 @@ + \ No newline at end of file diff --git a/example/pom.xml b/example/pom.xml index 1574d376..28c66486 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -111,7 +111,7 @@ co.aikar acf-core - 0.3.0-SNAPSHOT + 0.5.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 99f4ee17..a4aecfef 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ co.aikar acf-core - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT ACF @@ -101,6 +101,11 @@ annotations 13.0 + + co.aikar + minecraft-timings + 1.0.0 + com.destroystokyo.paper paper-api diff --git a/src/main/java/co/aikar/commands/ACFUtil.java b/src/main/java/co/aikar/commands/ACFUtil.java index 2d13024b..a7e9e993 100644 --- a/src/main/java/co/aikar/commands/ACFUtil.java +++ b/src/main/java/co/aikar/commands/ACFUtil.java @@ -23,6 +23,7 @@ package co.aikar.commands; +import co.aikar.timings.lib.CommandTiming; import com.google.common.collect.Iterables; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.WordUtils; @@ -862,45 +863,7 @@ public final class ACFUtil { throw (T) t; } - static TimingType timingProvider; - public static synchronized CommandTiming getTiming(BaseCommand cmd, String command) { - if (timingProvider == null) { - try { - Class.forName("co.aikar.timings.Timing"); - timingProvider = TimingType.MINECRAFT; - } catch (ClassNotFoundException ignored1) { - try { - Class.forName("org.spigotmc.CustomTimingsHandler"); - timingProvider = TimingType.SPIGOT; - } catch (ClassNotFoundException ignored2) { - timingProvider = TimingType.EMPTY; - } - } - } - return timingProvider.newTiming(cmd, command); - } - static boolean isValidItem(ItemStack item) { return item != null && item.getType() != Material.AIR && item.getAmount() > 0; } - - private enum TimingType { - SPIGOT() { - @Override - CommandTiming newTiming(BaseCommand cmd, String command) { - return new SpigotTiming(command); - } - }, - MINECRAFT() { - @Override - CommandTiming newTiming(BaseCommand cmd, String command) { - return new MinecraftTiming(cmd, command); - } - }, - EMPTY(); - - CommandTiming newTiming(BaseCommand cmd, String command) { - return new EmptyTiming(); - } - } } diff --git a/src/main/java/co/aikar/commands/BaseCommand.java b/src/main/java/co/aikar/commands/BaseCommand.java index 0fbac19f..6c993b5e 100644 --- a/src/main/java/co/aikar/commands/BaseCommand.java +++ b/src/main/java/co/aikar/commands/BaseCommand.java @@ -27,6 +27,7 @@ import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Subcommand; +import co.aikar.timings.lib.CommandTiming; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; diff --git a/src/main/java/co/aikar/commands/BukkitCommandManager.java b/src/main/java/co/aikar/commands/BukkitCommandManager.java index 22c27e40..7521c9dc 100644 --- a/src/main/java/co/aikar/commands/BukkitCommandManager.java +++ b/src/main/java/co/aikar/commands/BukkitCommandManager.java @@ -23,6 +23,7 @@ package co.aikar.commands; +import co.aikar.timings.lib.TimingManager; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; @@ -42,6 +43,7 @@ public class BukkitCommandManager implements CommandManager { @SuppressWarnings("WeakerAccess") protected final Plugin plugin; private final CommandMap commandMap; + private final TimingManager timingManager; protected Map knownCommands = new HashMap<>(); protected Map registeredCommands = new HashMap<>(); protected CommandContexts contexts; @@ -49,6 +51,7 @@ public class BukkitCommandManager implements CommandManager { public BukkitCommandManager(Plugin plugin) { this.plugin = plugin; + this.timingManager = TimingManager.of(plugin); CommandMap commandMap = null; try { Server server = Bukkit.getServer(); @@ -144,4 +147,9 @@ public class BukkitCommandManager implements CommandManager { unregisterCommands(); } } + + @Override + public TimingManager getTimings() { + return timingManager; + } } diff --git a/src/main/java/co/aikar/commands/CommandManager.java b/src/main/java/co/aikar/commands/CommandManager.java index 5b9efb85..afcb9d8e 100644 --- a/src/main/java/co/aikar/commands/CommandManager.java +++ b/src/main/java/co/aikar/commands/CommandManager.java @@ -23,10 +23,9 @@ package co.aikar.commands; +import co.aikar.timings.lib.TimingManager; import org.bukkit.plugin.Plugin; -import java.util.Map; - public interface CommandManager { Plugin getPlugin(); @@ -50,4 +49,6 @@ public interface CommandManager { * @return boolean */ boolean registerCommand(BaseCommand command); + + TimingManager getTimings(); } diff --git a/src/main/java/co/aikar/commands/CommandTiming.java b/src/main/java/co/aikar/commands/CommandTiming.java deleted file mode 100644 index 3920dc83..00000000 --- a/src/main/java/co/aikar/commands/CommandTiming.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -interface CommandTiming extends AutoCloseable { - CommandTiming startTiming(); - void stopTiming(); - - @Override - default void close() { - stopTiming(); - } -} diff --git a/src/main/java/co/aikar/commands/EmptyTiming.java b/src/main/java/co/aikar/commands/EmptyTiming.java deleted file mode 100644 index 9fd4cdeb..00000000 --- a/src/main/java/co/aikar/commands/EmptyTiming.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -class EmptyTiming implements CommandTiming { - EmptyTiming() { - super(); - } - - @Override - public final CommandTiming startTiming() { - return this; - } - - @Override - public final void stopTiming() { - - } -} diff --git a/src/main/java/co/aikar/commands/MinecraftTiming.java b/src/main/java/co/aikar/commands/MinecraftTiming.java deleted file mode 100644 index 3d818234..00000000 --- a/src/main/java/co/aikar/commands/MinecraftTiming.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -import co.aikar.timings.Timing; -import co.aikar.timings.Timings; - -class MinecraftTiming implements CommandTiming { - private final Timing timing; - MinecraftTiming(BaseCommand command, String name) { - super(); - this.timing = Timings.of(command.manager.getPlugin(), name); - } - - @Override - public CommandTiming startTiming() { - timing.startTiming(); - return this; - } - - @Override - public void stopTiming() { - timing.stopTiming(); - } -} diff --git a/src/main/java/co/aikar/commands/RegisteredCommand.java b/src/main/java/co/aikar/commands/RegisteredCommand.java index c678caa6..43f30f70 100644 --- a/src/main/java/co/aikar/commands/RegisteredCommand.java +++ b/src/main/java/co/aikar/commands/RegisteredCommand.java @@ -32,6 +32,7 @@ import co.aikar.commands.annotation.Syntax; import co.aikar.commands.annotation.Values; import co.aikar.commands.contexts.ContextResolver; import co.aikar.commands.contexts.SenderAwareContextResolver; +import co.aikar.timings.lib.CommandTiming; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -208,7 +209,7 @@ public class RegisteredCommand { CommandTiming getTiming() { if (this.timing == null) { - this.timing = ACFUtil.getTiming(scope, command); + this.timing = scope.manager.getTimings().of("Command: " + command); } return this.timing; } diff --git a/src/main/java/co/aikar/commands/SpigotTiming.java b/src/main/java/co/aikar/commands/SpigotTiming.java deleted file mode 100644 index 8141c4c8..00000000 --- a/src/main/java/co/aikar/commands/SpigotTiming.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -import org.spigotmc.CustomTimingsHandler; - -class SpigotTiming implements CommandTiming { - private final CustomTimingsHandler timing; - - SpigotTiming(String name) { - super(); - this.timing = new CustomTimingsHandler(name); - } - - @Override - public CommandTiming startTiming() { - timing.startTiming(); - return this; - } - - @Override - public void stopTiming() { - timing.stopTiming(); - } -}