Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to hide coordinates from command output #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/de/jeff_media/InvUnload/CommandSearchitem.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
}

summary.print(UnloadSummary.PrintRecipient.PLAYER, p);
if (main.canSeeCoordinates(p)) {
summary.print(UnloadSummary.PrintRecipient.PLAYER, p);
}

if(affectedChests.size()==0) {
p.sendMessage(String.format(main.messages.MSG_NOTHING_FOUND,mat.name()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/jeff_media/InvUnload/CommandUnload.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
}
}
if(main.getConfig().getBoolean("always-show-summary")) {
if(main.getConfig().getBoolean("always-show-summary") && main.canSeeCoordinates(p)) {
summary.print(PrintRecipient.PLAYER, p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if(laser.isStarted()) laser.stop();
}
}*/
if(main.visualizer.unloadSummaries.containsKey(p.getUniqueId())) {
if(main.visualizer.unloadSummaries.containsKey(p.getUniqueId()) && main.canSeeCoordinates(p)) {
UnloadSummary summary = main.visualizer.unloadSummaries.get(p.getUniqueId());
if(summary!=null) {
summary.print(PrintRecipient.PLAYER, p);
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/de/jeff_media/InvUnload/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import de.jeff_media.InvUnload.utils.EnchantmentUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -30,7 +32,7 @@ public class Main extends JavaPlugin implements Listener {
int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ...

@SuppressWarnings("FieldCanBeLocal")
private final int currentConfigVersion = 34;
private final int currentConfigVersion = 37;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new config version is set to 37 instead of just incremented by one because the latest version (5.0.2) published on spigot.org has it set to 36. It looks like the code in repo doesn't contain changes from the v5.0.2.


public Messages messages;
protected BlockUtils blockUtils;
Expand Down Expand Up @@ -173,6 +175,7 @@ private void setDefaultConfigValues() {
getConfig().addDefault("particle-count", 100);

getConfig().addDefault("always-show-summary", true);
getConfig().addDefault("show-coordinates", "default");

getConfig().addDefault("laser-animation", true);
getConfig().addDefault("laser-default-duration", 5);
Expand Down Expand Up @@ -284,4 +287,28 @@ private void saveAllPlayerSettings() {
}
}

/**
* Determines if given command sender can see coordinates of the chests in command output.
*/
public boolean canSeeCoordinates(CommandSender commandSender) {
if (commandSender.hasPermission("invunload.coordinates")) {
return true;
}

// Get reducedDebugInfo gamerule value.
boolean reducedDebugInfo = false;
if (commandSender instanceof Player) {
reducedDebugInfo = ((Player) commandSender).getWorld().getGameRuleValue(GameRule.REDUCED_DEBUG_INFO);
}

// By default, use reducedDebugInfo gamerule to decide if coordinates should be displayed.
if (this.getConfig().getString("show-coordinates").equals("default")) {
return !reducedDebugInfo;
}

// If show-coordinates config value is not set to 'default'
// ignore the gamerule and use configured boolean value.
return this.getConfig().getBoolean("show-coordinates");
}

}
3 changes: 3 additions & 0 deletions src/main/java/de/jeff_media/InvUnload/Visualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void run() {
}

void printSummaryToPlayer(Player p) {
if (!main.canSeeCoordinates(p)) {
return;
}
UnloadSummary summary = unloadSummaries.get(p.getUniqueId());
if(summary==null) return;
summary.print(PrintRecipient.PLAYER, p);
Expand Down
16 changes: 12 additions & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
####### Permissions #######
###############################

# invunload.use: Allows to use the commands /unload, /dump, /unloadinfo, /blacklist
# invunload.reload: Allows to reload the config using /unload reload
# invunload.search: Allows to use the command /searchitem
# invunload.use: Allows to use the commands /unload, /dump, /unloadinfo, /blacklist
# invunload.reload: Allows to reload the config using /unload reload
# invunload.search: Allows to use the command /searchitem
# invunload.coordinates: Allows to always see coordinates even when they are disabled in configuration

###############################
####### General config #######
Expand Down Expand Up @@ -113,6 +114,13 @@ sound-effect: ENTITY_PLAYER_LEVELUP
# When set to false, the summary is only shown when using /unloadinfo (or /dumpinfo).
always-show-summary: true

# Determines if coordinates should be shown in the text summaries and the output of the /searchitem command.
# Can be overridden for specific player/group by granting 'invunload.coordinates' permission.
# When set to default coordinates will be shown/hidden based on the reducedDebugInfo gamerule value.
# When set to true the gamerule will be ignored and coordinates will be shown.
# When set to false the gamerule will be ignored and coordinates will be hidden.
show-coordinates: default

# When set to true, InvUnload will draw the laser beam everytime you /unload or /dump
# When set to false, InvUnload only draws the laser beam on /unloadinfo and /search
laser-animation: false
Expand Down Expand Up @@ -499,4 +507,4 @@ message-cooldown: "&cPlease wait a moment before running the command again."
debug: false

# please do not change the following line manually!
config-version: 35
config-version: 37
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ permissions:
description: Allows usage of the /searchitem command
invunload.reload:
description: Allows to reload the config using /unload reload
invunload.coordinates:
descrition: Allows to see coordinates even when they are disabled in configuration.