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
This commit is contained in:
Aikar
2017-05-02 21:41:38 -04:00
parent 3936556e1b
commit e41d4e507c
13 changed files with 24 additions and 209 deletions
+1
View File
@@ -21,6 +21,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: co.aikar:minecraft-timings:1.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.11.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
+1
View File
@@ -36,5 +36,6 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-all:5.0.4" level="project" />
<orderEntry type="module" module-name="acf" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: co.aikar:minecraft-timings:1.0.0" level="project" />
</component>
</module>
+1 -1
View File
@@ -111,7 +111,7 @@
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-core</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
+6 -1
View File
@@ -29,7 +29,7 @@
<groupId>co.aikar</groupId>
<artifactId>acf-core</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<name>ACF</name>
@@ -101,6 +101,11 @@
<artifactId>annotations</artifactId>
<version>13.0</version>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>minecraft-timings</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
+1 -38
View File
@@ -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();
}
}
}
@@ -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;
@@ -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<String, Command> knownCommands = new HashMap<>();
protected Map<String, BaseCommand> 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;
}
}
@@ -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();
}
@@ -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();
}
}
@@ -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() {
}
}
@@ -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();
}
}
@@ -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;
}
@@ -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();
}
}