Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat. Adding the motd management option from the site #11

Merged
merged 5 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven'

group = 'fr.vmarchaud'
version = '3.0.1'
version = '3.0.2'

description = "mineweb_bridge"

Expand Down
Binary file added mineweb_bridge-3.0.2.jar
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/fr/vmarchaud/mineweb/bukkit/BukkitCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public void registerMethods() {
methods.put("RUN_COMMAND", new CommonRunCommand());
methods.put("RUN_SCHEDULED_COMMAND", new CommonScheduledCommand());
methods.put("GET_SERVER_TIMESTAMP", new CommonGetTimestamp());
methods.put("SET_MOTD", new CommonSetMotd());

// bukkit methods
methods.put("GET_BANNED_PLAYERS", new BukkitGetBannedPlayers());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/vmarchaud/mineweb/bukkit/BukkitListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;

import fr.vmarchaud.mineweb.common.ICore;

Expand Down Expand Up @@ -57,4 +58,13 @@ public void onQuit(PlayerQuitEvent e) {
// update our cached player list
api.getPlayers().remove(e.getPlayer().getName());
}

@EventHandler
public void onPing(ServerListPingEvent e) {
String motd = api.config().motd;
if(motd == null || motd.length() == 0)
return;
motd = motd.replace("&", "�").replace("{PLAYERS}", String.valueOf(api.getPlayers().size()));
e.setMotd(motd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public class BukkitGetMOTD implements IMethod {

@Override
public Object execute(ICore instance, Object... inputs) {
return ((Server)instance.getGameServer()).getMotd();

if (instance.config().getMotd() == null || instance.config().getMotd().length() == 0)
return ((Server)instance.getGameServer()).getMotd();
return instance.config().getMotd();
}

}
22 changes: 12 additions & 10 deletions src/main/java/fr/vmarchaud/mineweb/bungee/BungeeCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@
*******************************************************************************/
package fr.vmarchaud.mineweb.bungee;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import fr.vmarchaud.mineweb.bungee.methods.BungeeGetMOTD;
import fr.vmarchaud.mineweb.bungee.methods.BungeeGetMaxPlayers;
import fr.vmarchaud.mineweb.bungee.methods.BungeeGetVersion;
Expand All @@ -43,16 +54,6 @@
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.scheduler.ScheduledTask;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BungeeCore extends Plugin implements ICore {

public static ICore instance;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void registerMethods() {
methods.put("RUN_COMMAND", new CommonRunCommand());
methods.put("RUN_SCHEDULED_COMMAND", new CommonScheduledCommand());
methods.put("GET_SERVER_TIMESTAMP", new CommonGetTimestamp());
methods.put("SET_MOTD", new CommonSetMotd());

// bungee methods
methods.put("GET_MAX_PLAYERS", new BungeeGetMaxPlayers());
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/fr/vmarchaud/mineweb/bungee/BungeeListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

import fr.vmarchaud.mineweb.common.ICore;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

Expand Down Expand Up @@ -57,4 +60,18 @@ public void onQuit(PlayerDisconnectEvent e) {
// update our cached player list
api.getPlayers().remove(e.getPlayer().getName());
}


@EventHandler
public void onPing(ProxyPingEvent e) {
String motd = api.config().motd;
if(motd == null || motd.length() == 0)
return;
ServerPing response = e.getResponse();
motd = motd.replace("&", "�").replace("{PLAYERS}", String.valueOf(api.getPlayers().size()));
response.setDescriptionComponent(new TextComponent(motd));
e.setResponse(response);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@

import fr.vmarchaud.mineweb.common.ICore;
import fr.vmarchaud.mineweb.common.IMethod;
import fr.vmarchaud.mineweb.common.MethodHandler;
import net.md_5.bungee.api.ProxyServer;

@MethodHandler
public class BungeeGetMOTD implements IMethod {

@Override
public Object execute(ICore instance, Object... inputs) {
return ((ProxyServer)instance.getGameServer()).getConfigurationAdapter().getListeners().iterator().next().getMotd();
if (instance.config().getMotd() == null || instance.config().getMotd().length() == 0)
return ((ProxyServer) instance.getGameServer()).getConfigurationAdapter().getListeners().iterator().next()
.getMotd();
return instance.config().getMotd();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import fr.vmarchaud.mineweb.common.ICore;
import fr.vmarchaud.mineweb.common.IMethod;
import fr.vmarchaud.mineweb.common.MethodHandler;
import net.md_5.bungee.api.ProxyServer;

@MethodHandler
public class BungeeGetMaxPlayers implements IMethod {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import fr.vmarchaud.mineweb.common.ICore;
import fr.vmarchaud.mineweb.common.IMethod;
import fr.vmarchaud.mineweb.common.MethodHandler;
import net.md_5.bungee.api.ProxyServer;

@MethodHandler
public class BungeeGetVersion implements IMethod {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@

@Data
public class PluginConfiguration {

public transient File path;

public String logLevel = "FINE";
public String secretkey;
public String motd;
public String domain;
public Integer port;

public PluginConfiguration(File path) {
this.path = path;
}

/**
* Load the configuration from the file
*
* @param path object representing the path of the file
* @param api interface for logging and use gson instance
*/
Expand Down Expand Up @@ -54,9 +56,10 @@ public static PluginConfiguration load(File path, ICore api) {
return config;
}
}

/**
* Save the configuration to the file
*
* @param api interface for logging and use gson instance
*/
public void save(ICore api) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.vmarchaud.mineweb.common.methods;

import fr.vmarchaud.mineweb.common.ICore;
import fr.vmarchaud.mineweb.common.IMethod;
import fr.vmarchaud.mineweb.common.MethodHandler;

@MethodHandler(inputs = 1, types = { String.class })
public class CommonSetMotd implements IMethod {

@Override
public Object execute(ICore instance, Object... inputs) {
String motd = (String) inputs[0];
instance.config().setMotd(motd);
instance.config().save(instance);
return true;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: MinewebBridge
main: fr.vmarchaud.mineweb.bungee.BungeeCore
version: 3.0.1
version: 3.0.2
author: ThisIsMac, Shyrogan
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MinewebBridge
main: fr.vmarchaud.mineweb.bukkit.BukkitCore
version: 3.0.1
version: 3.0.2
authors:
- ThisIsMac
- Shyrogan
Expand Down