Skip to content

Commit

Permalink
Add support for Xaero's Minimap
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHaws committed Oct 8, 2022
1 parent 9601925 commit f70e6c7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ jobs:
- name: Archive plugin jars on GitHub
uses: actions/upload-artifact@v3
with:
name: XaerosWorldMapSpigot
name: xaero-map-spigot
path: build/libs
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Xaeros World Map Spigot Plugin
Adds server side support for [Xaero's World Map](https://www.curseforge.com/minecraft/mc-mods/xaeros-world-map) on spigot.
# Xaero Map Spigot Plugin
Adds server side support for Xaero's map mods on spigot.

# Credits
- [Xaero's World Map](https://www.curseforge.com/minecraft/mc-mods/xaeros-world-map)
- [Xaero's Minimap](https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap/)

# Support the project
You can help support the project by making a donation at [BuyMeACoffee](https://www.buymeacoffee.com/ChristopherHaws)!
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spigot {

shadowJar {
//archiveClassifier.set("")
relocate 'org.bstats', 'dev.chaws.xaeros.map.spigot'
relocate 'org.bstats', 'dev.chaws.xaero.map.spigot'
}

def targetJavaVersion = 17
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group = dev.chaws
packageName = xaeros-world-map-spigot
pluginName = xaeros-world-map-spigot
packageName = xaero-map-spigot
pluginName = xaero-map-spigot
authors = Chaws
mcVersion = 1.19.2
spigotApiVersion = 1.19
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'xaeros-world-map-spigot'
rootProject.name = 'xaero-map-spigot'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.chaws.xaeros.map.spigot;
package dev.chaws.xaero.map.spigot;

import com.google.common.io.ByteStreams;
import org.bstats.bukkit.Metrics;
Expand All @@ -17,19 +17,21 @@
import java.util.Random;
import java.util.logging.Logger;

public class WorldMap extends JavaPlugin implements Listener {
private static final String channel = "xaeroworldmap:main";
public class XaeroMapPlugin extends JavaPlugin implements Listener {
private static final String worldmapChannel = "xaeroworldmap:main";
private static final String minimapChannel = "xaerominimap:main";

public static Logger log;

private int worldId;
private int serverLevelId;

@Override
public void onEnable() {
log = getLogger();
this.worldId = this.initializeWorldId();
this.serverLevelId = this.initializeServerLevelId();

this.getServer().getMessenger().registerOutgoingPluginChannel(this, channel);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, worldmapChannel);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, minimapChannel);
this.getServer().getPluginManager().registerEvents(this, this);

try {
Expand All @@ -46,27 +48,31 @@ public void onDisable() {
// so the packet won't get picked up by the mod.
@EventHandler
public void onPlayerRegisterChannel(PlayerRegisterChannelEvent event) {
if (!event.getChannel().equals(channel)) {
var channel = event.getChannel();
if (!channel.equals(worldmapChannel) &&
!channel.equals(minimapChannel)) {
return;
}

sendPlayerWorldId(event.getPlayer());
this.sendPlayerWorldId(event.getPlayer(), channel);
}

@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
sendPlayerWorldId(event.getPlayer());
var player = event.getPlayer();
this.sendPlayerWorldId(player, worldmapChannel);
this.sendPlayerWorldId(player, minimapChannel);
}

private void sendPlayerWorldId(Player player) {
private void sendPlayerWorldId(Player player, String channel) {
var bytes = ByteStreams.newDataOutput();
bytes.writeByte(0);
bytes.writeInt(this.worldId);
bytes.writeInt(this.serverLevelId);

player.sendPluginMessage(this, channel, bytes.toByteArray());
}

private int initializeWorldId() {
private int initializeServerLevelId() {
try {
var worldFolder = getServer().getWorldContainer().getCanonicalPath();
var xaeromapFile = new File(worldFolder + File.separator + "xaeromap.txt");
Expand All @@ -83,8 +89,9 @@ private int initializeWorldId() {
log.warning("Failed to create xaeromap.txt: " + ex);
}
} else {
try (var fr = new FileReader(xaeromapFile); var br = new BufferedReader(fr)) {
var line = br.readLine();
try (var fileReader = new FileReader(xaeromapFile);
var bufferedReader = new BufferedReader(fileReader)) {
var line = bufferedReader.readLine();
var args = line.split(":");
if (!Objects.equals(args[0], "id")) {
throw new Exception("Failed to read id from xaeromap.txt");
Expand Down

0 comments on commit f70e6c7

Please sign in to comment.