From 88bb2b68de332ffe005a430e19b43595f79b7dea Mon Sep 17 00:00:00 2001 From: Lauriichan Date: Sat, 23 Dec 2023 04:21:45 +0100 Subject: [PATCH] Cleanup --- .../annotation/MCVersionEnumGenerator.java | 202 ++++++------------ .../annotation/SupportedVersions.java | 2 +- .../command/commands/ToggleCommand.java | 4 +- .../compatibility/CompatibilityHandler.java | 17 +- .../IncompatiblePluginException.java | 3 +- .../factionsuuid/FactionsUUID.java | 9 +- .../FactionsUUIDChopListener.java | 25 +-- .../jobsreborn/JobsRebornConfig.java | 2 +- .../logblock/LogBlockDatabaseAccessor.java | 2 +- .../mcmmo/McMmoChopListener.java | 2 +- .../residence/ResidenceChopListener.java | 2 +- .../listener/BlockBreakListener.java | 16 +- .../smoothtimber/platform/FoliaPlatform.java | 43 ++-- .../smoothtimber/platform/Platform.java | 13 +- .../smoothtimber/platform/SpigotPlatform.java | 16 +- .../smoothtimber/toggle/ToggledUser.java | 6 +- .../smoothtimber/utilities/PluginUtils.java | 1 - .../version/changer/v1_20xChanger.java | 2 +- 18 files changed, 153 insertions(+), 214 deletions(-) diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/MCVersionEnumGenerator.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/MCVersionEnumGenerator.java index 000786c..9fd6b9b 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/MCVersionEnumGenerator.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/MCVersionEnumGenerator.java @@ -19,13 +19,12 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileObject; import org.jboss.forge.roaster.Roaster; import org.jboss.forge.roaster.model.source.EnumConstantSource; import org.jboss.forge.roaster.model.source.JavaEnumSource; -import javax.tools.JavaFileObject; - import com.syntaxphoenix.syntaxapi.version.DefaultVersion; import com.syntaxphoenix.syntaxapi.version.Version; import com.syntaxphoenix.syntaxapi.version.VersionAnalyzer; @@ -52,28 +51,28 @@ public Set getSupportedAnnotationTypes() { } @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { + public boolean process(final Set annotations, final RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return false; } - HashMap> map = new HashMap<>(); - ArrayList types = new ArrayList<>(); - - VersionAnalyzer analyzer = new DefaultVersion().getAnalyzer(); + final HashMap> map = new HashMap<>(); + final ArrayList types = new ArrayList<>(); + + final VersionAnalyzer analyzer = new DefaultVersion().getAnalyzer(); for (final Element element : roundEnv.getElementsAnnotatedWith(SupportedVersions.class)) { if (element.getKind() != ElementKind.CLASS) { continue; } - String typeName = element.asType().toString(); + final String typeName = element.asType().toString(); if (types.contains(typeName)) { continue; } - SupportedVersions versionsSupported = element.getAnnotation(SupportedVersions.class); + final SupportedVersions versionsSupported = element.getAnnotation(SupportedVersions.class); types.add(typeName); - ArrayList versions = new ArrayList<>(); + final ArrayList versions = new ArrayList<>(); map.put(typeName, versions); - for (String supported : versionsSupported.value()) { - Version version = analyzer.analyze(supported); + for (final String supported : versionsSupported.value()) { + final Version version = analyzer.analyze(supported); if (version.getMajor() == 0) { messager.printMessage(Kind.WARNING, format("Failed to parse version '%s' of type '%s'", supported, typeName), element); continue; @@ -81,18 +80,18 @@ public boolean process(Set annotations, RoundEnvironment versions.add(analyzer.analyze(supported)); } } - + types.sort((t1, t2) -> { - ArrayList v1 = map.get(t1); - ArrayList v2 = map.get(t2); - int comp = Boolean.compare(v1.isEmpty(), v2.isEmpty()); + final ArrayList v1 = map.get(t1); + final ArrayList v2 = map.get(t2); + final int comp = Boolean.compare(v1.isEmpty(), v2.isEmpty()); if (comp != 0) { return comp; } return v1.get(0).compareTo(v2.get(0)); }); - - JavaEnumSource source = Roaster.create(JavaEnumSource.class); + + final JavaEnumSource source = Roaster.create(JavaEnumSource.class); source.setName("MCVersion"); source.setPackage("com.syntaxphoenix.spigot.smoothtimber.version.manager.gen"); source.addImport("com.syntaxphoenix.spigot.smoothtimber.version.manager.VersionChanger"); @@ -103,41 +102,25 @@ public boolean process(Set annotations, RoundEnvironment source.addImport("com.syntaxphoenix.syntaxapi.version.VersionState"); source.addImport("java.util.ArrayList"); source.addImport("org.bukkit.Bukkit"); - source.addNestedType(join("\n", new String[] { - "private static interface ChangerBuilder {", - " public VersionChanger create();", - "}" - })); - source.addNestedType(join("\n", new String[] { - "public static final class MCVersionResult {", - " private final MCVersion version;", - " private final VersionState state;", - " private MCVersionResult(MCVersion version, VersionState state) {", - " this.version = version;", - " this.state = state;", - " }", - " public MCVersion version() { return version; }", - " public VersionState state() { return state; }", - "}" - })); - source.addMethod(join("\n", new String[] { - "MCVersion(DefaultVersion[] versions, ChangerBuilder builder) {", - " this.builder = builder;", - " versionManager.setAll(VersionState.SUPPORTED, versions);", - "}" - })).setConstructor(true); + source.addNestedType(join("\n", "private static interface ChangerBuilder {", " public VersionChanger create();", "}")); + source.addNestedType(join("\n", "public static final class MCVersionResult {", " private final MCVersion version;", + " private final VersionState state;", " private MCVersionResult(MCVersion version, VersionState state) {", + " this.version = version;", " this.state = state;", " }", " public MCVersion version() { return version; }", + " public VersionState state() { return state; }", "}")); + source.addMethod(join("\n", "MCVersion(DefaultVersion[] versions, ChangerBuilder builder) {", " this.builder = builder;", + " versionManager.setAll(VersionState.SUPPORTED, versions);", "}")).setConstructor(true); for (int index = 0; index < types.size(); index++) { - String type = types.get(index); - ArrayList versions = map.get(type); - + final String type = types.get(index); + final ArrayList versions = map.get(type); + source.addImport(type); - String typeName = getNameFromType(type); - String versionName = getVersionFromName(typeName); - EnumConstantSource enumSource = source.addEnumConstant(versionName); - - StringBuilder versionArray = new StringBuilder("new DefaultVersion[] {"); - for (Version version : versions) { + final String typeName = getNameFromType(type); + final String versionName = getVersionFromName(typeName); + final EnumConstantSource enumSource = source.addEnumConstant(versionName); + + final StringBuilder versionArray = new StringBuilder("new DefaultVersion[] {"); + for (final Version version : versions) { versionArray.append("new DefaultVersion("); versionArray.append(version.getMajor()).append(", ").append(version.getMinor()).append(", ").append(version.getPatch()); versionArray.append("),"); @@ -149,104 +132,59 @@ public boolean process(Set annotations, RoundEnvironment source.addField("private static DefaultVersion minecraftVersion;"); source.addField("private static MCVersionResult coreVersionResult;"); - source.addField("private final VersionManager versionManager = new VersionManager(VersionState.NOT_COMPATIBLE, VersionState.NOT_TESTED, VersionState.NOT_COMPATIBLE);"); + source.addField( + "private final VersionManager versionManager = new VersionManager(VersionState.NOT_COMPATIBLE, VersionState.NOT_TESTED, VersionState.NOT_COMPATIBLE);"); source.addField("private final ChangerBuilder builder;"); - - source.addMethod(join("\n", new String[] { - "public VersionChanger create() {", - " return builder.create();", - "}" - })); - - source.addMethod(join("\n", new String[] { - "public VersionState getState(DefaultVersion version) {", - " return versionManager.getState(version);", - "}" - })); - - source.addMethod(join("\n", new String[] { - "public ArrayList getKnownSupported() {", - " return versionManager.getVersions(VersionState.SUPPORTED);", - "}" - })); - - source.addMethod(join("\n", new String[] { - "public static ArrayList getAllKnownSupported() {", - " ArrayList list = new ArrayList<>();", - " for (MCVersion version : ALL_VERSIONS) {", - " list.addAll(version.getKnownSupported());", - " }", - " return list;", - "}" - })); - source.addMethod(join("\n", new String[] { - "public static DefaultVersion getMinecraftVersion() {", - " if (minecraftVersion != null) {", - " return minecraftVersion;", - " }", - " String versionStr = Bukkit.getVersion().split(\" \")[2].replace(\")\", \"\");", + + source.addMethod(join("\n", "public VersionChanger create() {", " return builder.create();", "}")); + + source.addMethod( + join("\n", "public VersionState getState(DefaultVersion version) {", " return versionManager.getState(version);", "}")); + + source.addMethod(join("\n", "public ArrayList getKnownSupported() {", + " return versionManager.getVersions(VersionState.SUPPORTED);", "}")); + + source.addMethod(join("\n", "public static ArrayList getAllKnownSupported() {", + " ArrayList list = new ArrayList<>();", " for (MCVersion version : ALL_VERSIONS) {", + " list.addAll(version.getKnownSupported());", " }", " return list;", "}")); + source.addMethod(join("\n", "public static DefaultVersion getMinecraftVersion() {", " if (minecraftVersion != null) {", + " return minecraftVersion;", " }", " String versionStr = Bukkit.getVersion().split(\" \")[2].replace(\")\", \"\");", " Version version = ANALYZER.analyze(versionStr);", " if (version == null || version.getMajor() == 0 || !(version instanceof DefaultVersion)) {", - " throw new IllegalStateException(String.format(\"Minecraft version is invalid: '%s'\", versionStr));", - " }", - " return (minecraftVersion = (DefaultVersion) version);", - "}" - })); - source.addMethod(join("\n", new String[] { - "public static MCVersion getCoreVersion() {", - " return getCoreVersionResult().version();", - "}" - })); - source.addMethod(join("\n", new String[] { - "public static MCVersionResult getCoreVersionResult() {", - " if (coreVersionResult != null) {", - " return coreVersionResult;", - " }", - " return (coreVersionResult = detectCoreVersion(getMinecraftVersion()));", - "}" - })); - source.addMethod(join("\n", new String[] { - "public static MCVersionResult detectCoreVersion(DefaultVersion version) {", - " if (ALL_VERSIONS.length == 0) {", - " throw new IllegalStateException(\"No core version available\");", - " }", - " MCVersion selected = ALL_VERSIONS[0];", - " VersionState selectedState = VersionState.NOT_COMPATIBLE;", - " for (MCVersion current : ALL_VERSIONS) {", - " VersionState state = current.getState(version);", - " if (state == VersionState.NOT_COMPATIBLE) {", - " break;", - " }", - " selected = current;", - " if ((selectedState = state) == VersionState.SUPPORTED || state == VersionState.NOT_SUPPORTED) {", - " break;", - " }", - " }", - " return new MCVersionResult(selected, selectedState);", - "}" - })); - + " throw new IllegalStateException(String.format(\"Minecraft version is invalid: '%s'\", versionStr));", " }", + " return (minecraftVersion = (DefaultVersion) version);", "}")); + source.addMethod(join("\n", "public static MCVersion getCoreVersion() {", " return getCoreVersionResult().version();", "}")); + source.addMethod(join("\n", "public static MCVersionResult getCoreVersionResult() {", " if (coreVersionResult != null) {", + " return coreVersionResult;", " }", " return (coreVersionResult = detectCoreVersion(getMinecraftVersion()));", "}")); + source.addMethod(join("\n", "public static MCVersionResult detectCoreVersion(DefaultVersion version) {", + " if (ALL_VERSIONS.length == 0) {", " throw new IllegalStateException(\"No core version available\");", " }", + " MCVersion selected = ALL_VERSIONS[0];", " VersionState selectedState = VersionState.NOT_COMPATIBLE;", + " for (MCVersion current : ALL_VERSIONS) {", " VersionState state = current.getState(version);", + " if (state == VersionState.NOT_COMPATIBLE) {", " break;", " }", " selected = current;", + " if ((selectedState = state) == VersionState.SUPPORTED || state == VersionState.NOT_SUPPORTED) {", " break;", + " }", " }", " return new MCVersionResult(selected, selectedState);", "}")); + try { - JavaFileObject file = processingEnv.getFiler().createSourceFile(source.getPackage() + '.' + source.getName()); + final JavaFileObject file = processingEnv.getFiler().createSourceFile(source.getPackage() + '.' + source.getName()); try (Writer writer = file.openWriter()) { writer.write(source.toString()); } - } catch (IOException e) { + } catch (final IOException e) { } - + return false; } /* * Helper */ - - private String getNameFromType(String typeName) { - String[] parts = typeName.split("\\."); + + private String getNameFromType(final String typeName) { + final String[] parts = typeName.split("\\."); return parts[parts.length - 1]; } - - private String getVersionFromName(String changerName) { + + private String getVersionFromName(final String changerName) { return changerName.split("x", 2)[0] + 'x'; } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/SupportedVersions.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/SupportedVersions.java index 5bd4764..91cfa5a 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/SupportedVersions.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/annotation/SupportedVersions.java @@ -9,7 +9,7 @@ @Retention(SOURCE) @Target(TYPE) public @interface SupportedVersions { - + public String[] value() default {}; } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/command/commands/ToggleCommand.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/command/commands/ToggleCommand.java index b65ca03..a11b215 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/command/commands/ToggleCommand.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/command/commands/ToggleCommand.java @@ -26,7 +26,7 @@ public void execute(final MinecraftInfo info, final Arguments arguments) { return; } - if ((!sender.hasPermission("smoothtimber.toggle") && !sender.hasPermission("smoothtimber.*"))) { + if (!sender.hasPermission("smoothtimber.toggle") && !sender.hasPermission("smoothtimber.*")) { sender.sendMessage(Message.GLOBAL_PREFIX.colored() + ' ' + Message.COMMAND_MISSING222PERMISSION.colored(new String[] { "%permission%", "smoothtimber.toggle" @@ -41,7 +41,7 @@ public void execute(final MinecraftInfo info, final Arguments arguments) { int time = -1; - if ((arguments.count() != 0) && (arguments.getType(1) == ArgumentType.INTEGER || arguments.getType(1) == ArgumentType.BYTE + if (arguments.count() != 0 && (arguments.getType(1) == ArgumentType.INTEGER || arguments.getType(1) == ArgumentType.BYTE || arguments.getType(1) == ArgumentType.SHORT)) { time = arguments.get(1).asNumeric().asNumber().intValue(); } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/CompatibilityHandler.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/CompatibilityHandler.java index 75a8aba..0e30849 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/CompatibilityHandler.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/CompatibilityHandler.java @@ -5,12 +5,12 @@ import java.util.Map; import java.util.Optional; -import com.syntaxphoenix.spigot.smoothtimber.compatibility.factionsuuid.FactionsUUID; import org.bukkit.plugin.java.JavaPlugin; import com.syntaxphoenix.spigot.smoothtimber.SmoothTimber; import com.syntaxphoenix.spigot.smoothtimber.compatibility.blockylog.BlockyLog; import com.syntaxphoenix.spigot.smoothtimber.compatibility.coreprotect.CoreProtect; +import com.syntaxphoenix.spigot.smoothtimber.compatibility.factionsuuid.FactionsUUID; import com.syntaxphoenix.spigot.smoothtimber.compatibility.griefprevention.GriefPrevention; import com.syntaxphoenix.spigot.smoothtimber.compatibility.jobsreborn.JobsReborn; import com.syntaxphoenix.spigot.smoothtimber.compatibility.lands.Lands; @@ -103,7 +103,7 @@ public static class CompatAddon { private final Class owner; private final Reflect reflect; - + private final String name; private CompatibilityAddon instance; @@ -132,20 +132,23 @@ void start(final PluginPackage pluginPackage) { } instance = (CompatibilityAddon) reflect.init(); try { - PluginUtils.sendConsoleMessage(true, "&7Trying to enable compatibility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'..."); + PluginUtils.sendConsoleMessage(true, + "&7Trying to enable compatibility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'..."); instance.onEnable(pluginPackage, JavaPlugin.getPlugin(SmoothTimber.class)); if (instance.hasConfig()) { - PluginUtils.sendConsoleMessage(true, "&7Trying to load config of compatibility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'..."); + PluginUtils.sendConsoleMessage(true, "&7Trying to load config of compatibility addon '&3" + name + "&7' for plugin '&3" + + pluginPackage.getName() + "&7'..."); instance.getConfig().reload(); } - PluginUtils.sendConsoleMessage(true, "&7Successfully enabled compatbility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'..."); + PluginUtils.sendConsoleMessage(true, + "&7Successfully enabled compatbility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'..."); } catch (final IncompatiblePluginException pluginException) { instance = null; PluginUtils.sendConsoleMessage(true, Exceptions.stackTraceToString(pluginException)); } catch (final Exception exception) { instance = null; - PluginUtils.sendConsoleMessage(true, "&7Failed to enable compatibility addon '&3" + name - + "&7' for plugin '&3" + pluginPackage.getName() + "&7'!"); + PluginUtils.sendConsoleMessage(true, + "&7Failed to enable compatibility addon '&3" + name + "&7' for plugin '&3" + pluginPackage.getName() + "&7'!"); } } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/IncompatiblePluginException.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/IncompatiblePluginException.java index 75bd0c0..2fe96da 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/IncompatiblePluginException.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/IncompatiblePluginException.java @@ -12,8 +12,7 @@ public class IncompatiblePluginException extends RuntimeException { * message. The cause is not initialized, and may subsequently be initialized by * a call to {@link #initCause}. */ - public IncompatiblePluginException() { - } + public IncompatiblePluginException() {} /** * Constructs a new IncompatiblePluginException with the specified detail diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUID.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUID.java index a3c5e12..1ffcef1 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUID.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUID.java @@ -1,12 +1,13 @@ package com.syntaxphoenix.spigot.smoothtimber.compatibility.factionsuuid; +import org.bukkit.Bukkit; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + import com.syntaxphoenix.spigot.smoothtimber.SmoothTimber; import com.syntaxphoenix.spigot.smoothtimber.compatibility.CompatibilityAddon; import com.syntaxphoenix.spigot.smoothtimber.compatibility.IncompatiblePluginException; import com.syntaxphoenix.spigot.smoothtimber.utilities.plugin.PluginPackage; -import org.bukkit.Bukkit; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; public class FactionsUUID extends CompatibilityAddon { @@ -19,7 +20,7 @@ public void onEnable(final PluginPackage pluginPackage, final SmoothTimber smoot Class.forName("com.massivecraft.factions.perms.PermissibleActions"); Bukkit.getServer().getPluginManager().registerEvents(listener = new FactionsUUIDChopListener(), smoothTimber); return; - } catch (ClassNotFoundException ignored) { + } catch (final ClassNotFoundException ignored) { } if (listener == null) { throw new IncompatiblePluginException("Found a Factions plugin not presently supported by SmoothTimber"); diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUIDChopListener.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUIDChopListener.java index 2f0c875..c074aa9 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUIDChopListener.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/factionsuuid/FactionsUUIDChopListener.java @@ -1,5 +1,10 @@ package com.syntaxphoenix.spigot.smoothtimber.compatibility.factionsuuid; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.config.file.MainConfig; @@ -8,16 +13,11 @@ import com.syntaxphoenix.spigot.smoothtimber.event.AsyncPlayerChopTreeEvent; import com.syntaxphoenix.spigot.smoothtimber.event.reason.DefaultReason; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - public class FactionsUUIDChopListener implements Listener { - - private MainConfig config; - private FPlayers players; - + + private final MainConfig config; + private final FPlayers players; + public FactionsUUIDChopListener() { this.config = FactionsPlugin.getInstance().conf(); this.players = FPlayers.getInstance(); @@ -25,11 +25,12 @@ public FactionsUUIDChopListener() { @EventHandler public void onAsyncPlayerChopTree(final AsyncPlayerChopTreeEvent event) { - Player player = event.getPlayer(); - if (config.factions().protection().getPlayersWhoBypassAllProtection().contains(player.getName()) || players.getByPlayer(player).isAdminBypassing()) { + final Player player = event.getPlayer(); + if (config.factions().protection().getPlayersWhoBypassAllProtection().contains(player.getName()) + || players.getByPlayer(player).isAdminBypassing()) { return; } - for(Location bktLocation : event.getBlockLocations()) { + for (final Location bktLocation : event.getBlockLocations()) { if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), bktLocation, PermissibleActions.DESTROY, true)) { event.setCancelled(true); event.setReason(DefaultReason.FACTIONS); diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/jobsreborn/JobsRebornConfig.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/jobsreborn/JobsRebornConfig.java index 891f6c8..85ef58d 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/jobsreborn/JobsRebornConfig.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/jobsreborn/JobsRebornConfig.java @@ -13,7 +13,7 @@ public final class JobsRebornConfig extends CompatibilityAddonConfig public static final EnumMap DEFAULT_WOOD_DATA = new EnumMap<>(WoodType.class); public static final HashMap> JOB_DATA = new HashMap<>(); - + private final VersionChanger change = PluginUtils.CHANGER; /* diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/logblock/LogBlockDatabaseAccessor.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/logblock/LogBlockDatabaseAccessor.java index aa04786..4385684 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/logblock/LogBlockDatabaseAccessor.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/logblock/LogBlockDatabaseAccessor.java @@ -48,7 +48,7 @@ public boolean isPlayerPlaced(final Block block) { statement.setInt(2, block.getY()); statement.setInt(3, block.getZ()); try (ResultSet resultSet = statement.executeQuery()) { - if (!resultSet.next() || (resultSet.getInt("playerid") < 0)) { + if (!resultSet.next() || resultSet.getInt("playerid") < 0) { return false; } final Material type = MaterialConverter.getMaterial(resultSet.getInt("type")); diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/mcmmo/McMmoChopListener.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/mcmmo/McMmoChopListener.java index 7115e22..ea768dd 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/mcmmo/McMmoChopListener.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/mcmmo/McMmoChopListener.java @@ -25,7 +25,7 @@ public void onChopEvent(final AsyncPlayerChopTreeEvent event) { if (player == null || !PrimarySkillType.WOODCUTTING.getPermissions(event.getPlayer())) { return; } - + Platform.getPlatform().regionalSyncTask(event.getTreeLocation(), () -> { for (final Location location : event.getBlockLocations()) { if (!hasWoodcuttingXP(location.getBlock()) || mcMMO.getPlaceStore().isTrue(location.getBlock().getState())) { diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/residence/ResidenceChopListener.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/residence/ResidenceChopListener.java index 4be2c84..b283aaf 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/residence/ResidenceChopListener.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/residence/ResidenceChopListener.java @@ -24,7 +24,7 @@ public void onChopEvent(final AsyncPlayerChopTreeEvent event) { final ResidenceManager manager = Residence.getInstance().getResidenceManager(); for (final Location location : event.getBlockLocations()) { final ClaimedResidence residence = manager.getByLoc(location); - if ((residence != null) && !residence.getPermissions().playerHas(event.getPlayer(), Flags.build, true)) { + if (residence != null && !residence.getPermissions().playerHas(event.getPlayer(), Flags.build, true)) { event.setCancelled(true); event.setReason(DefaultReason.RESIDENCE); return null; diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/listener/BlockBreakListener.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/listener/BlockBreakListener.java index b8b64fb..776d2f1 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/listener/BlockBreakListener.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/listener/BlockBreakListener.java @@ -2,7 +2,6 @@ import java.util.ArrayList; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.block.Block; @@ -58,7 +57,8 @@ public void onBlockBreak(final BlockBreakEvent event) { } } - if (CutterConfig.SNEAK.test(() -> player.isSneaking()) || CutterConfig.TOGGLEABLE.test(() -> SmoothTimber.STORAGE.hasToggled(player.getUniqueId()))) { + if (CutterConfig.SNEAK.test(() -> player.isSneaking()) + || CutterConfig.TOGGLEABLE.test(() -> SmoothTimber.STORAGE.hasToggled(player.getUniqueId()))) { return; } @@ -113,8 +113,7 @@ public void run() { final Entity entity = change.toFallingBlock(block); entity.setMetadata("STAnimate", new FixedMetadataValue(plugin, amount)); if (collect) { - entity.setMetadata("STCollect", - new FixedMetadataValue(plugin, player.getUniqueId().toString())); + entity.setMetadata("STCollect", new FixedMetadataValue(plugin, player.getUniqueId().toString())); } continue; } @@ -137,16 +136,15 @@ private int generateAmount(final int max) { float next = more * 3f; final float chance = generator.nextFloat() * (float) CutterConfig.LUCK_MULTIPLIER; while (true) { - if (previous < chance && chance > next) { - drop++; - previous = next; - next += more; - } else { + if ((previous >= chance) || (chance <= next)) { if (previous < chance && chance < next) { drop++; } break; } + drop++; + previous = next; + next += more; } return Math.min(drop, 64); } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/FoliaPlatform.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/FoliaPlatform.java index 8135aaa..57e9bdf 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/FoliaPlatform.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/FoliaPlatform.java @@ -21,10 +21,11 @@ final class FoliaPlatform extends Platform { private final RegionScheduler region; private final AsyncScheduler async; - public FoliaPlatform(SmoothTimber plugin){ + public FoliaPlatform(final SmoothTimber plugin) { this.plugin = plugin; - Server server = plugin.getServer(); - AbstractReflect reflect = new Reflect(server.getClass()).searchMethod("async", "getAsyncScheduler").searchMethod("region", "getRegionScheduler").searchMethod("global", "getGlobalRegionScheduler"); + final Server server = plugin.getServer(); + final AbstractReflect reflect = new Reflect(server.getClass()).searchMethod("async", "getAsyncScheduler") + .searchMethod("region", "getRegionScheduler").searchMethod("global", "getGlobalRegionScheduler"); this.global = (GlobalRegionScheduler) reflect.run(server, "global"); this.region = (RegionScheduler) reflect.run(server, "region"); this.async = (AsyncScheduler) reflect.run(server, "async"); @@ -37,48 +38,48 @@ protected void internalShutdown() { } @Override - public void regionalTask(Location location, Runnable runnable) { + public void regionalTask(final Location location, final Runnable runnable) { region.execute(plugin, location, runnable); } @Override - public void regionalSyncTask(Location location, Runnable runnable) { - region.run(plugin, location, (t) -> runnable.run()); + public void regionalSyncTask(final Location location, final Runnable runnable) { + region.run(plugin, location, t -> runnable.run()); } @Override - public void regionalSyncTaskLater(Location location, Runnable runnable, long delay) { - region.runDelayed(plugin, location, (t) -> runnable.run(), delay); + public void regionalSyncTaskLater(final Location location, final Runnable runnable, final long delay) { + region.runDelayed(plugin, location, t -> runnable.run(), delay); } @Override - public void syncTask(Runnable runnable) { - global.run(plugin, (t) -> runnable.run()); + public void syncTask(final Runnable runnable) { + global.run(plugin, t -> runnable.run()); } @Override - public void syncTaskLater(Runnable runnable, long delay) { - global.runDelayed(plugin, (t) -> runnable.run(), delay); + public void syncTaskLater(final Runnable runnable, final long delay) { + global.runDelayed(plugin, t -> runnable.run(), delay); } @Override - public void syncTaskTimer(Runnable runnable, long delay, long repeat) { - global.runAtFixedRate(plugin, (t) -> runnable.run(), delay, repeat); + public void syncTaskTimer(final Runnable runnable, final long delay, final long repeat) { + global.runAtFixedRate(plugin, t -> runnable.run(), delay, repeat); } @Override - public void asyncTask(Runnable runnable) { - async.runNow(plugin, (t) -> runnable.run()); + public void asyncTask(final Runnable runnable) { + async.runNow(plugin, t -> runnable.run()); } @Override - public void asyncTaskLater(Runnable runnable, long delay) { - async.runDelayed(plugin, (t) -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS); + public void asyncTaskLater(final Runnable runnable, final long delay) { + async.runDelayed(plugin, t -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS); } @Override - public void asyncTaskTimer(Runnable runnable, long delay, long repeat) { - async.runAtFixedRate(plugin, (t) -> runnable.run(), delay * 50L, repeat * 50L, TimeUnit.MILLISECONDS); + public void asyncTaskTimer(final Runnable runnable, final long delay, final long repeat) { + async.runAtFixedRate(plugin, t -> runnable.run(), delay * 50L, repeat * 50L, TimeUnit.MILLISECONDS); } - + } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/Platform.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/Platform.java index 1080163..6dc2c00 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/Platform.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/Platform.java @@ -18,13 +18,14 @@ public static Platform getPlatform() { } public static void shutdown() { - Platform platform = Platform.platform.get(); + final Platform platform = Platform.platform.get(); Platform.platform.replace(null); platform.internalShutdown(); } - private static Platform createPlatform(SmoothTimber plugin) { - if (ClassCache.getOptionalClass("io.papermc.paper.threadedregions.RegionizedServer").or(() -> ClassCache.getOptionalClass("io.papermc.paper.threadedregions.RegionizedServerInitEvent")).isPresent()) { + private static Platform createPlatform(final SmoothTimber plugin) { + if (ClassCache.getOptionalClass("io.papermc.paper.threadedregions.RegionizedServer") + .or(() -> ClassCache.getOptionalClass("io.papermc.paper.threadedregions.RegionizedServerInitEvent")).isPresent()) { return new FoliaPlatform(plugin); } return new SpigotPlatform(plugin); @@ -32,15 +33,15 @@ private static Platform createPlatform(SmoothTimber plugin) { protected abstract void internalShutdown(); - public void regionalTask(Location location, Runnable runnable) { + public void regionalTask(final Location location, final Runnable runnable) { runnable.run(); } - public void regionalSyncTask(Location location, Runnable runnable) { + public void regionalSyncTask(final Location location, final Runnable runnable) { syncTask(runnable); } - public void regionalSyncTaskLater(Location location, Runnable runnable, long delay) { + public void regionalSyncTaskLater(final Location location, final Runnable runnable, final long delay) { syncTaskLater(runnable, delay); } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/SpigotPlatform.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/SpigotPlatform.java index a5e2e36..7976ac2 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/SpigotPlatform.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/platform/SpigotPlatform.java @@ -9,7 +9,7 @@ final class SpigotPlatform extends Platform { private final SmoothTimber plugin; private final BukkitScheduler scheduler; - public SpigotPlatform(SmoothTimber plugin){ + public SpigotPlatform(final SmoothTimber plugin) { this.plugin = plugin; this.scheduler = plugin.getServer().getScheduler(); } @@ -20,33 +20,33 @@ protected void internalShutdown() { } @Override - public void syncTask(Runnable runnable) { + public void syncTask(final Runnable runnable) { scheduler.runTask(plugin, runnable); } @Override - public void syncTaskLater(Runnable runnable, long delay) { + public void syncTaskLater(final Runnable runnable, final long delay) { scheduler.runTaskLater(plugin, runnable, delay); } @Override - public void syncTaskTimer(Runnable runnable, long delay, long repeat) { + public void syncTaskTimer(final Runnable runnable, final long delay, final long repeat) { scheduler.runTaskTimer(plugin, runnable, delay, repeat); } @Override - public void asyncTask(Runnable runnable) { + public void asyncTask(final Runnable runnable) { scheduler.runTaskAsynchronously(plugin, runnable); } @Override - public void asyncTaskLater(Runnable runnable, long delay) { + public void asyncTaskLater(final Runnable runnable, final long delay) { scheduler.runTaskLaterAsynchronously(plugin, runnable, delay); } @Override - public void asyncTaskTimer(Runnable runnable, long delay, long repeat) { + public void asyncTaskTimer(final Runnable runnable, final long delay, final long repeat) { scheduler.runTaskTimerAsynchronously(plugin, runnable, delay, repeat); } - + } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/toggle/ToggledUser.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/toggle/ToggledUser.java index c0b3d6c..6a81924 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/toggle/ToggledUser.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/toggle/ToggledUser.java @@ -96,15 +96,13 @@ public Message getMessage(final boolean trigger, final boolean timed, final bool if (trigger) { if (state) { return timed ? Message.TOGGLE_ON_TIMED : Message.TOGGLE_ON_FOREVER; - } else { - return Message.TOGGLE_OFF_FOREVER; } + return Message.TOGGLE_OFF_FOREVER; } if (state) { return timed ? Message.TOGGLE_OFF_TIMED : Message.TOGGLE_OFF_FOREVER; - } else { - return Message.TOGGLE_ON_FOREVER; } + return Message.TOGGLE_ON_FOREVER; } } diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/utilities/PluginUtils.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/utilities/PluginUtils.java index 5be8c3e..9a197ea 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/utilities/PluginUtils.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/utilities/PluginUtils.java @@ -11,7 +11,6 @@ import org.bukkit.command.PluginCommand; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.bukkit.scheduler.BukkitScheduler; import com.syntaxphoenix.spigot.smoothtimber.SmoothTimber; import com.syntaxphoenix.spigot.smoothtimber.command.CommandRedirect; diff --git a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/version/changer/v1_20xChanger.java b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/version/changer/v1_20xChanger.java index e43d739..60dd002 100644 --- a/src/main/java/com/syntaxphoenix/spigot/smoothtimber/version/changer/v1_20xChanger.java +++ b/src/main/java/com/syntaxphoenix/spigot/smoothtimber/version/changer/v1_20xChanger.java @@ -61,7 +61,7 @@ public ItemStack removeDurabilityFromItem(final ItemStack stack) { } if (meta instanceof Damageable) { final Damageable dmg = (Damageable) meta; - int damage = dmg.getDamage() + 1; + final int damage = dmg.getDamage() + 1; if (stack.getType().getMaxDurability() - damage < 0) { stack.setAmount(0); return null;