Skip to content

Commit d9e1faa

Browse files
committed
v1.1
1 parent e686cab commit d9e1faa

File tree

9 files changed

+166
-13
lines changed

9 files changed

+166
-13
lines changed

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'dev.letsgoaway'
6-
version = '1.0'
6+
version = '1.1'
77

88
repositories {
99
mavenCentral()
@@ -39,6 +39,12 @@ tasks.withType(JavaCompile).configureEach {
3939
}
4040
}
4141

42+
tasks {
43+
jar {
44+
archiveFileName = "MapXYZ.jar"
45+
}
46+
}
47+
4248
processResources {
4349
def props = [version: version]
4450
inputs.properties props

src/main/java/dev/letsgoaway/mapxyz/Config.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77

88
public class Config {
99
//region DEFAULTS
10+
public static boolean enableXYZDisplay = true;
11+
1012
public static boolean enableStartingMap = true;
1113

1214
public static boolean useLegacyConsoleDefaultZoom = true;
1315

1416
public static boolean enableReducedDebugInfo = true;
1517

18+
public static boolean enableLocatorMaps = true;
19+
1620
public static boolean useEyeLevelPosition = false;
1721
//endregion
1822

1923
private static FileConfiguration config;
2024

2125
private static void updateValues() {
26+
if (config.contains("enable-xyz-display", true)) {
27+
enableXYZDisplay = config.getBoolean("enable-xyz-display");
28+
}
29+
2230
if (config.contains("enable-starting-map", true)) {
2331
enableStartingMap = config.getBoolean("enable-starting-map");
2432
}
@@ -31,6 +39,10 @@ private static void updateValues() {
3139
enableReducedDebugInfo = config.getBoolean("enable-reduced-debug-info");
3240
}
3341

42+
if (config.contains("enable-locator-maps", true)) {
43+
enableLocatorMaps = config.getBoolean("enable-locator-maps");
44+
}
45+
3446
if (config.contains("use-eye-level-position", true)) {
3547
useEyeLevelPosition = config.getBoolean("use-eye-level-position");
3648
}
@@ -39,9 +51,11 @@ private static void updateValues() {
3951
}
4052

4153
private static void saveValues() {
54+
config.set("enable-xyz-display", enableXYZDisplay);
4255
config.set("enable-starting-map", enableStartingMap);
4356
config.set("use-legacy-console-default-zoom", useLegacyConsoleDefaultZoom);
4457
config.set("enable-reduced-debug-info", enableReducedDebugInfo);
58+
config.set("enable-locator-maps", enableLocatorMaps);
4559
config.set("use-eye-level-position", useEyeLevelPosition);
4660
try {
4761
config.save(MapXYZ.instance.getDataFolder().toPath().resolve("config.yml").toFile());

src/main/java/dev/letsgoaway/mapxyz/MapXYZ.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package dev.letsgoaway.mapxyz;
22

3-
import org.bukkit.Bukkit;
4-
import org.bukkit.GameRule;
5-
import org.bukkit.Material;
6-
import org.bukkit.World;
3+
import org.bukkit.*;
74
import org.bukkit.event.EventHandler;
85
import org.bukkit.event.Listener;
96
import org.bukkit.event.entity.EntityPickupItemEvent;
@@ -13,9 +10,11 @@
1310
import org.bukkit.event.player.PlayerJoinEvent;
1411
import org.bukkit.event.server.MapInitializeEvent;
1512
import org.bukkit.inventory.ItemStack;
13+
import org.bukkit.inventory.meta.ItemMeta;
1614
import org.bukkit.inventory.meta.MapMeta;
1715
import org.bukkit.map.MapRenderer;
1816
import org.bukkit.map.MapView;
17+
import org.bukkit.persistence.PersistentDataType;
1918
import org.bukkit.plugin.java.JavaPlugin;
2019

2120
import java.io.IOException;

src/main/java/dev/letsgoaway/mapxyz/MapXYZCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class MapXYZCommand implements CommandExecutor {
99
@Override
1010
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
11-
if (sender.isOp()) {
11+
if (sender.hasPermission("mapxyz.command")) {
1212
Config.reload();
1313
sender.sendMessage("MapXYZ successfully reloaded!");
1414
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.letsgoaway.mapxyz;
2+
3+
public class MathUtils {
4+
public static boolean between(float x, float min, float max) {
5+
return x >= min && x <= max;
6+
}
7+
8+
public static boolean between(double x, double min, double max) {
9+
return x >= min && x <= max;
10+
}
11+
12+
public static boolean between(int x, int min, int max) {
13+
return x >= min && x <= max;
14+
}
15+
16+
/**
17+
* If number is greater than the max, set it to max, and if number is lower than low, set it to low.
18+
*
19+
* @param num number to calculate
20+
* @param min the lowest value the number can be
21+
* @param max the greatest value the number can be
22+
* @return - min if num is lower than min <br>
23+
* - max if num is greater than max <br>
24+
* - num otherwise
25+
*/
26+
public static float constrain(float num, float min, float max) {
27+
if (num > max) {
28+
num = max;
29+
}
30+
31+
if (num < min) {
32+
num = min;
33+
}
34+
35+
return num;
36+
}
37+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package dev.letsgoaway.mapxyz;
2+
3+
import org.bukkit.World;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.map.*;
6+
7+
import java.util.ArrayList;
8+
import java.util.logging.Level;
9+
10+
@SuppressWarnings("deprecation")
11+
public class PlayerCursorRenderer {
12+
13+
private static final MapCursor.Type MARKER_TYPE = MapCursor.Type.BLUE_MARKER;
14+
private static final MapCursor.Type NETHER_MARKER_TYPE = MapCursor.Type.RED_MARKER;
15+
16+
public static void render(Player viewer, Player player, MapCanvas canvas, MapView map) {
17+
if (viewer.equals(player)) {
18+
return;
19+
}
20+
21+
int scaleFactor = 1 << map.getScale().getValue();
22+
float x = (float)(player.getLocation().getX() - (double)map.getCenterX()) / (float)scaleFactor;
23+
float z = (float)(player.getLocation().getZ() - (double)map.getCenterZ()) / (float)scaleFactor;
24+
25+
byte d = calculateRotation(player);
26+
27+
// Nether marker type matches Bedrock Edition locator maps
28+
canvas.getCursors().addCursor(new MapCursor(clampMapCoordinate(x), clampMapCoordinate(z), d, map.getWorld().getEnvironment().equals(World.Environment.NETHER) ? NETHER_MARKER_TYPE : MARKER_TYPE, true, player.getName()));
29+
}
30+
31+
private static byte clampMapCoordinate(float coordinate) {
32+
if (coordinate <= -63.0F) {
33+
return -128;
34+
} else {
35+
return coordinate >= 63.0F ? 127 : (byte)((int)((double)(coordinate * 2.0F) + 0.5));
36+
}
37+
}
38+
39+
private static byte calculateRotation(Player player) {
40+
double yaw = player.getLocation().getYaw();
41+
boolean shouldFlip = 0.0 > yaw;
42+
World world = player.getLocation().getWorld();
43+
if (world != null && world.getEnvironment().equals(World.Environment.NETHER)) {
44+
// use world.getFullTime() if its the same player
45+
// but im going to use player.getTicksLived()
46+
// to make sure it looks different from your marker
47+
int i = (int) (player.getTicksLived() / 10L);
48+
return (byte) (i * i * 34187121 + i * 121 >> 15 & 15);
49+
} else {
50+
double adjusted = yaw < 0.0 ? yaw - 8.0 : yaw + 8.0;
51+
if (shouldFlip) {
52+
int i = 16 + ((int) (adjusted * 16.0 / 360.0));
53+
// todo figure out better way to fix
54+
if (i == 16) {
55+
return (byte) 0;
56+
}
57+
return (byte) (i);
58+
} else {
59+
return (byte) ((int) (adjusted * 16.0 / 360.0));
60+
}
61+
}
62+
}
63+
64+
public static void renderAll(Player viewer, MapCanvas canvas, MapView map) {
65+
for (int i = 0; i < canvas.getCursors().size(); i++) {
66+
MapCursor c = canvas.getCursors().getCursor(i);
67+
MapCursor.Type t = c.getType();
68+
69+
if (t.equals(MARKER_TYPE) || t.equals(NETHER_MARKER_TYPE)) {
70+
canvas.getCursors().removeCursor(c);
71+
}
72+
73+
if (Config.enableLocatorMaps && (t.equals(MapCursor.Type.PLAYER) || t.equals(MapCursor.Type.PLAYER_OFF_MAP) || t.equals(MapCursor.Type.PLAYER_OFF_LIMITS))){
74+
canvas.getCursors().removeCursor(c);
75+
}
76+
}
77+
78+
if (!Config.enableLocatorMaps) {
79+
return;
80+
}
81+
82+
World world = map.getWorld();
83+
if (world != null) {
84+
for (Player player : world.getPlayers()) {
85+
render(viewer, player, canvas, map);
86+
}
87+
}
88+
}
89+
}

src/main/java/dev/letsgoaway/mapxyz/PosRenderer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import org.bukkit.entity.Player;
66
import org.bukkit.inventory.ItemStack;
77
import org.bukkit.inventory.meta.MapMeta;
8-
import org.bukkit.map.MapCanvas;
9-
import org.bukkit.map.MapPalette;
10-
import org.bukkit.map.MapRenderer;
11-
import org.bukkit.map.MapView;
8+
import org.bukkit.map.*;
129
import org.jetbrains.annotations.NotNull;
1310

1411
public class PosRenderer extends MapRenderer {
@@ -46,6 +43,13 @@ public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Pla
4643
canvas.setPixelColor(x, y, canvas.getBasePixelColor(x, y));
4744
}
4845
}
46+
47+
if (!Config.enableXYZDisplay) {
48+
return;
49+
}
50+
51+
PlayerCursorRenderer.renderAll(player, canvas, map);
52+
4953
/*
5054
this is for item frames, unfortunately the position is still visible
5155
if you are holding the same map of id in your hand but that's the best we can do atm
@@ -87,8 +91,7 @@ public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Pla
8791
Location pos;
8892
if (Config.useEyeLevelPosition) {
8993
pos = player.getEyeLocation();
90-
}
91-
else {
94+
} else {
9295
pos = player.getLocation();
9396
}
9497
canvas.drawText(0, 0, MapXYZ.asciiFont, "§" + color + ";X: " + pos.getBlockX() + ", Y: " + pos.getBlockY() + ", Z: " + pos.getBlockZ());

src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# If true, show XYZ on map
2+
enable-xyz-display: true
13
# If true, players will get an empty map when they first join the server.
24
enable-starting-map: true
35
# If true, maps will scale at 1:8 (Level 3/4) by default when a map is created.
46
use-legacy-console-default-zoom: true
57
# Enables the reducedDebugInfo game rule on all worlds
68
# This option hides position info in the Debug menu (F3)
79
enable-reduced-debug-info: true
10+
# Enable locator maps, similar idea to the one on Bedrock Edition
11+
# Shows other player's markers on maps
12+
enable-locator-maps: true
813
# Make the XYZ display position show the eye level position instead of
914
# the players feet level. This matches Legacy Console Edition but may cause confusion
1015
use-eye-level-position: false

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: MapXYZ
2-
version: '1.0'
2+
version: '1.1'
33
main: dev.letsgoaway.mapxyz.MapXYZ
44
api-version: '1.21'
55
author: LetsGoAway

0 commit comments

Comments
 (0)