Skip to content

Commit

Permalink
Updated Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
linsaftw committed Sep 30, 2020
1 parent 6315e18 commit fa70dc1
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bungee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
main: net.simplyrin.protocolchanger.BungeeProtocolChanger
version: 1.0.0
name: BungeeProtocolChanger
author: SimplyRin
1 change: 1 addition & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protocol: Spigot 1.7-1.8
64 changes: 64 additions & 0 deletions src/net/simplyrin/protocolchanger/BungeeProtocolChanger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.simplyrin.protocolchanger;

import java.io.File;
import java.io.IOException;

import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.event.EventHandler;

public class BungeeProtocolChanger extends Plugin implements Listener {
private String protocol;

@Override
public void onEnable() {
try {
configuration();
} catch (IOException e) {
e.printStackTrace();
}

getProxy().getPluginManager().registerListener(this, this);
}

private void configuration() throws IOException {
final File dataFolder = getDataFolder();

if (!dataFolder.exists()) {
dataFolder.mkdir();
}

final File file = new File(dataFolder, "config.yml");

if (!file.exists()) {
file.createNewFile();
}

final ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class);
final Configuration config = provider.load(file);

if (config.get("protocol") == null) {
config.set("protocol", "BungeeCord " + getProxy().getGameVersion());

provider.save(config, file);
}

this.protocol = config.getString("protocol");
}

@EventHandler
public void onPing(final ProxyPingEvent event) throws IOException {
final ServerPing ping = event.getResponse();

if (ping == null) {
return;
}

ping.getVersion().setName(protocol);
}
}
36 changes: 36 additions & 0 deletions src/net/simplyrin/protocolchanger/ProtocolChanger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.simplyrin.protocolchanger;

import java.util.Arrays;

import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedServerPing;

public class ProtocolChanger extends JavaPlugin implements Listener {
@Override
public void onEnable() {
saveDefaultConfig();

ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL,
Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO), ListenerOptions.ASYNC) {
@Override
public void onPacketSending(final PacketEvent event) {
if (event.isCancelled()) {
return;
}

final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
final String name = getConfig().getString("protocol");

ping.setVersionName(name);
}
});
}
}
5 changes: 5 additions & 0 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
main: net.simplyrin.protocolchanger.ProtocolChanger
name: ProtocolChanger
version: 1.1.0
authors: [SimplyRin, LinsaFTW]
depend: [ProtocolLib]
Binary file added target/ProtocolChanger.jar
Binary file not shown.

0 comments on commit fa70dc1

Please sign in to comment.