Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Add bungee module
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyRin committed Jun 28, 2023
1 parent 7da9274 commit 07d5708
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 1 deletion.
31 changes: 31 additions & 0 deletions module/cmd-bungee/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
</properties>
</project-shared-configuration>
20 changes: 20 additions & 0 deletions module/cmd-bungee/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-bungee</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>cmd_bungee</name>
<description>Provides the bungee command</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package net.md_5.bungee.module.cmd.bungee;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import javax.net.ssl.HttpsURLConnection;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import net.md_5.bungee.api.plugin.Command;

public class CommandBungee extends Command
{
private PluginBungee plugin;

public CommandBungee(PluginBungee plugin)
{
super( "bungee", "bungeecord.command.bungee" );

this.plugin = plugin;
}

@Override
public void execute(CommandSender sender, String[] args)
{
TextComponent bungee = new TextComponent( ChatColor.BLUE + "This server is running HexaCord version " + ProxyServer.getInstance().getVersion() + " by md_5" );
bungee.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( "Click to copy to clipboard" ) ) );
bungee.setClickEvent( new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, ChatColor.stripColor( bungee.getText() ) ) );

sender.sendMessage( bungee );

TextComponent protocol = new TextComponent( ChatColor.BLUE + "Protocol support for 1.7.x by Zartec, ghac and I9hdkill" );
protocol.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( "Click to copy to clipboard" ) ) );
protocol.setClickEvent( new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, ChatColor.stripColor( protocol.getText() ) ) );

sender.sendMessage( protocol );

sender.sendMessage( "Checking version. please wait..." );

String version = ProxyServer.getInstance().getVersion();
int lastColon = version.lastIndexOf( ':' );
String buildNumber = version.substring( lastColon + 1, version.length() );

if ( "unknown".equals( buildNumber ) )
{
sender.sendMessage( "Couldn't detect bungee version. Custom build?" );
return;
}

int currentBuildNumber = Integer.valueOf( buildNumber ).intValue();

ProxyServer.getInstance().getScheduler().runAsync( this.plugin, () ->
{
try
{
HttpsURLConnection connection = (HttpsURLConnection) new URL( "https://ci.simplyrin.net/job/HexaCord/lastStableBuild/buildNumber" ).openConnection();
connection.addRequestProperty( "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" );

// 5 second timeout at various stages
connection.setConnectTimeout( 5000 );
connection.setReadTimeout( 5000 );

String result = new BufferedReader( new InputStreamReader( connection.getInputStream(), StandardCharsets.UTF_8 ) ).lines().collect( Collectors.joining() );

int lastStableBuild = Integer.valueOf( result ).intValue();

if ( lastStableBuild == currentBuildNumber )
{
TextComponent latest = new TextComponent( ChatColor.GREEN + "You are running the latest version" );
latest.setHoverEvent( bungee.getHoverEvent() );
latest.setClickEvent( bungee.getClickEvent() );

sender.sendMessage( latest );
} else
{
TextComponent behind = new TextComponent( ChatColor.YELLOW + String.format( "You are %d version(s) behind", lastStableBuild - currentBuildNumber ) );
behind.setHoverEvent( bungee.getHoverEvent() );
behind.setClickEvent( bungee.getClickEvent() );

sender.sendMessage( behind );

TextComponent text = new TextComponent( ChatColor.YELLOW + "Download the new version at: " );
text.setHoverEvent( bungee.getHoverEvent() );
text.setClickEvent( bungee.getClickEvent() );

TextComponent url = new TextComponent( ChatColor.GOLD + "https://ci.simplyrin.net/job/HexaCord/" );
url.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new Text( "Click to open" ) ) );
url.setClickEvent( new ClickEvent( ClickEvent.Action.OPEN_URL, "https://ci.simplyrin.net/job/HexaCord/" ) );

text.addExtra( url );

sender.sendMessage( text );
}
} catch ( Exception e )
{
e.printStackTrace();
}
} );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.md_5.bungee.module.cmd.bungee;

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

public class PluginBungee extends Plugin
{

@Override
public void onEnable()
{
getProxy().getPluginManager().registerCommand( this, new CommandBungee( this ) );
}
}
5 changes: 5 additions & 0 deletions module/cmd-bungee/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: ${project.name}
main: net.md_5.bungee.module.cmd.bungee.PluginBungee
version: ${describe}
description: ${project.description}
author: ${module.author}
1 change: 1 addition & 0 deletions module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<modules>
<module>cmd-alert</module>
<module>cmd-bungee</module>
<module>cmd-find</module>
<module>cmd-kick</module>
<module>cmd-list</module>
Expand Down
2 changes: 1 addition & 1 deletion proxy/src/main/java/net/md_5/bungee/conf/YamlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void load()
} ) );
set( "permissions.admin", Arrays.asList( new String[]
{
"bungeecord.command.alert", "bungeecord.command.end", "bungeecord.command.ip", "bungeecord.command.reload", "bungeecord.command.kick"
"bungeecord.command.alert", "bungeecord.command.end", "bungeecord.command.ip", "bungeecord.command.reload", "bungeecord.command.kick", "bungeecord.command.bungee"
} ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void load(ProxyServer proxy, File moduleDirectory) throws Exception
{
case 0:
defaults.add( "jenkins://cmd_alert" );
defaults.add( "jenkins://cmd_bungee" );
defaults.add( "jenkins://cmd_find" );
defaults.add( "jenkins://cmd_list" );
defaults.add( "jenkins://cmd_send" );
Expand Down

0 comments on commit 07d5708

Please sign in to comment.