From 289cb7ef6284b2ac1ccafbfa87654dc85415befe Mon Sep 17 00:00:00 2001 From: Relluem94 Date: Sat, 20 Apr 2024 12:50:17 +0200 Subject: [PATCH] RE-183 Clean Up --- .github/workflows/codacy.yml | 2 +- .gitmodules | 4 +- .idea/compiler.xml | 3 +- dependency-reduced-pom.xml | 362 +++++++++--------- pom.xml | 8 +- .../server/spigot/essentials/api/WarpAPI.java | 40 +- .../essentials/commands/PermissionsGroup.java | 2 +- .../commands/ProtectTabCompleter.java | 1 - .../spigot/essentials/commands/Sudo.java | 211 +++++----- .../spigot/essentials/commands/Warp.java | 17 +- .../spigot/essentials/commands/Worlds.java | 12 +- .../essentials/constants/Constants.java | 2 + .../spigot/essentials/events/BetterLock.java | 3 - .../spigot/essentials/events/BetterNPC.java | 3 +- .../spigot/essentials/events/BetterSoil.java | 2 - .../spigot/essentials/events/PlayerMove.java | 17 +- .../spigot/essentials/helpers/SignHelper.java | 18 +- .../essentials/managers/ConfigManager.java | 11 +- .../spigot/essentials/managers/IEnable.java | 4 +- .../spigot/essentials/permissions/Groups.java | 21 +- 20 files changed, 375 insertions(+), 368 deletions(-) diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index caced5bb..139767d8 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -51,7 +51,7 @@ jobs: # Adjust severity of non-security issues gh-code-scanning-compat: true # Force 0 exit code to allow SARIF file generation - # This will handover control about PR rejection to the GitHub side + # This will hand over control about PR rejection to the GitHub side max-allowed-issues: 2147483647 # Upload the SARIF file generated in the previous step diff --git a/.gitmodules b/.gitmodules index 155b5da1..ca24c877 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "RelluBash-Script-Collection"] - path = RelluBash-Script-Collection - url = https://github.com/Relluem94s/RelluBash-Script-Collection + path = RelluBash-Script-Collection + url = https://github.com/Relluem94s/RelluBash-Script-Collection diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 4233bdb1..6abea8eb 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -13,8 +13,7 @@ - - + diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 30f98451..2c310f10 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -1,181 +1,181 @@ - - - 4.0.0 - de.relluem94 - relluessentials - RelluEssentials - 4.2 - https://github.com/Relluem94s/RelluEssentials - - scm:git:git@github.com:Relluem94s/RelluEssentials.git - scm:git:git@github.com:Relluem94s/RelluEssentials.git - https://github.com/Relluem94s/RelluEssentials - - - src/main/java - - - true - src/main/resources - - - - - maven-compiler-plugin - 3.12.1 - - 17 - 17 - UTF-8 - - - org.projectlombok - lombok - ${lombok.version} - - - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - true - - - *:* - - META-INF/** - LICENSE - module-info.class - - - - - - - - - maven-resources-plugin - 3.3.0 - - UTF-8 - - - - - - - - github - - - - - github - RelluLib - https://maven.pkg.github.com/Relluem94s/RelluLib - - - - - - - central - central - https://repo.maven.apache.org/maven2/ - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - github - Relluem94s - https://maven.pkg.github.com/Relluem94s/RelluLib - - - - - org.spigotmc - spigot-api - 1.20.1-R0.1-SNAPSHOT - provided - - - org.junit.jupiter - junit-jupiter-engine - 5.10.1 - test - - - junit-platform-engine - org.junit.platform - - - junit-jupiter-api - org.junit.jupiter - - - apiguardian-api - org.apiguardian - - - - - org.junit.platform - junit-platform-runner - 1.10.1 - test - - - junit - junit - - - junit-platform-launcher - org.junit.platform - - - junit-platform-suite-api - org.junit.platform - - - junit-platform-suite-commons - org.junit.platform - - - apiguardian-api - org.apiguardian - - - - - - - github - GitHub Relluem94s Apache Maven Packages - https://maven.pkg.github.com/Relluem94s/RelluEssentials - - - - 17 - 1.20 - 1.18.30 - 1.20.1-R0.1-SNAPSHOT - Relluem94 - utf-8 - https://www.relluem94.de - de.relluem94.minecraft.server.spigot.essentials.RelluEssentials - - + + + 4.0.0 + de.relluem94 + relluessentials + RelluEssentials + 4.2 + https://github.com/Relluem94s/RelluEssentials + + scm:git:git@github.com:Relluem94s/RelluEssentials.git + scm:git:git@github.com:Relluem94s/RelluEssentials.git + https://github.com/Relluem94s/RelluEssentials + + + src/main/java + + + true + src/main/resources + + + + + maven-compiler-plugin + 3.12.1 + + 17 + 17 + UTF-8 + + + org.projectlombok + lombok + ${lombok.version} + + + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + true + + + *:* + + META-INF/** + LICENSE + module-info.class + + + + + + + + + maven-resources-plugin + 3.3.0 + + UTF-8 + + + + + + + + github + + + + + github + RelluLib + https://maven.pkg.github.com/Relluem94s/RelluLib + + + + + + + central + central + https://repo.maven.apache.org/maven2/ + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + github + Relluem94s + https://maven.pkg.github.com/Relluem94s/RelluLib + + + + + org.spigotmc + spigot-api + 1.20.1-R0.1-SNAPSHOT + provided + + + org.junit.jupiter + junit-jupiter-engine + 5.10.1 + test + + + junit-platform-engine + org.junit.platform + + + junit-jupiter-api + org.junit.jupiter + + + apiguardian-api + org.apiguardian + + + + + org.junit.platform + junit-platform-runner + 1.10.1 + test + + + junit + junit + + + junit-platform-launcher + org.junit.platform + + + junit-platform-suite-api + org.junit.platform + + + junit-platform-suite-commons + org.junit.platform + + + apiguardian-api + org.apiguardian + + + + + + + github + GitHub Relluem94s Apache Maven Packages + https://maven.pkg.github.com/Relluem94s/RelluEssentials + + + + 17 + 1.20 + 1.18.30 + 1.20.1-R0.1-SNAPSHOT + Relluem94 + utf-8 + https://www.relluem94.de + de.relluem94.minecraft.server.spigot.essentials.RelluEssentials + + diff --git a/pom.xml b/pom.xml index f015a72f..11b72685 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 4.2 https://github.com/Relluem94s/RelluEssentials - 1.18.30 + 1.18.32 1.20.1-R0.1-SNAPSHOT 1.20 Relluem94 @@ -94,18 +94,18 @@ com.google.guava guava - 32.1.3-jre + 33.1.0-jre org.junit.jupiter junit-jupiter-engine - 5.10.1 + 5.10.2 test org.junit.platform junit-platform-runner - 1.10.1 + 1.10.2 test diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/api/WarpAPI.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/api/WarpAPI.java index 98914bf3..0ccc4dce 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/api/WarpAPI.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/api/WarpAPI.java @@ -1,52 +1,46 @@ package de.relluem94.minecraft.server.spigot.essentials.api; -import java.util.ArrayList; -import java.util.List; - -import lombok.Getter; -import org.bukkit.World; - import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.LocationEntry; +import org.bukkit.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -@Getter -public class WarpAPI { - private final List warps; +import java.util.ArrayList; +import java.util.List; - public WarpAPI(List warps){ - this.warps = warps; - } +public record WarpAPI(List warps) { - public LocationEntry getWarp(String name){ - for(LocationEntry le : warps){ - if(le != null && le.getLocationName().equals(name)){ + public @Nullable LocationEntry getWarp(String name) { + for (LocationEntry le : warps) { + if (le != null && le.getLocationName().equals(name)) { return le; } } return null; } - public LocationEntry getWarp(String name, World world){ - for(LocationEntry le : warps){ - if(le != null && le.getLocation() != null && le.getLocation().getWorld() != null && le.getLocationName().equals(name) && le.getLocation().getWorld().equals(world)){ + public @Nullable LocationEntry getWarp(String name, World world) { + for (LocationEntry le : warps) { + if (le != null && le.getLocation() != null && le.getLocation().getWorld() != null && le.getLocationName().equals(name) && le.getLocation().getWorld().equals(world)) { return le; } } return null; } - public void removeWarp(LocationEntry le){ + public void removeWarp(LocationEntry le) { warps.remove(le); } - public void addWarp(LocationEntry le){ + public void addWarp(LocationEntry le) { warps.add(le); } - public List getWarps(World world){ + public @NotNull List getWarps(World world) { List filteredWarps = new ArrayList<>(); - for(LocationEntry le : warps){ - if(le != null && le.getLocation() != null && le.getLocation().getWorld() != null && le.getLocation().getWorld().equals(world)){ + for (LocationEntry le : warps) { + if (le != null && le.getLocation() != null && le.getLocation().getWorld() != null && le.getLocation().getWorld().equals(world)) { filteredWarps.add(le); } } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/PermissionsGroup.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/PermissionsGroup.java index a11aa9fd..58f5728e 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/PermissionsGroup.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/PermissionsGroup.java @@ -74,7 +74,7 @@ else if (isCMDBlock(sender) || isConsole(sender)) { private static GroupEntry checkGroupExists(String groupName, Player p) { GroupEntry g = Groups.getGroup(groupName); - if(!Groups.groupExists(groupName)){ + if(Groups.groupExists(groupName)){ p.sendMessage(PLUGIN_COMMAND_SETGROUP_GROUP_NOT_FOUND); return null; } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/ProtectTabCompleter.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/ProtectTabCompleter.java index 0c40a8f5..8b71585d 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/ProtectTabCompleter.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/ProtectTabCompleter.java @@ -1,6 +1,5 @@ package de.relluem94.minecraft.server.spigot.essentials.commands; -import de.relluem94.minecraft.server.spigot.essentials.constants.ProtectionFlags; import de.relluem94.minecraft.server.spigot.essentials.helpers.TabCompleterHelper; import de.relluem94.minecraft.server.spigot.essentials.permissions.Groups; import de.relluem94.minecraft.server.spigot.essentials.permissions.Permission; diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Sudo.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Sudo.java index 6d9050e7..efd4c1c2 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Sudo.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Sudo.java @@ -1,106 +1,107 @@ -package de.relluem94.minecraft.server.spigot.essentials.commands; - -import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_PERMISSION_MISSING; -import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_WRONG_SUB_COMMAND; -import static de.relluem94.minecraft.server.spigot.essentials.constants.CommandNameConstants.PLUGIN_COMMAND_NAME_SUDO; -import static de.relluem94.minecraft.server.spigot.essentials.helpers.TypeHelper.isPlayer; - -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; - -import de.relluem94.minecraft.server.spigot.essentials.RelluEssentials; -import de.relluem94.minecraft.server.spigot.essentials.constants.Constants; -import de.relluem94.minecraft.server.spigot.essentials.helpers.PlayerHelper; -import de.relluem94.minecraft.server.spigot.essentials.helpers.WorldHelper; -import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.OfflinePlayerEntry; -import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.PlayerEntry; -import de.relluem94.minecraft.server.spigot.essentials.managers.SudoManager; -import de.relluem94.minecraft.server.spigot.essentials.permissions.Groups; -import de.relluem94.minecraft.server.spigot.essentials.permissions.Permission; -import de.relluem94.rellulib.utils.StringUtils; - -public class Sudo implements CommandExecutor { - - @Override - public boolean onCommand(@NonNull CommandSender sender, Command command, @NonNull String label, String[] args) { - if (command.getName().equalsIgnoreCase(PLUGIN_COMMAND_NAME_SUDO)) { - - if(RelluEssentials.getInstance().getCommand(args[0]) != null){ - dispatchCommand(args); - return true; - } - - if (args.length == 1) { - if (isPlayer(sender)) { - Player p = (Player) sender; - if(SudoManager.sudoers.containsKey(p.getUniqueId())){ - exitSudo(p); - return true; - } - else if (Permission.isAuthorized(p, Groups.getGroup("admin").getId())) { - OfflinePlayerEntry target = PlayerHelper.getOfflinePlayerByName((args[0])); - PlayerEntry pe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p); - if (target != null && RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(target.getId()) != null) { - PlayerEntry tpe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(target.getId()); - SudoManager.sudoers.put(p.getUniqueId(), new PlayerEntry(pe)); - WorldHelper.saveWorldGroupInventory(p, true); - pe.setId(tpe.getId()); - pe.setCustomName(tpe.getCustomName()); - pe.setGroup(tpe.getGroup()); - pe.setHomes(tpe.getHomes()); - pe.setPurse(tpe.getPurse()); - p.setCustomName(tpe.getGroup().getPrefix() + target.getName()); - if(tpe.getCustomName() != null){ - p.setCustomName(tpe.getGroup().getPrefix() + tpe.getCustomName()); - } - WorldHelper.loadWorldGroupInventory(p); - p.sendMessage(String.format(Constants.PLUGIN_COMMAND_SUDO_ACTIVATED, tpe.getGroup().getPrefix() + target.getName())); - } - else{ - - p.sendMessage(String.format(Constants.PLUGIN_COMMAND_SUDO_PLAYER_NOT_FOUND, args[0])); - } - return true; - } - else { - p.sendMessage(PLUGIN_COMMAND_PERMISSION_MISSING); - return true; - } - } - } - else{ - sender.sendMessage(PLUGIN_COMMAND_WRONG_SUB_COMMAND); - return true; - } - } - return false; - } - - private void dispatchCommand(String[] args){ - ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); - Bukkit.getServer().dispatchCommand(console, StringUtils.toString(args)); - } - - public static void exitSudo(Player p){ - PlayerEntry tpe = SudoManager.sudoers.get(p.getUniqueId()); - PlayerEntry pe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p); - WorldHelper.saveWorldGroupInventory(p, true); - pe.setId(tpe.getId()); - pe.setCustomName(tpe.getCustomName()); - pe.setGroup(tpe.getGroup()); - pe.setHomes(tpe.getHomes()); - pe.setPurse(tpe.getPurse()); - p.setCustomName(tpe.getGroup().getPrefix() + p.getName()); - if(tpe.getCustomName() != null){ - p.setCustomName(tpe.getGroup().getPrefix() + tpe.getCustomName()); - } - WorldHelper.loadWorldGroupInventory(p); - SudoManager.sudoers.remove(p.getUniqueId()); - p.sendMessage(Constants.PLUGIN_COMMAND_SUDO_DEACTIVATED); - } +package de.relluem94.minecraft.server.spigot.essentials.commands; + +import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_PERMISSION_MISSING; +import static de.relluem94.minecraft.server.spigot.essentials.constants.Constants.PLUGIN_COMMAND_WRONG_SUB_COMMAND; +import static de.relluem94.minecraft.server.spigot.essentials.constants.CommandNameConstants.PLUGIN_COMMAND_NAME_SUDO; +import static de.relluem94.minecraft.server.spigot.essentials.helpers.TypeHelper.isPlayer; + +import lombok.NonNull; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +import de.relluem94.minecraft.server.spigot.essentials.RelluEssentials; +import de.relluem94.minecraft.server.spigot.essentials.constants.Constants; +import de.relluem94.minecraft.server.spigot.essentials.helpers.PlayerHelper; +import de.relluem94.minecraft.server.spigot.essentials.helpers.WorldHelper; +import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.OfflinePlayerEntry; +import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.PlayerEntry; +import de.relluem94.minecraft.server.spigot.essentials.managers.SudoManager; +import de.relluem94.minecraft.server.spigot.essentials.permissions.Groups; +import de.relluem94.minecraft.server.spigot.essentials.permissions.Permission; +import de.relluem94.rellulib.utils.StringUtils; +import org.jetbrains.annotations.NotNull; + +public class Sudo implements CommandExecutor { + + @Override + public boolean onCommand(@NonNull CommandSender sender, @NotNull Command command, @NonNull String label, String[] args) { + if (command.getName().equalsIgnoreCase(PLUGIN_COMMAND_NAME_SUDO)) { + + if(RelluEssentials.getInstance().getCommand(args[0]) != null){ + dispatchCommand(args); + return true; + } + + if (args.length == 1) { + if (isPlayer(sender)) { + Player p = (Player) sender; + if(SudoManager.sudoers.containsKey(p.getUniqueId())){ + exitSudo(p); + return true; + } + else if (Permission.isAuthorized(p, Groups.getGroup("admin").getId())) { + OfflinePlayerEntry target = PlayerHelper.getOfflinePlayerByName((args[0])); + PlayerEntry pe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p); + if (target != null && RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(target.getId()) != null) { + PlayerEntry tpe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(target.getId()); + SudoManager.sudoers.put(p.getUniqueId(), new PlayerEntry(pe)); + WorldHelper.saveWorldGroupInventory(p, true); + pe.setId(tpe.getId()); + pe.setCustomName(tpe.getCustomName()); + pe.setGroup(tpe.getGroup()); + pe.setHomes(tpe.getHomes()); + pe.setPurse(tpe.getPurse()); + p.setCustomName(tpe.getGroup().getPrefix() + target.getName()); + if(tpe.getCustomName() != null){ + p.setCustomName(tpe.getGroup().getPrefix() + tpe.getCustomName()); + } + WorldHelper.loadWorldGroupInventory(p); + p.sendMessage(String.format(Constants.PLUGIN_COMMAND_SUDO_ACTIVATED, tpe.getGroup().getPrefix() + target.getName())); + } + else{ + + p.sendMessage(String.format(Constants.PLUGIN_COMMAND_SUDO_PLAYER_NOT_FOUND, args[0])); + } + return true; + } + else { + p.sendMessage(PLUGIN_COMMAND_PERMISSION_MISSING); + return true; + } + } + } + else{ + sender.sendMessage(PLUGIN_COMMAND_WRONG_SUB_COMMAND); + return true; + } + } + return false; + } + + private void dispatchCommand(String[] args){ + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + Bukkit.getServer().dispatchCommand(console, StringUtils.toString(args)); + } + + public static void exitSudo(Player p){ + PlayerEntry tpe = SudoManager.sudoers.get(p.getUniqueId()); + PlayerEntry pe = RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p); + WorldHelper.saveWorldGroupInventory(p, true); + pe.setId(tpe.getId()); + pe.setCustomName(tpe.getCustomName()); + pe.setGroup(tpe.getGroup()); + pe.setHomes(tpe.getHomes()); + pe.setPurse(tpe.getPurse()); + p.setCustomName(tpe.getGroup().getPrefix() + p.getName()); + if(tpe.getCustomName() != null){ + p.setCustomName(tpe.getGroup().getPrefix() + tpe.getCustomName()); + } + WorldHelper.loadWorldGroupInventory(p); + SudoManager.sudoers.remove(p.getUniqueId()); + p.sendMessage(Constants.PLUGIN_COMMAND_SUDO_DEACTIVATED); + } } \ No newline at end of file diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Warp.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Warp.java index 4597c99e..5b2c5248 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Warp.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Warp.java @@ -23,6 +23,7 @@ import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.LocationEntry; import de.relluem94.minecraft.server.spigot.essentials.permissions.Groups; import de.relluem94.minecraft.server.spigot.essentials.permissions.Permission; +import org.jetbrains.annotations.NotNull; public class Warp implements CommandExecutor { @@ -64,10 +65,12 @@ else if (args.length == 2) { } if(args[0].equalsIgnoreCase(PLUGIN_COMMAND_NAME_WARP_ADD)){ - return addWarp(args[1], p); + addWarp(args[1], p); + return true; } else if(args[0].equalsIgnoreCase(PLUGIN_COMMAND_NAME_WARP_REMOVE)){ - return removeWarp(args[1]); + removeWarp(args[1]); + return true; } else { p.sendMessage(PLUGIN_COMMAND_WRONG_SUB_COMMAND); @@ -77,7 +80,7 @@ else if(args[0].equalsIgnoreCase(PLUGIN_COMMAND_NAME_WARP_REMOVE)){ return false; } - private boolean addWarp(String name, Player p){ + private void addWarp(String name, Player p){ LocationEntry le = RelluEssentials.getInstance().getWarpAPI().getWarp(name); if(le == null){ int typeId = 3; @@ -93,21 +96,17 @@ private boolean addWarp(String name, Player p){ RelluEssentials.getInstance().getWarpAPI().addWarp(le); } - - return true; } - private boolean removeWarp(String name){ + private void removeWarp(String name){ LocationEntry le = RelluEssentials.getInstance().getWarpAPI().getWarp(name); if(le != null){ RelluEssentials.getInstance().getDatabaseHelper().deleteLocation(le); RelluEssentials.getInstance().getWarpAPI().removeWarp(le); } - - return true; } - private void warp(String name, Player p){ + private void warp(String name, @NotNull Player p){ LocationEntry le = RelluEssentials.getInstance().getWarpAPI().getWarp(name, p.getWorld()); if(le == null){ diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Worlds.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Worlds.java index 74b9e2c1..b65a1c75 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Worlds.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Worlds.java @@ -52,6 +52,7 @@ import de.relluem94.minecraft.server.spigot.essentials.helpers.WorldHelper; import de.relluem94.minecraft.server.spigot.essentials.permissions.Groups; import de.relluem94.minecraft.server.spigot.essentials.permissions.Permission; +import org.jetbrains.annotations.NotNull; public class Worlds implements CommandExecutor { @@ -120,9 +121,11 @@ public boolean onCommand(@NonNull CommandSender sender, Command command, @NonNul p.sendMessage(PLUGIN_COMMAND_WORLD_LOAD_WORLD); return true; case PLUGIN_COMMAND_NAME_WORLD_UNLOAD: - return unloadWorld(p, args[1], true); + unloadWorld(p, args[1], true); + return true; case PLUGIN_COMMAND_NAME_WORLD_UNLOAD_NO_SAVE: - return unloadWorld(p, args[1], false); + unloadWorld(p, args[1], false); + return true; case PLUGIN_COMMAND_NAME_WORLD_CREATE: default: p.sendMessage(PLUGIN_COMMAND_WORLD_CREATE_INFO); @@ -144,7 +147,7 @@ public boolean onCommand(@NonNull CommandSender sender, Command command, @NonNul return true; } - private void createWorld(Player p, String[] args){ + private void createWorld(Player p, String @NotNull [] args){ if(WorldType.getByName(args[2].toUpperCase()) != null && World.Environment.valueOf(args[3].toUpperCase()) != null && Boolean.valueOf(args[4]) != null){ WorldType type = WorldType.getByName(args[2].toUpperCase()); World.Environment worldEnvironment = World.Environment.valueOf(args[3].toUpperCase()); @@ -157,7 +160,7 @@ private void createWorld(Player p, String[] args){ } } - private boolean unloadWorld(Player p, String name, boolean save){ + private void unloadWorld(@NotNull Player p, String name, boolean save){ try { WorldHelper.unloadWorld(name, save); p.sendMessage(save ? PLUGIN_COMMAND_WORLD_UNLOAD_WORLD : PLUGIN_COMMAND_WORLD_UNLOAD_WORLD_NO_SAVE); @@ -166,7 +169,6 @@ private boolean unloadWorld(Player p, String name, boolean save){ catch (WorldNotLoadedException ex) { Logger.getLogger(Worlds.class.getName()).log(Level.SEVERE, PLUGIN_COMMAND_WORLD_WORLD_NOT_LOADED, ex); } - return true; } private void teleportWorld(Player p, String name){ diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/Constants.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/Constants.java index 83c9065e..33c1aac9 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/Constants.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/Constants.java @@ -82,6 +82,8 @@ public interface Constants { String PLUGIN_INTERNAL_UTILITY_CLASS = "This is a Utility Class"; + String PLUGIN_FOLDER_MKDIR_ERROR = "Couldn't create the Plugin Folder"; + /* ******************************************************************************* */ diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java index cf7e93d8..9c2e93ea 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java @@ -847,9 +847,6 @@ else if(ProtectionHelper.isLockAble(b)){ e.getPlayer().sendMessage(PLUGIN_EVENT_PROTECTED_BLOCK_ALLOW); } } - else{ - //Unprotected Block - } } } } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterNPC.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterNPC.java index f1c1747b..6f24a3aa 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterNPC.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterNPC.java @@ -123,8 +123,7 @@ private void trade(ItemStack is, Inventory inv, Player p, PlayerEntry pe, int sl InventoryHelper.closeInventory(p); } else if(CustomItems.npc_gui_disabled.equalsExact(is)){ - return; - // DISABLED DOES NOTHING. COULD BE AN EASTER EGG! + p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_STEP, 1f, 1f); } else if(is.getType().equals(Material.PLAYER_HEAD) && is.getItemMeta() instanceof SkullMeta && ((SkullMeta) is.getItemMeta()).getOwnerProfile() != null && ((SkullMeta) is.getItemMeta()).getOwnerProfile().getName().equals(CustomHeads.BAG.getName()) ){ BagTypeEntry bt = null; diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterSoil.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterSoil.java index e2d51192..9aacd6fb 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterSoil.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterSoil.java @@ -2,7 +2,6 @@ import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -21,7 +20,6 @@ import de.relluem94.minecraft.server.spigot.essentials.helpers.BagHelper; import de.relluem94.minecraft.server.spigot.essentials.helpers.EnchantmentHelper; import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.PlayerEntry; -import org.bukkit.scheduler.BukkitRunnable; /* Better Call Soil */ public class BetterSoil implements Listener { diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/PlayerMove.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/PlayerMove.java index b68a019d..1fc54da3 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/PlayerMove.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/PlayerMove.java @@ -23,14 +23,13 @@ public class PlayerMove implements Listener { @EventHandler public void onMove(PlayerMoveEvent e) { Player p = e.getPlayer(); - - if(p.getWorld().getName().equals(Constants.PLUGIN_WORLD_LOBBY)){ - if(e.getTo().clone().add(0, -1, 0).getBlock().getType().equals(Material.MYCELIUM)){ - if(p.isSneaking()){ + + if (p.getWorld().getName().equals(Constants.PLUGIN_WORLD_LOBBY)) { + if (e.getTo().clone().add(0, -1, 0).getBlock().getType().equals(Material.MYCELIUM)) { + if (p.isSneaking()) { p.getWorld().playEffect(p.getLocation(), Effect.BAT_TAKEOFF, 5); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_CHICKEN_STEP, 1F, 0F); - } - else{ + p.getWorld().playSound(p.getLocation(), Sound.ENTITY_CHICKEN_STEP, 1F, 0F); + } else { Vector dir = p.getLocation().getDirection().multiply(0.50); Vector vec = new Vector(dir.getX(), 2.0D, dir.getZ()); p.setVelocity(vec); @@ -42,8 +41,8 @@ public void onMove(PlayerMoveEvent e) { } } - if(RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p.getUniqueId()) != null){ + if (RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p.getUniqueId()) != null) { e.setCancelled(RelluEssentials.getInstance().getPlayerAPI().getPlayerEntry(p.getUniqueId()).isAfk()); } - } + } } \ No newline at end of file diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/SignHelper.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/SignHelper.java index df61a03b..5d6d4493 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/SignHelper.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/SignHelper.java @@ -11,6 +11,8 @@ import org.bukkit.block.data.type.WallSign; import de.relluem94.minecraft.server.spigot.essentials.exceptions.SignMissingCustomInputException; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; /** * @@ -24,7 +26,7 @@ public class SignHelper { private final ActionType signActionType; - public SignHelper(ActionType signActionType, String customInput) { + public SignHelper(@NotNull ActionType signActionType, String customInput) { this.signActionType = signActionType; this.line1 = signActionType.getDisplayName(); if (signActionType.isCustomInput()) { @@ -34,7 +36,7 @@ public SignHelper(ActionType signActionType, String customInput) { } } - public SignHelper(ActionType signActionType) throws SignMissingCustomInputException { + public SignHelper(@NotNull ActionType signActionType) throws SignMissingCustomInputException { this.signActionType = signActionType; this.line1 = signActionType.getDisplayName(); this.line2 = ""; @@ -51,15 +53,15 @@ public String getLine3() { return PLUGIN_SIGN_CLICK; } - public static boolean isSign(SignHelper sh, String line0, String line1, String line3) { + public static boolean isSign(@NotNull SignHelper sh, String line0, String line1, String line3) { return sh.getLine0().equals(line0) && sh.getLine1().equals(line1) && sh.getLine3().equals(line3); } - public static boolean isSign(SignHelper sh, String line1) { + public static boolean isSign(@NotNull SignHelper sh, String line1) { return sh.getSignActionType().getShorthand().equals(line1) || sh.getSignActionType().getName().equalsIgnoreCase(line1); } - public static boolean isBlockASign(Block b){ + public static boolean isBlockASign(@NotNull Block b){ return ( b.getBlockData() instanceof WallSign || b.getBlockData() instanceof Sign || @@ -88,11 +90,13 @@ public enum ActionType { } - public String getShorthand() { + @Contract(pure = true) + public @NotNull String getShorthand() { return "[" + id + "]"; } - public String getName() { + @Contract(pure = true) + public @NotNull String getName() { return "[" + this.name() + "]"; } } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/ConfigManager.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/ConfigManager.java index 26680741..460803f4 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/ConfigManager.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/ConfigManager.java @@ -4,15 +4,20 @@ import static de.relluem94.minecraft.server.spigot.essentials.helpers.ChatHelper.consoleSendMessage; import de.relluem94.minecraft.server.spigot.essentials.RelluEssentials; +import org.bukkit.plugin.InvalidPluginException; public class ConfigManager implements IEnable, IDisable { @Override - public void enable() { + public void enable() throws InvalidPluginException { consoleSendMessage(PLUGIN_NAME_CONSOLE, PLUGIN_COLOR_COMMAND + PLUGIN_MANAGER_LOADING_CONFIGS); - if (!RelluEssentials.getInstance().getDataFolder().exists()) { - RelluEssentials.getInstance().getDataFolder().mkdir(); + if (RelluEssentials.getInstance().getDataFolder().exists()) { + return; + } + + if(!RelluEssentials.getInstance().getDataFolder().mkdir()){ + throw new InvalidPluginException(PLUGIN_FOLDER_MKDIR_ERROR); } RelluEssentials.getInstance().saveDefaultConfig(); diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/IEnable.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/IEnable.java index b8774f71..0f0ac4d9 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/IEnable.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/managers/IEnable.java @@ -1,5 +1,7 @@ package de.relluem94.minecraft.server.spigot.essentials.managers; +import org.bukkit.plugin.InvalidPluginException; + public interface IEnable { - void enable(); + void enable() throws InvalidPluginException; } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/permissions/Groups.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/permissions/Groups.java index e11c267b..3784dfe9 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/permissions/Groups.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/permissions/Groups.java @@ -4,6 +4,8 @@ import de.relluem94.minecraft.server.spigot.essentials.constants.Constants; import de.relluem94.minecraft.server.spigot.essentials.helpers.pojo.GroupEntry; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @@ -21,22 +23,27 @@ private Groups() { * @param name String * @return GroupEntry */ - public static GroupEntry getGroup(String name) { + public static @NotNull GroupEntry getGroup(String name) { for (GroupEntry ge : RelluEssentials.getInstance().groupEntryList) { if (ge.getName().equalsIgnoreCase(name)) { return ge; } } - return getGroup("user"); + if(!groupExists("user")){ + return new GroupEntry(1, "user", "ยง8"); + } + else{ + return getGroup("user"); + } } public static boolean groupExists(String name) { for (GroupEntry ge : RelluEssentials.getInstance().groupEntryList) { if (ge.getName().equalsIgnoreCase(name)) { - return true; + return false; } } - return false; + return true; } /** * Returns a GroupEntry if a Group is found by id
@@ -45,7 +52,7 @@ public static boolean groupExists(String name) { * @param id int * @return GroupEntry */ - public static GroupEntry getGroup(int id) { + public static @Nullable GroupEntry getGroup(int id) { for (GroupEntry ge : RelluEssentials.getInstance().groupEntryList) { if (ge.getId() == id) { return ge; @@ -61,8 +68,8 @@ public static GroupEntry getGroup(int id) { * @return boolean */ @SuppressWarnings("unused") - public static boolean addGroup(GroupEntry groupEntry) { - if (!groupExists(groupEntry.getName())) { + public static boolean addGroup(@NotNull GroupEntry groupEntry) { + if (groupExists(groupEntry.getName())) { RelluEssentials.getInstance().getDatabaseHelper().insertGroup(groupEntry); RelluEssentials.getInstance().groupEntryList.addAll(RelluEssentials.getInstance().getDatabaseHelper().getGroups()); return true;