Skip to content

Commit

Permalink
#75 Added Server Signs
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Mar 17, 2022
1 parent 5454590 commit 7433fc0
Show file tree
Hide file tree
Showing 28 changed files with 1,260 additions and 771 deletions.
2 changes: 1 addition & 1 deletion SubServers.Bungee/common/pom.xml
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w50a</version>
<version>22w11a</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion SubServers.Bungee/pom.xml
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId>
<version>21w50a</version>
<version>22w11a</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -128,6 +128,7 @@ public boolean start(UUID player) {
}
void started(UUID address) {
if (!running) {
stopping = false;
started = false;
running = true;
lock = false;
Expand All @@ -152,14 +153,17 @@ public boolean stop(UUID player) {
if (!event.isCancelled()) {
history.add(new LoggedCommand(player, stopcmd));
host.queue(new PacketExControlServer(this, Action.STOP));
stopping = true;
return true;
} else return false;
} else return false;
}
private void stopped(Boolean allowrestart) {
logger.stop();
history.clear();
started = false;
running = false;
stopping = false;
SubStoppedEvent event = new SubStoppedEvent(this);
host.plugin.getPluginManager().callEvent(event);
Logger.get("SubServers").info(getName() + " has stopped");
Expand Down Expand Up @@ -205,6 +209,7 @@ public boolean terminate(UUID player) {
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
host.queue(new PacketExControlServer(this, Action.TERMINATE));
stopping = true;
return true;
} else return false;
} else return false;
Expand All @@ -220,6 +225,7 @@ public boolean command(UUID player, String command) {
history.add(new LoggedCommand(player, event.getCommand()));
if (event.getCommand().equalsIgnoreCase(stopcmd)) {
host.queue(new PacketExControlServer(this, Action.STOP));
stopping = true;
} else {
host.queue(new PacketExControlServer(this, Action.COMMAND, event.getCommand()));
}
Expand Down
Expand Up @@ -149,6 +149,7 @@ void updating(boolean value) {
private void run() {
boolean locked = lock;
allowrestart = true;
stopping = false;
started = false;
try {
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.getCreator().getBashDirectory(), executable)).directory(directory);
Expand Down Expand Up @@ -181,6 +182,8 @@ private void run() {
Logger.get("SubServers").info(getName() + " has stopped");
process = null;
command = null;
started = false;
stopping = false;
history.clear();

SubStoppedEvent event = new SubStoppedEvent(this);
Expand Down Expand Up @@ -245,6 +248,7 @@ public boolean stop(UUID player) {
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
try {
stopping = true;
allowrestart = false;
history.add(new LoggedCommand(player, stopcmd));
if (process != null && process.isAlive()) {
Expand All @@ -267,6 +271,7 @@ public boolean terminate(UUID player) {
SubStopEvent event = new SubStopEvent(player, this, true);
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
stopping = true;
allowrestart = false;
if (process != null && process.isAlive()) Executable.terminate(process);
return true;
Expand All @@ -282,7 +287,10 @@ public boolean command(UUID player, String command) {
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) {
try {
if (event.getCommand().equalsIgnoreCase(stopcmd)) allowrestart = false;
if (event.getCommand().equalsIgnoreCase(stopcmd)) {
stopping = true;
allowrestart = false;
}
history.add(new LoggedCommand(player, event.getCommand()));
if (process != null && process.isAlive()) {
this.command.write(event.getCommand());
Expand Down
Expand Up @@ -217,6 +217,14 @@ default int permaEdit(ObjectMap<String> edit) {
*/
boolean isOnline();

/**
* If the Server is Stopping<br>
* <b>This method can only be true when the server is stopped through the server manager!</b>
*
* @return Stopping Status
*/
boolean isStopping();

/**
* Grabs the Host of the Server
*
Expand Down
Expand Up @@ -22,7 +22,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
private List<Pair<String, String>> incompatibilities = new ArrayList<Pair<String, String>>();
private SubCreator.ServerTemplate templateV = null;
private String templateS = null;
protected boolean registered, started, updating;
protected boolean registered, started, stopping, updating;

/**
* Creates a SubServer
Expand Down Expand Up @@ -93,6 +93,11 @@ public boolean isOnline() {
return isRunning() && started;
}

@Override
public boolean isStopping() {
return isRunning() && stopping;
}

@Override
public void setTemplate(String template) {
this.templateV = null;
Expand Down Expand Up @@ -183,6 +188,7 @@ public ObjectMap<String> forSubData() {
sinfo.set("exec", getExecutable());
sinfo.set("running", isRunning());
sinfo.set("online", isOnline());
sinfo.set("stopping", isStopping());
sinfo.set("stop-cmd", getStopCommand());
sinfo.set("stop-action", getStopAction().toString());
sinfo.set("auto-run", SubAPI.getInstance().getInternals().servers.get().getMap("Servers").getMap(getName(), new ObjectMap<String>()).getBoolean("Run-On-Launch", false));
Expand Down
Expand Up @@ -325,8 +325,11 @@ public static void updateLang(File file) throws IOException {
existing = updated.clone();
i++;
} if (was.compareTo(new Version("21w49b")) <= 0) {
if (existing.contains("Lang")) {
updated.getMap("Lang").remove("Command.Teleport");
}

//existing = updated.clone();
existing = updated.clone();
i++;
}// if (was.compareTo(new Version("99w99a")) <= 0) {
// // do something
Expand Down Expand Up @@ -358,6 +361,13 @@ public static void updateLang(File file) throws IOException {
def.put("Bungee.List.List", "&f$str$");
def.put("Bungee.List.Divider", "&f, ");
def.put("Bungee.List.Total", "Total players online: $int$");
def.put("Signs.Create", "&aSubServers &2&l\\u00BB&a Server sign activated");
def.put("Signs.Delete", "&aSubServers &2&l\\u00BB&a Server sign removed");
def.put("Signs.Text.Error", "&f&oSubServers\\n&3$str$\\n&7Unknown Status\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Offline", "&c&oSubServers\\n&3#subserver.displayname($str$)\\n&4Offline\\n&7Click to Start");
def.put("Signs.Text.Starting", "&e&oSubServers\\n&3#subserver.displayname($str$)\\n&6Starting\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Signs.Text.Online", "&a&oSubServers\\n&3#subserver.displayname($str$)\\n&2#subserver.players($str$) Online\\n&7Click to Join");
def.put("Signs.Text.Stopping", "&e&oSubServers\\n&3#subserver.displayname($str$)\\n&6Stopping\\n&8\\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022 \\u2022");
def.put("Command.Generic.Player-Only", "&cSubServers &4&l\\u00BB&c The console cannot perform this command");
def.put("Command.Generic.Console-Only", "&cSubServers &4&l\\u00BB&c This command is for console use only");
def.put("Command.Generic.Usage", "&7SubServers &8&l\\u00BB&7 Usage: &f$str$");
Expand Down Expand Up @@ -457,7 +467,8 @@ public static void updateLang(File file) throws IOException {
def.put("Command.Delete.Disappeared", "&cSubServers &4&l\\u00BB&c Subserver &4$str$&c has disappeared");
def.put("Command.Delete.Running", "&cSubServers &4&l\\u00BB&c Cannot delete &4$str$&c while it is still running");
def.put("Command.Delete", "&aSubServers &2&l\\u00BB&a Deleting &2$int$&a subserver(s)");
def.put("Command.Teleport", "&aSubServers &2&l\\u00BB&a Teleporting &2$str$&a to server");
def.put("Command.Teleport", "&aSubServers &2&l\\u00BB&a Teleporting to &2$str$");
def.put("Command.Teleport.Others", "&aSubServers &2&l\\u00BB&a Teleporting &2$name$&a to &2$str$");
def.put("Command.Teleport.Not-Running", "&cSubServers &4&l\\u00BB&c Subserver &4$str$&c is not running");
def.put("Interface.Generic.Back", "&cBack");
def.put("Interface.Generic.Back-Arrow", "&e&l<--");
Expand Down
Expand Up @@ -289,7 +289,10 @@ public void execute(CommandSender sender, String[] args) {
sender.sendMessage(" -> Players: " + ChatColor.AQUA + server.getRemotePlayers().size() + " online");
}
sender.sendMessage(" -> MOTD: " + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
if (server instanceof SubServer && ((SubServer) server).getStopAction() != SubServer.StopAction.NONE) sender.sendMessage(" -> Stop Action: " + ChatColor.WHITE + ((SubServer) server).getStopAction().toString());
if (server instanceof SubServer) {
if (((SubServer) server).getStopAction() != SubServer.StopAction.NONE) sender.sendMessage(" -> Stop Action: " + ChatColor.WHITE + ((SubServer) server).getStopAction().toString());
if (((SubServer) server).isStopping()) sender.sendMessage(" -> Stopping: " + ChatColor.GREEN+"yes");
}
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + server.getSignature());
if (server instanceof SubServer) sender.sendMessage(" -> Logging: " + ((((SubServer) server).isLogging())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Restricted: " + ((server.isRestricted())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
Expand Down
Expand Up @@ -92,7 +92,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
public SubProtocol subprotocol;
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.18a");
public static final Version version = Version.fromString("2.18.2a");

public final Proxy mProxy;
public boolean canSudo = false;
Expand Down
Expand Up @@ -17,13 +17,19 @@
import java.util.LinkedList;
import java.util.List;

/**
* BungeeCord Chat Library Compatibility Class
*/
public class BungeeChat {
private SubPlugin plugin;

public BungeeChat(SubPlugin plugin) {
this.plugin = plugin;
}

/**
* Output for <b>/sub list</b>
*/
public void listCommand(CommandSender sender, String label) {
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> {
int i = 0;
Expand Down
@@ -0,0 +1,73 @@
package net.ME1312.SubServers.Client.Bukkit.Library.Compatibility;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

/**
* Offline Block Location Class
*/
public class OfflineBlock {
public final UUID world;
public final int x, y, z;

/**
* Convert an existing location object
*
* @param location Location
*/
public OfflineBlock(Location location) {
this(location.getWorld().getUID(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}

/**
* Store location data
*
* @param world World ID
* @param x X position
* @param y Y position
* @param z Z position
*/
public OfflineBlock(UUID world, int x, int y, int z) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}

/**
* Find the World if loaded
*
* @return World (or null if unavailable)
*/
public World world() {
return Bukkit.getWorld(this.world);
}

/**
* Find the Location if loaded
*
* @return Location (or null if unavailable)
*/
public Location load() {
World world = Bukkit.getWorld(this.world);
return (world == null)? null : new Location(world, x, y, z);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OfflineBlock that = (OfflineBlock) o;
return x == that.x && y == that.y && z == that.z && Objects.equals(world, that.world);
}

@Override
public int hashCode() {
return Objects.hash(world, x, y, z);
}
}

0 comments on commit 7433fc0

Please sign in to comment.