Skip to content

Commit

Permalink
[CORE] SonarLint Remarks. Mark GriefPreventionProtection as Deprecate…
Browse files Browse the repository at this point in the history
…d for now

Signed-off-by: Wolfieheart <[email protected]>
  • Loading branch information
Wolfieheart committed Jan 24, 2023
1 parent 84d853e commit 0ea8ca4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ target/
/src/main/java/META-INF/*.MF
/src/main/java/META-INF/
/TODO-LIST.MD
/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;

public class ArmorStandEditorPlugin extends JavaPlugin{

Expand All @@ -52,6 +53,8 @@ public class ArmorStandEditorPlugin extends JavaPlugin{

//Server Version Detection: Paper or Spigot and Invalid NMS Version
String nmsVersion;
String languageFolderLocation = "lang/";
String warningMCVer = "Minecraft Version: ";
public boolean hasSpigot = false;
public boolean hasPaper = false;
String nmsVersionNotLatest = null;
Expand Down Expand Up @@ -117,7 +120,7 @@ public void onEnable() {
nmsVersion.startsWith("v1_11") ||
nmsVersion.startsWith("v1_12") ||
nmsVersion.startsWith("v1_13")){
getLogger().warning("Minecraft Version: " + nmsVersion + " is not supported. Loading Plugin Failed.");
getLogger().log(Level.WARNING,"Minecraft Version: {0} is unsupported. Please Update Immediately. Loading failed.",nmsVersion);
getLogger().info(SEPARATOR_FIELD);
getServer().getPluginManager().disablePlugin(this);
return;
Expand All @@ -130,10 +133,10 @@ public void onEnable() {
nmsVersion.startsWith("v1_17") ||
nmsVersion.startsWith("v1_18") ){
//Revert NMS Check for any 1.19 Version
getLogger().warning("Minecraft Version: " + nmsVersion + " is supported, but not latest.");
getLogger().warning("ArmorStandEditor will still work, but please update to the latest Version of " + nmsVersionNotLatest + ". Loading continuing.");
getLogger().log(Level.WARNING,"Minecraft Version: {0} is supported, but not latest.",nmsVersion);
getLogger().log(Level.WARNING, "ArmorStandEditor will still work on your current version. Loading Continuing.");
} else {
getLogger().info("Minecraft Version: " + nmsVersion + " is supported. Loading continuing.");
getLogger().log(Level.INFO, "Minecraft Version: {0} is supported. Loading Continuing.",nmsVersion);
}
//Spigot Check
hasSpigot = getHasSpigot();
Expand All @@ -147,9 +150,10 @@ public void onEnable() {
return;
} else {
if (hasSpigot) {
getLogger().info("SpigotMC: " + hasSpigot);
getLogger().log(Level.INFO,"SpigotMC: {0}",hasSpigot);
//getLogger().info("SpigotMC: " + hasSpigot);
} else {
getLogger().info("PaperMC: " + hasPaper);
getLogger().log(Level.INFO,"PaperMC: {0}",hasPaper);
}
}

Expand All @@ -159,17 +163,17 @@ public void onEnable() {

//saveResource doesn't accept File.separator on Windows, need to hardcode unix separator "/" instead
updateConfig("", "config.yml");
updateConfig("lang/", "test_NA.yml");
updateConfig("lang/", "nl_NL.yml");
updateConfig("lang/", "uk_UA.yml");
updateConfig("lang/", "ru_RU.yml");
updateConfig("lang/", "zh_CN.yml");
updateConfig("lang/", "fr_FR.yml");
updateConfig("lang/", "ro_RO.yml");
updateConfig("lang/", "ja_JP.yml");
updateConfig("lang/", "de_DE.yml");
updateConfig("lang/", "es_ES.yml");
updateConfig("lang/", "pt_BR.yml");
updateConfig(languageFolderLocation, "test_NA.yml");
updateConfig(languageFolderLocation, "nl_NL.yml");
updateConfig(languageFolderLocation, "uk_UA.yml");
updateConfig(languageFolderLocation, "ru_RU.yml");
updateConfig(languageFolderLocation, "zh_CN.yml");
updateConfig(languageFolderLocation, "fr_FR.yml");
updateConfig(languageFolderLocation, "ro_RO.yml");
updateConfig(languageFolderLocation, "ja_JP.yml");
updateConfig(languageFolderLocation, "de_DE.yml");
updateConfig(languageFolderLocation, "es_ES.yml");
updateConfig(languageFolderLocation, "pt_BR.yml");

//English is the default language and needs to be unaltered to so that there is always a backup message string
saveResource("lang/en_US.yml", true);
Expand Down Expand Up @@ -392,7 +396,6 @@ public boolean isEditTool(ItemStack itemStk){
if (editTool != itemStk.getType()) { return false; }

//FIX: Depreciated Stack for getDurability
// if(requireToolData && item.getDurability() != (short)editToolData) return false;
if (requireToolData){
Damageable d1 = (Damageable) itemStk.getItemMeta(); //Get the Damageable Options for itemStk
if (d1 != null) { //We do this to prevent NullPointers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class PlayerEditor {
int frameTargetIndex = 0;
EquipmentMenu equipMenu;
long lastCancelled = 0;
private boolean state;

public PlayerEditor(UUID uuid, ArmorStandEditorPlugin plugin) {
this.uuid = uuid;
Expand Down Expand Up @@ -171,6 +170,10 @@ public void editArmorStand(ArmorStand armorStand) {
case NONE:
sendMessage("nomode", null);
break;
default:
sendMessage("nomode", null);
break;

}
}

Expand All @@ -182,9 +185,13 @@ public void editItemFrame(ItemFrame itemFrame) {
break;
case RESET:
itemFrame.setVisible(true);
break;
case NONE:
sendMessage("nomodeif", null);
break;
default:
sendMessage("nomodeif", null);
break;
}
}

Expand Down Expand Up @@ -500,7 +507,7 @@ ArmorStand attemptTarget(ArmorStand armorStand) {
void sendMessage(String path, String format, String option) {
String message = plugin.getLang().getMessage(path, format, option);
if (plugin.sendToActionBar) {
if (ArmorStandEditorPlugin.instance().hasSpigot || ArmorStandEditorPlugin.instance().hasPaper) { //Paper and Spigot having the same Interaction for sendToActionBar
if (ArmorStandEditorPlugin.instance().getHasPaper() || ArmorStandEditorPlugin.instance().getHasSpigot()) { //Paper and Spigot having the same Interaction for sendToActionBar
plugin.getServer().getPlayer(getUUID()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else {
String rawText = plugin.getLang().getRawMessage(path, format, option);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.common.collect.ImmutableList;
import io.github.rypofalem.armorstandeditor.menu.ASEHolder;
import io.github.rypofalem.armorstandeditor.protections.*;
import me.ryanhamshire.GriefPrevention.GriefPrevention;

import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -60,7 +60,8 @@ public class PlayerEditorManager implements Listener {
// Instantiate protections used to determine whether a player may edit an armor stand or item frame
private final List<Protection> protections = ImmutableList.of(
new GriefDefenderProtection(), new GriefPreventionProtection(), new LandsProtection(),
new PlotSquaredProtection(), new SkyblockProtection(), new TownyProtection(), new WorldGuardProtection());
new PlotSquaredProtection(), new SkyblockProtection(), new TownyProtection(), new WorldGuardProtection(),
new BentoBoxProtection());

PlayerEditorManager( ArmorStandEditorPlugin plugin) {
this.plugin = plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class GriefDefenderProtection implements Protection {

public GriefDefenderProtection() {
gdEnabled = Bukkit.getPluginManager().isPluginEnabled("GriefDefender");
if(!gdEnabled) return;
}

public boolean checkPermission(Block block, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

/** @deprecated **/

public class GriefPreventionProtection implements Protection {

private boolean gpEnabled;
private GriefPrevention griefPrevention = null;

/** @deprecated **/
public GriefPreventionProtection(){
gpEnabled = Bukkit.getPluginManager().isPluginEnabled("GriefPrevention");

if(!gpEnabled) return;
griefPrevention = (GriefPrevention) Bukkit.getPluginManager().getPlugin("GriefPrevention");
}

/** @deprecated **/
public boolean checkPermission(Block block, Player player){
if(!gpEnabled) return true;
if(player.hasPermission("asedit.ignoreProtection.griefPrevention")) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.land.Area;
import me.angeschossen.lands.api.land.Land;
import me.angeschossen.lands.api.player.LandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -33,12 +32,12 @@ public boolean checkPermission(Block block, Player player) {
//Get the Area that the block is in
Area area = land.getArea(block.getLocation());

//Get the Lands Player
LandPlayer lPlayer = lands.getLandPlayer(player.getUniqueId());

//Return if Trusted in the area or not either based on BukktiPlayer or LandsPlayer
return area == null ? area.isTrusted(player.getUniqueId()) : area.isTrusted(lPlayer.getUID());
if(area != null)

//Return if Trusted in the area or not either based on BukkitPlayer
return area.isTrusted(player.getUniqueId());
else
return false;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class TownyProtection implements Protection {

public TownyProtection(){
tEnabled = Bukkit.getPluginManager().isPluginEnabled("Towny");
if(!tEnabled) return;
}

public boolean checkPermission(Block block, Player player){
Expand All @@ -27,9 +26,7 @@ public boolean checkPermission(Block block, Player player){
Location playerLoc = player.getLocation();

if (TownyAPI.getInstance().isWilderness(playerLoc)) return false;
if (!TownyActionEventExecutor.canDestroy(player, block.getLocation(), Material.ARMOR_STAND)) return false;

return true;
return TownyActionEventExecutor.canDestroy(player, block.getLocation(), Material.ARMOR_STAND);
}
}

0 comments on commit 0ea8ca4

Please sign in to comment.