forked from BLOCKFANTASY/LOOHP-Limbo
Merge pull request #35 from GamerDuck123/master
Added 2 things: Added the default commands to the server jar, and added PlayerList header and footer support
This commit is contained in:
commit
a3b25de473
|
|
@ -37,6 +37,7 @@ import org.json.simple.parser.ParseException;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.loohp.limbo.commands.CommandSender;
|
import com.loohp.limbo.commands.CommandSender;
|
||||||
|
import com.loohp.limbo.commands.Defaults;
|
||||||
import com.loohp.limbo.consolegui.GUI;
|
import com.loohp.limbo.consolegui.GUI;
|
||||||
import com.loohp.limbo.events.EventsManager;
|
import com.loohp.limbo.events.EventsManager;
|
||||||
import com.loohp.limbo.file.ServerProperties;
|
import com.loohp.limbo.file.ServerProperties;
|
||||||
|
|
@ -291,14 +292,14 @@ public class Limbo {
|
||||||
pluginFolder = new File("plugins");
|
pluginFolder = new File("plugins");
|
||||||
pluginFolder.mkdirs();
|
pluginFolder.mkdirs();
|
||||||
|
|
||||||
File defaultCommandsJar = new File(pluginFolder, "LimboDefaultCmd.jar");
|
// File defaultCommandsJar = new File(pluginFolder, "LimboDefaultCmd.jar");
|
||||||
defaultCommandsJar.delete();
|
// defaultCommandsJar.delete();
|
||||||
console.sendMessage("Loading limbo default commands module...");
|
// console.sendMessage("Loading limbo default commands module...");
|
||||||
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream("LimboDefaultCmd.jar")) {
|
// try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream("LimboDefaultCmd.jar")) {
|
||||||
Files.copy(in, defaultCommandsJar.toPath());
|
// Files.copy(in, defaultCommandsJar.toPath());
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
|
|
||||||
pluginManager = new PluginManager(pluginFolder);
|
pluginManager = new PluginManager(pluginFolder);
|
||||||
try {
|
try {
|
||||||
|
|
@ -322,7 +323,9 @@ public class Limbo {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
Limbo.getInstance().terminate();
|
Limbo.getInstance().terminate();
|
||||||
}));
|
}));
|
||||||
|
console.sendMessage("Enabling Commands");
|
||||||
|
registerDefaultCommands();
|
||||||
|
console.sendMessage("Default Commands Enabled");
|
||||||
console.run();
|
console.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,6 +415,11 @@ public class Limbo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerDefaultCommands() {
|
||||||
|
LimboPlugin plug = new LimboPlugin();
|
||||||
|
getPluginManager().registerCommands(plug, new Defaults());
|
||||||
|
}
|
||||||
|
|
||||||
public ServerProperties getServerProperties() {
|
public ServerProperties getServerProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,179 @@
|
||||||
|
package com.loohp.limbo.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.loohp.limbo.Limbo;
|
||||||
|
import com.loohp.limbo.player.Player;
|
||||||
|
import com.loohp.limbo.utils.GameMode;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class Defaults implements CommandExecutor, TabCompletor {
|
||||||
|
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||||
|
List<String> tab = new ArrayList<>();
|
||||||
|
switch (args.length) {
|
||||||
|
case 0:
|
||||||
|
if (sender.hasPermission("limboserver.spawn"))
|
||||||
|
tab.add("spawn");
|
||||||
|
if (sender.hasPermission("limboserver.kick"))
|
||||||
|
tab.add("kick");
|
||||||
|
if (sender.hasPermission("limboserver.stop"))
|
||||||
|
tab.add("stop");
|
||||||
|
if (sender.hasPermission("limboserver.say"))
|
||||||
|
tab.add("say");
|
||||||
|
if (sender.hasPermission("limboserver.gamemode"))
|
||||||
|
tab.add("gamemode");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (sender.hasPermission("limboserver.spawn") &&
|
||||||
|
"spawn".startsWith(args[0].toLowerCase()))
|
||||||
|
tab.add("spawn");
|
||||||
|
if (sender.hasPermission("limboserver.kick") &&
|
||||||
|
"kick".startsWith(args[0].toLowerCase()))
|
||||||
|
tab.add("kick");
|
||||||
|
if (sender.hasPermission("limboserver.stop") &&
|
||||||
|
"stop".startsWith(args[0].toLowerCase()))
|
||||||
|
tab.add("stop");
|
||||||
|
if (sender.hasPermission("limboserver.say") &&
|
||||||
|
"say".startsWith(args[0].toLowerCase()))
|
||||||
|
tab.add("say");
|
||||||
|
if (sender.hasPermission("limboserver.gamemode") &&
|
||||||
|
"gamemode".startsWith(args[0].toLowerCase()))
|
||||||
|
tab.add("gamemode");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (sender.hasPermission("limboserver.kick") &&
|
||||||
|
args[0].equalsIgnoreCase("kick"))
|
||||||
|
for (Player player : Limbo.getInstance().getPlayers()) {
|
||||||
|
if (player.getName().toLowerCase().startsWith(args[1].toLowerCase()))
|
||||||
|
tab.add(player.getName());
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("limboserver.gamemode") &&
|
||||||
|
args[0].equalsIgnoreCase("gamemode")) {
|
||||||
|
byte b;
|
||||||
|
int i;
|
||||||
|
GameMode[] arrayOfGameMode;
|
||||||
|
for (i = (arrayOfGameMode = GameMode.values()).length, b = 0; b < i; ) {
|
||||||
|
GameMode mode = arrayOfGameMode[b];
|
||||||
|
if (mode.getName().toLowerCase().startsWith(args[1].toLowerCase()))
|
||||||
|
tab.add(mode.getName());
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (sender.hasPermission("limboserver.gamemode") &&
|
||||||
|
args[0].equalsIgnoreCase("gamemode"))
|
||||||
|
for (Player player : Limbo.getInstance().getPlayers()) {
|
||||||
|
if (player.getName().toLowerCase().startsWith(args[2].toLowerCase()))
|
||||||
|
tab.add(player.getName());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
if (args.length == 0)
|
||||||
|
return;
|
||||||
|
if (args[0].equalsIgnoreCase("spawn")) {
|
||||||
|
if (sender.hasPermission("limboserver.spawn")) {
|
||||||
|
if (args.length == 1 && sender instanceof Player) {
|
||||||
|
Player player = (Player)sender;
|
||||||
|
player.teleport(Limbo.getInstance().getServerProperties().getWorldSpawn());
|
||||||
|
player.sendMessage(ChatColor.GOLD + "Teleporting you to spawn!");
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
Player player = Limbo.getInstance().getPlayer(args[1]);
|
||||||
|
if (player != null) {
|
||||||
|
player.teleport(Limbo.getInstance().getServerProperties().getWorldSpawn());
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Teleporting " + player.getName() + " to spawn!");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid command usage!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("stop")) {
|
||||||
|
if (sender.hasPermission("limboserver.stop")) {
|
||||||
|
Limbo.getInstance().stopServer();
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("kick")) {
|
||||||
|
if (sender.hasPermission("limboserver.kick")) {
|
||||||
|
String reason = "Disconnected!";
|
||||||
|
Player player = (args.length > 1) ? Limbo.getInstance().getPlayer(args[1]) : null;
|
||||||
|
if (player != null) {
|
||||||
|
if (args.length < 2) {
|
||||||
|
player.disconnect();
|
||||||
|
} else {
|
||||||
|
reason = String.join(" ", Arrays.<CharSequence>copyOfRange((CharSequence[])args, 2, args.length));
|
||||||
|
player.disconnect(reason);
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.RED + "Kicked the player " + args[1] + " for the reason: " + reason);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Player is not online!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("gamemode")) {
|
||||||
|
if (sender.hasPermission("limboserver.gamemode")) {
|
||||||
|
if (args.length > 1) {
|
||||||
|
Player player = (args.length > 2) ? Limbo.getInstance().getPlayer(args[2]) : ((sender instanceof Player) ? (Player)sender : null);
|
||||||
|
if (player != null) {
|
||||||
|
try {
|
||||||
|
player.setGamemode(GameMode.fromId(Integer.parseInt(args[1])));
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
player.setGamemode(GameMode.fromName(args[1]));
|
||||||
|
} catch (Exception e1) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Updated gamemode to " + player.getGamemode().getName());
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Player is not online!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid usage!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("say")) {
|
||||||
|
if (sender.hasPermission("limboserver.say")) {
|
||||||
|
if (sender instanceof com.loohp.limbo.Console) {
|
||||||
|
if (args.length > 1) {
|
||||||
|
String message = "[Server] " + String.join(" ", Arrays.<CharSequence>copyOfRange((CharSequence[])args, 1, args.length));
|
||||||
|
Limbo.getInstance().getConsole().sendMessage(message);
|
||||||
|
for (Player each : Limbo.getInstance().getPlayers())
|
||||||
|
each.sendMessage(message);
|
||||||
|
}
|
||||||
|
} else if (args.length > 1) {
|
||||||
|
String message = "[" + sender.getName() + "] " + String.join(" ", Arrays.<CharSequence>copyOfRange((CharSequence[])args, 1, args.length));
|
||||||
|
Limbo.getInstance().getConsole().sendMessage(message);
|
||||||
|
for (Player each : Limbo.getInstance().getPlayers())
|
||||||
|
each.sendMessage(message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -55,6 +55,9 @@ public class ServerProperties {
|
||||||
private boolean resourcePackRequired;
|
private boolean resourcePackRequired;
|
||||||
private String resourcePackPromptJson;
|
private String resourcePackPromptJson;
|
||||||
|
|
||||||
|
private String tabHeader;
|
||||||
|
private String tabFooter;
|
||||||
|
|
||||||
Optional<BufferedImage> favicon;
|
Optional<BufferedImage> favicon;
|
||||||
|
|
||||||
public ServerProperties(File file) throws IOException {
|
public ServerProperties(File file) throws IOException {
|
||||||
|
|
@ -133,6 +136,9 @@ public class ServerProperties {
|
||||||
resourcePackRequired = Boolean.parseBoolean(prop.getProperty("required-resource-pack"));
|
resourcePackRequired = Boolean.parseBoolean(prop.getProperty("required-resource-pack"));
|
||||||
resourcePackPromptJson = prop.getProperty("resource-pack-prompt");
|
resourcePackPromptJson = prop.getProperty("resource-pack-prompt");
|
||||||
|
|
||||||
|
tabHeader = prop.getProperty("tab-header");
|
||||||
|
tabFooter = prop.getProperty("tab-footer");
|
||||||
|
|
||||||
File png = new File("server-icon.png");
|
File png = new File("server-icon.png");
|
||||||
if (png.exists()) {
|
if (png.exists()) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -268,5 +274,13 @@ public class ServerProperties {
|
||||||
public String getResourcePackPromptJson() {
|
public String getResourcePackPromptJson() {
|
||||||
return resourcePackPromptJson;
|
return resourcePackPromptJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTabHeader() {
|
||||||
|
return tabHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTabFooter() {
|
||||||
|
return tabFooter;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import com.loohp.limbo.server.ClientConnection;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutChat;
|
import com.loohp.limbo.server.packets.PacketPlayOutChat;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutGameState;
|
import com.loohp.limbo.server.packets.PacketPlayOutGameState;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutHeldItemChange;
|
import com.loohp.limbo.server.packets.PacketPlayOutHeldItemChange;
|
||||||
|
import com.loohp.limbo.server.packets.PacketPlayOutPlayerListHeaderFooter;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutPositionAndLook;
|
import com.loohp.limbo.server.packets.PacketPlayOutPositionAndLook;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutResourcePackSend;
|
import com.loohp.limbo.server.packets.PacketPlayOutResourcePackSend;
|
||||||
import com.loohp.limbo.server.packets.PacketPlayOutRespawn;
|
import com.loohp.limbo.server.packets.PacketPlayOutRespawn;
|
||||||
|
|
@ -282,5 +283,38 @@ public class Player extends LivingEntity implements CommandSender {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
|
||||||
|
try {
|
||||||
|
PacketPlayOutPlayerListHeaderFooter packsend = new PacketPlayOutPlayerListHeaderFooter(
|
||||||
|
ComponentSerializer.toString(header),
|
||||||
|
ComponentSerializer.toString(footer));
|
||||||
|
clientConnection.sendPacket(packsend);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerListHeader(BaseComponent[] header) {
|
||||||
|
try {
|
||||||
|
PacketPlayOutPlayerListHeaderFooter packsend = new PacketPlayOutPlayerListHeaderFooter(
|
||||||
|
ComponentSerializer.toString(header),
|
||||||
|
null);
|
||||||
|
clientConnection.sendPacket(packsend);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerListFooter(BaseComponent[] footer) {
|
||||||
|
try {
|
||||||
|
PacketPlayOutPlayerListHeaderFooter packsend = new PacketPlayOutPlayerListHeaderFooter(
|
||||||
|
null,
|
||||||
|
ComponentSerializer.toString(footer));
|
||||||
|
clientConnection.sendPacket(packsend);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -421,6 +421,8 @@ public class ClientConnection extends Thread {
|
||||||
sendPacket(state);
|
sendPacket(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RESOURCEPACK CODE ADDED BY GAMERDUCK123
|
||||||
|
|
||||||
if (properties.getResourcePackLink() != null && !properties.getResourcePackLink().equalsIgnoreCase("")) {
|
if (properties.getResourcePackLink() != null && !properties.getResourcePackLink().equalsIgnoreCase("")) {
|
||||||
if (properties.getResourcePackSHA1() != null && !properties.getResourcePackSHA1().equalsIgnoreCase("")) {
|
if (properties.getResourcePackSHA1() != null && !properties.getResourcePackSHA1().equalsIgnoreCase("")) {
|
||||||
//SEND RESOURCEPACK
|
//SEND RESOURCEPACK
|
||||||
|
|
@ -434,6 +436,20 @@ public class ClientConnection extends Thread {
|
||||||
} else {
|
} else {
|
||||||
//RESOURCEPACK NOT ENABLED
|
//RESOURCEPACK NOT ENABLED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PLAYER LIST HEADER AND FOOTER CODE ADDED BY GAMERDUCK123
|
||||||
|
// Sadly due to the limitations of minecraft (?) I cannot get the footer to work alone, it needs a header to have a footer, BUT
|
||||||
|
// You can have just a header with no footer (which is weird!)
|
||||||
|
String tabHeader = "";
|
||||||
|
String tabFooter = "";
|
||||||
|
if (properties.getTabHeader() != null && !properties.getTabHeader().equalsIgnoreCase("")) {
|
||||||
|
tabHeader = properties.getTabHeader();
|
||||||
|
}
|
||||||
|
if (properties.getTabFooter() != null && !properties.getTabFooter().equalsIgnoreCase("")) {
|
||||||
|
tabFooter = properties.getTabFooter();
|
||||||
|
}
|
||||||
|
player.setPlayerListHeaderFooter(ComponentSerializer.parse(tabHeader),
|
||||||
|
ComponentSerializer.parse(tabFooter));
|
||||||
|
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.loohp.limbo.server.packets;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import com.loohp.limbo.utils.DataTypeIO;
|
||||||
|
|
||||||
|
public class PacketPlayOutPlayerListHeaderFooter extends PacketOut{
|
||||||
|
|
||||||
|
private String header;
|
||||||
|
private String footer;
|
||||||
|
|
||||||
|
public PacketPlayOutPlayerListHeaderFooter(String header, String footer) {
|
||||||
|
this.header = header;
|
||||||
|
this.footer = footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFooter() {
|
||||||
|
return footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] serializePacket() throws IOException {
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
DataOutputStream output = new DataOutputStream(buffer);
|
||||||
|
output.writeByte(Packet.getPlayOut().get(getClass()));
|
||||||
|
DataTypeIO.writeString(output, header, StandardCharsets.UTF_8);
|
||||||
|
DataTypeIO.writeString(output, footer, StandardCharsets.UTF_8);
|
||||||
|
return buffer.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
"PacketPlayOutSpawnEntity": "0x00",
|
"PacketPlayOutSpawnEntity": "0x00",
|
||||||
"PacketPlayOutSpawnEntityLiving": "0x02",
|
"PacketPlayOutSpawnEntityLiving": "0x02",
|
||||||
"PacketPlayOutHeldItemChange": "0x48",
|
"PacketPlayOutHeldItemChange": "0x48",
|
||||||
|
"PacketPlayOutPlayerListHeaderFooter": "0x5E",
|
||||||
"PacketPlayOutResourcePackSend": "0x3C"
|
"PacketPlayOutResourcePackSend": "0x3C"
|
||||||
},
|
},
|
||||||
"StatusIn": {
|
"StatusIn": {
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,12 @@ motd={"text":"","extra":[{"text":"Limbo Server!","color":"yellow"}]}
|
||||||
#Server list version as string
|
#Server list version as string
|
||||||
version=Limbo!
|
version=Limbo!
|
||||||
|
|
||||||
|
#Tab-List Header (May be left blank)
|
||||||
|
tab-header=
|
||||||
|
|
||||||
|
#Tab-List Footer (May be left blank)
|
||||||
|
tab-footer=
|
||||||
|
|
||||||
#Server resource pack url (May be left blank)
|
#Server resource pack url (May be left blank)
|
||||||
resource-pack=
|
resource-pack=
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue