Skip to content

Commit

Permalink
[CORE] Fix Folia Leftoever, Fix P2 Protection and add Debug in a few …
Browse files Browse the repository at this point in the history
…places.

Signed-off-by: Wolfieheart <[email protected]>
  • Loading branch information
Wolfieheart committed Oct 15, 2023
1 parent f54fba8 commit 9460cd6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ArmorStandEditorPlugin extends JavaPlugin {
public boolean hasFolia = false;
String nmsVersionNotLatest = null;
PluginDescriptionFile pdfFile = this.getDescription();
static final String SEPARATOR_FIELD = "================================";
public static final String SEPARATOR_FIELD = "================================";

public PlayerEditorManager editorManager;

Expand Down Expand Up @@ -102,6 +102,9 @@ public class ArmorStandEditorPlugin extends JavaPlugin {
public Team team;
String lockedTeam = "ASLocked";

//Debugging Options.... Not Exposed
boolean debugFlag;

private static ArmorStandEditorPlugin plugin;

public ArmorStandEditorPlugin() {
Expand Down Expand Up @@ -264,6 +267,15 @@ public void onEnable() {

adminOnlyNotifications = getConfig().getBoolean("adminOnlyNotifications", true);

debugFlag = getConfig().getBoolean("debugFlag", false);
if(debugFlag){
getServer().getLogger().warning(ArmorStandEditorPlugin.SEPARATOR_FIELD);
getServer().getLogger().warning(" ArmorStandEditor - Debug Mode ");
getServer().getLogger().warning(" Debug Mode: ENABLED! ");
getServer().getLogger().warning(" USE THIS FOR DEVELOPMENT PURPOSES ONLY! ");
getServer().getLogger().warning(ArmorStandEditorPlugin.SEPARATOR_FIELD);
}

//Run UpdateChecker - Reports out to Console on Startup ONLY!
if (!hasFolia && runTheUpdateChecker) {

Expand Down Expand Up @@ -396,6 +408,9 @@ public boolean getHasPaper() {
}
}

public boolean getHasFolia() {
return Scheduler.isFolia();
}

public String getArmorStandEditorVersion() {
return getConfig().getString("version");
Expand Down Expand Up @@ -510,9 +525,7 @@ public boolean isEditTool(ItemStack itemStk) {
}
return true;
}


public void performReload() {
public void performReload() {

//Unregister Scoreboard before before performing the reload
if (!hasFolia) {
Expand Down Expand Up @@ -692,4 +705,14 @@ public NamespacedKey getIconKey() {
return iconKey;
}

/**
* For debugging ASE - Do not use this outside of Development or stuff
*/
public boolean isDebug() {
return debugFlag;
}

public void debugMsgHandler(String msg){
if(isDebug()) getServer().getLogger().log(Level.WARNING, "[ASE-DEBUG]: {0}", msg);
}
}
20 changes: 16 additions & 4 deletions src/main/java/io/github/rypofalem/armorstandeditor/CommandEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public CommandEx(ArmorStandEditorPlugin armorStandEditorPlugin) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (sender instanceof ConsoleCommandSender) { //Fix to Support #267
if(plugin.isDebug()) plugin.debugMsgHandler("Sender is CONSOLE!");
if (args.length == 0) {
sender.sendMessage(VERSION);
sender.sendMessage(HELP);
Expand All @@ -93,11 +94,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

if (sender instanceof Player player && !getPermissionBasic(player)) {
if(plugin.isDebug()) plugin.debugMsgHandler("Sender is Player but asedit.basic is" + getPermissionBasic(player));
sender.sendMessage(plugin.getLang().getMessage("nopermoption", "warn", "basic"));
return true;
} else {

Player player = (Player) sender;

if(plugin.isDebug()) plugin.debugMsgHandler("Sender is Player and asedit.basic is" + getPermissionBasic(player));
if (args.length == 0) {
player.sendMessage(LISTMODE);
player.sendMessage(LISTAXIS);
Expand Down Expand Up @@ -161,6 +164,7 @@ private void commandGive(Player player) {
}

private void commandGivePlayerHead(Player player, String[] args) {

if (plugin.getAllowedToRetrievePlayerHead() && checkPermission(player, "head", true)) {

if (args.length == 2) {
Expand Down Expand Up @@ -309,6 +313,7 @@ private void commandMode(Player player, String[] args) {
if (args[1].equals("invisible") && !(checkPermission(player, "togglearmorstandvisibility", true) || plugin.getArmorStandVisibility())) return;
if (args[1].equals("itemframe") && !(checkPermission(player, "toggleitemframevisibility", true) || plugin.getItemFrameVisibility())) return;
plugin.editorManager.getPlayerEditor(player.getUniqueId()).setMode(mode);
if(plugin.isDebug()) plugin.debugMsgHandler(player.getDisplayName() + " chose the mode: " + mode);
return;
}
}
Expand Down Expand Up @@ -339,13 +344,14 @@ private void commandUpdate(Player player) {
if (!(checkPermission(player, "update", true))) return;

//Only Run if the Update Command Works
if (plugin.isDebug()) plugin.debugMsgHandler("Current ArmorStandEditor Version is: " + plugin.getArmorStandEditorVersion());
if (plugin.getArmorStandEditorVersion().contains(".x")) {
player.sendMessage(ChatColor.YELLOW + "[ArmorStandEditor] Update Checker will not work on Development Versions.");
player.sendMessage(ChatColor.YELLOW + "[ArmorStandEditor] Report all bugs to: https://github.com/Wolfieheart/ArmorStandEditor/issues");
} else {
if (!Scheduler.isFolia() && plugin.getRunTheUpdateChecker()) {
if (!plugin.getHasFolia() && plugin.getRunTheUpdateChecker()) {
new UpdateChecker(plugin, UpdateCheckSource.SPIGOT, "" + ArmorStandEditorPlugin.SPIGOT_RESOURCE_ID + "").checkNow(player); //Runs Update Check
} else if (Scheduler.isFolia()) {
} else if (plugin.getHasFolia()) {
player.sendMessage(ChatColor.YELLOW + "[ArmorStandEditor] Update Checker does not currently work on Folia.");
player.sendMessage(ChatColor.YELLOW + "[ArmorStandEditor] Report all bugs to: https://github.com/Wolfieheart/ArmorStandEditor/issues");
} else {
Expand All @@ -355,6 +361,8 @@ private void commandUpdate(Player player) {
}

private void commandVersion(Player player) {
if (plugin.isDebug()) plugin.debugMsgHandler(player.getDisplayName() + " permission check for asedit.update: " + getPermissionUpdate(player));

if (!(getPermissionUpdate(player))) return;
String verString = plugin.getArmorStandEditorVersion();
player.sendMessage(ChatColor.YELLOW + "[ArmorStandEditor] Version: " + verString);
Expand All @@ -366,6 +374,8 @@ private void commandVersionConsole(CommandSender sender) {
}

private void commandReload(Player player) {
if (plugin.isDebug()) plugin.debugMsgHandler(player.getDisplayName() + " permission check for asedit.reload: " + getPermissionReload(player));

if (!(getPermissionReload(player))) return;
plugin.performReload();
player.sendMessage(plugin.getLang().getMessage("reloaded", ""));
Expand All @@ -377,6 +387,8 @@ private void commandReloadConsole(CommandSender sender) {
}

private void commandStats(Player player) {
if (plugin.isDebug()) plugin.debugMsgHandler(player.getDisplayName() + " permission check for asedit.stats: " + getPermissionStats(player));

if(getPermissionStats(player)) {
for (Entity e : player.getNearbyEntities(1, 1, 1)) {
if (e instanceof ArmorStand as) {
Expand Down Expand Up @@ -482,7 +494,7 @@ private void commandStats(Player player) {
player.sendMessage(ChatColor.YELLOW + "Left Arm: " + ChatColor.AQUA + leftArmX + " / " + leftArmY + " / " + leftArmZ);
player.sendMessage(ChatColor.YELLOW + "Right Leg: " + ChatColor.AQUA + rightLegX + " / " + rightLegY + " / " + rightLegZ);
player.sendMessage(ChatColor.YELLOW + "Left Leg: " + ChatColor.AQUA + leftLegX + " / " + leftLegY + " / " + leftLegZ);
player.sendMessage(ChatColor.YELLOW + "Coordinates: " + ChatColor.AQUA + " x: " + locationX + " / y: " + locationY + " / z: " + locationZ);
player.sendMessage(ChatColor.YELLOW + "Coordinates: " + ChatColor.AQUA + " X: " + locationX + " / Y: " + locationY + " / Z: " + locationZ);
player.sendMessage(ChatColor.YELLOW + "Is Visible: " + ChatColor.AQUA + isVisible + ". " + ChatColor.YELLOW + "Arms Visible: " + ChatColor.AQUA + armsVisible + ". " + ChatColor.YELLOW + "Base Plate Visible: " + ChatColor.AQUA + basePlateVisible);
player.sendMessage(ChatColor.YELLOW + "Is Vulnerable: " + ChatColor.AQUA + isVulnerable + ". " + ChatColor.YELLOW + "Affected by Gravity: " + ChatColor.AQUA + hasGravity);
player.sendMessage(ChatColor.YELLOW + "Is Small: " + ChatColor.AQUA + isSmall + ". " + ChatColor.YELLOW + "Is Glowing: " + ChatColor.AQUA + isGlowing + ". " + ChatColor.YELLOW + "Is Locked: " + ChatColor.AQUA + isLocked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void runTaskLater(Plugin plugin, Runnable runnable, long delayedTi
}

public static void teleport(Entity entity, Location location) {
if (IS_FOLIA) callMethod(Entity.class, entity, "teleportAsync", new Class[]{Location.class}, location);
if (isFolia()) callMethod(Entity.class, entity, "teleportAsync", new Class[]{Location.class}, location);
else entity.teleport(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ public boolean checkPermission(Block block, Player player) {
if (player.hasPermission("asedit.ignoreProtection.plotSquared")) return true;
if (plotAPI == null) plotAPI = new PlotAPI();

//Get the Location of the Plot
Location plotLocation = Location.at(player.getWorld().getName(), BlockVector3.at(block.getX(), block.getY(), block.getZ()));
//Get the Location of the Plot
Location plotLocation = Location.at(block.getWorld().getName(), BlockVector3.at(block.getX(), block.getY(), block.getZ()));

//Get the Area of the PLot
PlotArea area = plotLocation.getPlotArea();

//If the Area is not a Plot, then we assume its a road, we return if a player can build on roads or not
if(area == null)
return player.hasPermission("plots.admin.build.road");
if(area == null) return true;

//Get the Plot
Plot plot = area.getPlot(plotLocation);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ allowedToRetrievePlayerHead: false
#Each time the command is used, the admins will be notified that this has been ran but only
#if this setting is made true
adminOnlyNotifications: false

#Debug Mode - For Development and Support Purposes ONLY!
# Do Not Enable. Will Generate ALOT OF NOISE in your Log Files
debugFlag: false
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ permissions:
asedit.copy: true
asedit.paste: true
asedit.reset: true
asedit.stats: true
asedit.toggleInvulnerability: true
asedit.togglebaseplate: true
asedit.togglearms: true
Expand Down

0 comments on commit 9460cd6

Please sign in to comment.