-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
src/net/simplyrin/protocolchanger/BungeeProtocolChanger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.