Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
turikhay committed Sep 6, 2022
0 parents commit be202eb
Show file tree
Hide file tree
Showing 34 changed files with 1,095 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build

on:
push:
branches:
- '**'
tags-ignore:
- 'v*.*.*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- id: sha
run: |
SHA=${{ github.sha }}
echo "::set-output name=sha8::${SHA:0:8}"
- uses: gradle/gradle-build-action@v2
with:
arguments: |
build
-Pversion=0.0.0+${{ steps.sha.outputs.sha8 }}
- uses: actions/upload-artifact@v3
with:
name: Artifacts (${{ steps.sha.outputs.sha8 }})
path: |
bungee/build/libs/MapModCompanion-Bungee.jar
spigot/build/libs/MapModCompanion-Spigot.jar
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
push:
tags:
- 'v*.*.*'

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Detect version from the tag name
id: version
run: |
TAG=${{ github.ref }}
VERSION=${TAG#refs/tags/v}
echo "::set-output name=version::$VERSION"
IS_PRE_RELEASE=$([[ $VERSION =~ .+(alpha|beta|pre|rc).* ]] && echo "true" || echo "false")
echo "::set-output name=pre-release::$IS_PRE_RELEASE"
- uses: gradle/gradle-build-action@v2
with:
arguments: |
build
-Pversion=${{ steps.version.outputs.version }}
- uses: softprops/action-gh-release@v1
with:
name: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.pre-release }}
generate_release_notes: true
draft: true
files: |
bungee/build/libs/MapModCompanion-Bungee.jar
spigot/build/libs/MapModCompanion-Spigot.jar
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
debug*/

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Artur Khusainov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Companion for map mods
Unofficial BungeeCord and Spigot (Paper) companion plugin for
[Xaero's Minimap](https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap)
(and their [World Map](https://www.curseforge.com/minecraft/mc-mods/xaeros-world-map)),
[JourneyMap](https://www.curseforge.com/minecraft/mc-mods/journeymap) and
VoxelMap.

This plugin fixes Multi-world detection in multiplayer by simulating mod presence on
the server side.

This plugin was inspired by @kosma's [worldnamepacket](https://github.com/kosma/worldnamepacket),
which supported Velocity, Fabric and Spigot at the time of writing.

## Support table
| Mod | Version | Status |
|------------------------------------------------------------------------------------|-----------------------------|-------------|
| [Xaero's Minimap](https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap) | v22.13.2 (1.19.2) | ✅ Supported |
| [Xaero's World Map](https://www.curseforge.com/minecraft/mc-mods/xaeros-world-map) | v22.13.2 (1.19.2) | ✅ Supported |
| [JourneyMap](https://www.curseforge.com/minecraft/mc-mods/journeymap) | 5.9.0beta2 (1.18.2, 1.19.2) | ✅ Supported |
| VoxelMap (Refresh-MC) | 1.11.10 (1.19.2) | ✅ Supported |

## Installation
1. Download the latest release from [Releases](https://github.com/turikhay/xaeros-minimap-companion/releases) page
2. Put each of them into the corresponding plugins folder
3. That's it. No configuration required. You can restart your servers now.

⚠️ **NOTE** Spigot plugin can be used without BungeeCord counterpart, but it's highly recommended to install
plugins on both sides. On the contrary, BungeeCord plugin is useless if you don't install Spigot plugin on
downstream servers.

## Alternatives
- [worldnamepacket](https://github.com/kosma/worldnamepacket) (Velocity, Fabric, Spigot)
- [JourneyMap Server](https://www.curseforge.com/minecraft/mc-mods/journeymap-server) (Spigot)
- [Minimap server](https://github.com/Ewpratten/MinimapServer) (Spigot)
33 changes: 33 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'java'
id 'kr.entree.spigradle' version '2.4.2' apply false
id 'kr.entree.spigradle.bungee' version '2.4.2' apply false
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
}

group 'com.turikhay.mc'

subprojects {
apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

group rootProject.group
version rootProject.version

repositories {
mavenCentral()
}

dependencies {
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.1'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
useJUnitPlatform()
}
}
22 changes: 22 additions & 0 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'kr.entree.spigradle.bungee'
id 'com.github.johnrengelman.shadow'
}

bungee {
name 'MapModCompanion'
author 'turikhay'
}

assemble {
dependsOn shadowJar
}

shadowJar {
archiveName("MapModCompanion-Bungee.jar")
}

dependencies {
implementation project(":common")
compileOnly bungeecord()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.turikhay.mc.mapmodcompanion.bungee;

import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;

import java.util.Arrays;
import java.util.List;

public class CompanionBungee extends Plugin implements Listener {

List<PacketHandler<?, ?>> handlers = Arrays.asList(
new XaerosPacketHandler(this),
new WorldIdPacketHandler(this)
);

@Override
public void onEnable() {
handlers.forEach(PacketHandler::init);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.turikhay.mc.mapmodcompanion.bungee;

import com.turikhay.mc.mapmodcompanion.IdMessagePacket;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

import javax.annotation.Nullable;
import java.util.Arrays;

public abstract class PacketHandler<Id2 extends IdMessagePacket<?>, Id extends IdMessagePacket<Id2>> implements Listener {
private final String channelName;
private final CompanionBungee plugin;

public PacketHandler(String channelName, CompanionBungee plugin) {
this.channelName = channelName;
this.plugin = plugin;
}

public void init() {
plugin.getProxy().registerChannel(channelName);
plugin.getProxy().getPluginManager().registerListener(plugin, this);
}

/*
Intercept world IDs received from the downstream servers
in order to (hopefully) resolve ID conflicts that may occur
*/
@EventHandler
public void onPluginMessageSentToPlayer(PluginMessageEvent event) {
if (!event.getTag().equals(channelName)) {
return;
}
if (!(event.getSender() instanceof Server)) {
return;
}
Server server = (Server) event.getSender();
if (!(event.getReceiver() instanceof ProxiedPlayer)) {
return;
}
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
byte[] data = event.getData();
Id oldId = tryRead(data);
if (oldId == null) {
plugin.getLogger().warning("Possibly corrupted packet from " + channelName + ": " + Arrays.toString(data));
return;
}
event.setCancelled(true);
Id2 newId = oldId.combineWith(getId(server));
player.sendData(channelName, IdMessagePacket.bytesPacket(newId));
}

@Nullable
public abstract Id tryRead(byte[] data);
public abstract Id2 getId(Server server);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.turikhay.mc.mapmodcompanion.bungee;

import com.turikhay.mc.mapmodcompanion.worldid.WorldId;
import net.md_5.bungee.api.connection.Server;
import org.jetbrains.annotations.Nullable;

import static com.turikhay.mc.mapmodcompanion.worldid.WorldIdCompanion.WORLD_ID_CHANNEL_NAME;

public class WorldIdPacketHandler extends PacketHandler<WorldId, WorldId> {

public WorldIdPacketHandler(CompanionBungee plugin) {
super(WORLD_ID_CHANNEL_NAME, plugin);
}

@Nullable
@Override
public WorldId tryRead(byte[] data) {
return WorldId.tryRead(data);
}

@Override
public WorldId getId(Server server) {
return WorldId.createTruncatingLength(server.getInfo().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.turikhay.mc.mapmodcompanion.bungee;

import com.turikhay.mc.mapmodcompanion.xaeros.LevelMapProperties;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.plugin.Listener;
import org.jetbrains.annotations.Nullable;

import static com.turikhay.mc.mapmodcompanion.xaeros.XaerosCompanion.XAEROS_CHANNEL_NAME;

public class XaerosPacketHandler extends PacketHandler<LevelMapProperties, LevelMapProperties> implements Listener {

public XaerosPacketHandler(CompanionBungee plugin) {
super(XAEROS_CHANNEL_NAME, plugin);
}

@Nullable
@Override
public LevelMapProperties tryRead(byte[] data) {
return LevelMapProperties.tryRead(data);
}

@Override
public LevelMapProperties getId(Server server) {
return new LevelMapProperties(server.getInfo().getName().hashCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package com.turikhay.mc.mapmodcompanion.bungee;

import javax.annotation.ParametersAreNonnullByDefault;
Empty file added common/build.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.turikhay.mc.mapmodcompanion;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public interface IdMessagePacket<CombinableWith extends IdMessagePacket<?>> {
CombinableWith combineWith(CombinableWith packet);
void constructPacket(DataOutputStream out) throws IOException;

static byte[] bytesPacket(IdMessagePacket<?> id) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (DataOutputStream out = new DataOutputStream(buffer)) {
id.constructPacket(out);
} catch (IOException e) {
throw new Error(e);
}
return buffer.toByteArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package com.turikhay.mc.mapmodcompanion;

import javax.annotation.ParametersAreNonnullByDefault;
Loading

0 comments on commit be202eb

Please sign in to comment.