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

Support minimal dimension colouring #21

Merged
merged 5 commits into from
Sep 18, 2023
Merged
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
40 changes: 32 additions & 8 deletions src/main/java/com/jewelexx/tablocation/TabLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@

import com.jewelexx.craftcolours.CraftColours;

enum ShowDimension {
Minimal,
Expanded,
False,
}

public final class TabLocation extends JavaPlugin implements Listener {
static final Logger log = Bukkit.getLogger();
static boolean environmentEnabled;
static ShowDimension environmentEnabled;
static boolean locationEnabled;
static FileConfiguration config;
final String version = getDescription().getVersion();
Expand All @@ -36,7 +42,16 @@ public void onEnable() {

config = getConfig();

environmentEnabled = config.getBoolean("Show dimension");
String showDimension = config.getString("Show dimension");

if (showDimension.equals("minimal")) {
environmentEnabled = ShowDimension.Minimal;
} else if (showDimension.equals("true")) {
environmentEnabled = ShowDimension.Expanded;
} else {
environmentEnabled = ShowDimension.False;
}

locationEnabled = config.getBoolean("Show location");

manager.registerEvents(this, this);
Expand Down Expand Up @@ -98,13 +113,16 @@ static void updateLocation(Player player) {
}

protected static String getLoc(Player player) {
if ((!locationEnabled && !environmentEnabled) || player.hasPermission("tablocation.hide")) {
if ((!locationEnabled && environmentEnabled == ShowDimension.False)
|| player.hasPermission("tablocation.hide")) {
return "";
}

String colourcode = CraftColours.WHITE;

String world = "";

if (environmentEnabled) {
if (environmentEnabled != ShowDimension.False) {
Environment environment = player.getWorld().getEnvironment();

switch (environment) {
Expand All @@ -122,9 +140,15 @@ protected static String getLoc(Player player) {
break;
}

String colourcode = config.getString("Colour for The " + world);
String dimensionColourCode = config.getString("Colour for The " + world);

world = colourcode + "The " + world + CraftColours.RESET;
if (environmentEnabled == ShowDimension.Expanded) {
world = dimensionColourCode + "The " + world + CraftColours.RESET;
} else {
colourcode = dimensionColourCode;
// Hide `world` variable if displaying minimal
world = "";
}
}

String location = "";
Expand All @@ -139,10 +163,10 @@ protected static String getLoc(Player player) {

String separator = "";

if (locationEnabled && environmentEnabled) {
if (locationEnabled && environmentEnabled == ShowDimension.Expanded) {
separator = ", ";
}

return " " + CraftColours.WHITE + "[" + location + separator + world + "]";
return " " + colourcode + "[" + CraftColours.WHITE + location + separator + world + colourcode + "]";
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Show the dimension player's current dimension
# Show the player's current dimension (false, true or minimal)
Show dimension: true
# Show the exact coordinates of the player
Show location: true
Expand Down
Loading