diff --git a/server/src/main/java/server/Server.java b/server/src/main/java/server/Server.java index c65feec..ee8e329 100755 --- a/server/src/main/java/server/Server.java +++ b/server/src/main/java/server/Server.java @@ -132,6 +132,7 @@ public final class Server implements IThreadListener, Executor { private KeyPair keyPair; private WorldServer space; private ChannelFuture endpoint; + private Position execPos; private boolean running = true; private boolean stopped; @@ -1168,19 +1169,19 @@ public final class Server implements IThreadListener, Executor { return this.keyPair.getPrivate(); } - public void logConsole(String msg) { + public void log(String msg) { Log.CONSOLE.info(msg); } public Position getExecPos() { - return null; + return this.execPos; } - public Entity getPointedEntity() { - return null; + public void setExecPos(Position pos) { + this.execPos = pos; } - public BlockPos getPointedPosition() { - return null; + public boolean isConsole() { + return true; } } diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index 12d2a92..55b3df1 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -171,13 +171,13 @@ public class CommandEnvironment { catch(RunException e) { Throwable cause = e; do { - exec.logConsole(TextColor.RED + cause.getMessage()); + exec.log(TextColor.RED + cause.getMessage()); cause = cause.getCause(); } while(cause != null); } catch(Throwable t) { - exec.logConsole(TextColor.RED + "Fehler: %s", t.getMessage()); + exec.log(TextColor.RED + "Fehler: %s", t.getMessage()); Log.CONSOLE.error(t, "Fehler beim Ausführen von Befehl '%s'", cmd); } finally { @@ -259,6 +259,7 @@ public class CommandEnvironment { this.registerExecutable(new CommandClear()); this.registerExecutable(new CommandEntity()); this.registerExecutable(new CommandItem()); - this.registerExecutable(new CommandAt()); + this.registerExecutable(new CommandRunat()); + this.registerExecutable(new CommandRunas()); } } diff --git a/server/src/main/java/server/command/Executor.java b/server/src/main/java/server/command/Executor.java index 55b1935..e628987 100644 --- a/server/src/main/java/server/command/Executor.java +++ b/server/src/main/java/server/command/Executor.java @@ -3,24 +3,29 @@ package server.command; import common.entity.Entity; import common.util.BlockPos; import common.util.Position; -import server.Server; -import server.network.Player; public interface Executor { - void logConsole(String msg); + void log(String msg); Position getExecPos(); - Entity getPointedEntity(); - BlockPos getPointedPosition(); + void setExecPos(Position pos); + + default Entity getPointedEntity() { + return null; + } + + default BlockPos getPointedPosition() { + return null; + } default boolean isConsole() { - return this instanceof Server; + return false; } default boolean isPlayer() { - return this instanceof Player; + return false; } - default void logConsole(String fmt, Object ... args) { - this.logConsole(String.format(fmt, args)); + default void log(String fmt, Object ... args) { + this.log(String.format(fmt, args)); } } diff --git a/server/src/main/java/server/command/FixedExecutor.java b/server/src/main/java/server/command/FixedExecutor.java deleted file mode 100644 index 6095089..0000000 --- a/server/src/main/java/server/command/FixedExecutor.java +++ /dev/null @@ -1,19 +0,0 @@ -package server.command; - -import common.entity.Entity; -import common.util.BlockPos; -import common.util.Position; - -public record FixedExecutor(Executor delegate, Position getExecPos) implements Executor { - public void logConsole(String msg) { - this.delegate.logConsole(msg); - } - - public Entity getPointedEntity() { - return null; - } - - public BlockPos getPointedPosition() { - return null; - } -} diff --git a/server/src/main/java/server/command/commands/CommandAdmin.java b/server/src/main/java/server/command/commands/CommandAdmin.java index dee122c..a5587c4 100644 --- a/server/src/main/java/server/command/commands/CommandAdmin.java +++ b/server/src/main/java/server/command/commands/CommandAdmin.java @@ -17,7 +17,7 @@ public class CommandAdmin extends Command { public void exec(CommandEnvironment env, Executor exec, User user) { user.setAdmin(true); if(user.isOnline()) - ((Player)user).logConsole("Du hast Administatorrechte von %s bekommen", exec.isPlayer() ? ((Player)exec).getUser() : "der Konsole"); - exec.logConsole("%s ist jetzt ein Admin", user.getUser()); + ((Player)user).log("Du hast Administatorrechte von %s bekommen", exec.isPlayer() ? ((Player)exec).getUser() : "der Konsole"); + exec.log("%s ist jetzt ein Admin", user.getUser()); } } diff --git a/server/src/main/java/server/command/commands/CommandBlock.java b/server/src/main/java/server/command/commands/CommandBlock.java index 128ca08..d0d3530 100644 --- a/server/src/main/java/server/command/commands/CommandBlock.java +++ b/server/src/main/java/server/command/commands/CommandBlock.java @@ -53,9 +53,9 @@ public class CommandBlock extends Command { } } if(success) - exec.logConsole("%s bei %d, %d, %d in %s gesetzt", state.getBlock().getDisplay(), position.getX(), position.getY(), position.getZ(), world.dimension.getFormattedName(false)); + exec.log("%s bei %d, %d, %d in %s gesetzt", state.getBlock().getDisplay(), position.getX(), position.getY(), position.getZ(), world.dimension.getFormattedName(false)); else - exec.logConsole("Block wurde nicht verändert"); + exec.log("Block wurde nicht verändert"); return success; } } diff --git a/server/src/main/java/server/command/commands/CommandClear.java b/server/src/main/java/server/command/commands/CommandClear.java index 2949e87..b221069 100644 --- a/server/src/main/java/server/command/commands/CommandClear.java +++ b/server/src/main/java/server/command/commands/CommandClear.java @@ -29,12 +29,12 @@ public class CommandClear extends Command { ((EntityNPC)entity).setItem(z, null); } } - exec.logConsole("Inventar von %s gelöscht", entity.getCommandName()); + exec.log("Inventar von %s gelöscht", entity.getCommandName()); done++; } } if(done > 1) - exec.logConsole("Inventar von %d Objekten gelöscht", done); + exec.log("Inventar von %d Objekten gelöscht", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandEntity.java b/server/src/main/java/server/command/commands/CommandEntity.java index 8f4dde7..377c5aa 100644 --- a/server/src/main/java/server/command/commands/CommandEntity.java +++ b/server/src/main/java/server/command/commands/CommandEntity.java @@ -27,20 +27,20 @@ public class CommandEntity extends Command { TagObject etag = new TagObject(); entity.writeTags(etag); if(tag == null) { - exec.logConsole("************************************************************"); - exec.logConsole("Daten von %s bei %d, %d, %d in %s:", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); - exec.logConsole(etag.format(4)); + exec.log("************************************************************"); + exec.log("Daten von %s bei %d, %d, %d in %s:", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); + exec.log(etag.format(4)); } else { etag.merge(tag); entity.readTags(etag); - exec.logConsole("Daten von %s bei %d, %d, %d in %s geändert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); + exec.log("Daten von %s bei %d, %d, %d in %s geändert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); } done++; } } if(tag != null && done > 1) - exec.logConsole("Daten von %d Objekten geändert", done); + exec.log("Daten von %d Objekten geändert", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandFind.java b/server/src/main/java/server/command/commands/CommandFind.java index 70d69dc..99e8d27 100644 --- a/server/src/main/java/server/command/commands/CommandFind.java +++ b/server/src/main/java/server/command/commands/CommandFind.java @@ -21,12 +21,12 @@ public class CommandFind extends Command { for(Entity entity : entities) { if(entity.isEntityAlive()) { BlockPos pos = entity.getPosition(); - exec.logConsole("%s bei %d, %d, %d in %s gefunden", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); + exec.log("%s bei %d, %d, %d in %s gefunden", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), entity.worldObj.dimension.getFormattedName(false)); done++; } } if(done > 1) - exec.logConsole("%d Objekte gefunden", done); + exec.log("%d Objekte gefunden", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandHelp.java b/server/src/main/java/server/command/commands/CommandHelp.java index bcf77e8..8f21e7f 100644 --- a/server/src/main/java/server/command/commands/CommandHelp.java +++ b/server/src/main/java/server/command/commands/CommandHelp.java @@ -53,7 +53,7 @@ public class CommandHelp extends Command { } }, param.parsers())) + (required ? ">" : "]")); } - exec.logConsole("%s %s", cmd.name(), Util.buildLines(" ", list)); + exec.log("%s %s", cmd.name(), Util.buildLines(" ", list)); } public void exec(CommandEnvironment env, Executor exec, String command) { diff --git a/server/src/main/java/server/command/commands/CommandItem.java b/server/src/main/java/server/command/commands/CommandItem.java index 5e291b3..00797d0 100644 --- a/server/src/main/java/server/command/commands/CommandItem.java +++ b/server/src/main/java/server/command/commands/CommandItem.java @@ -52,12 +52,12 @@ public class CommandItem extends Command { total = amount - total; if(total <= 0) continue; - exec.logConsole("%d * %s zum Inventar von %s hinzugefügt", total, stack.getDisplayName(), player.getCommandName()); + exec.log("%d * %s zum Inventar von %s hinzugefügt", total, stack.getDisplayName(), player.getCommandName()); done++; given += total; } if(done > 1) - exec.logConsole("%d * %s an %d Spieler verteilt", given, stack.getDisplayName(), done); + exec.log("%d * %s an %d Spieler verteilt", given, stack.getDisplayName(), done); return given; } } diff --git a/server/src/main/java/server/command/commands/CommandKick.java b/server/src/main/java/server/command/commands/CommandKick.java index 98cd208..2717426 100644 --- a/server/src/main/java/server/command/commands/CommandKick.java +++ b/server/src/main/java/server/command/commands/CommandKick.java @@ -17,6 +17,6 @@ public class CommandKick extends Command { public void exec(CommandEnvironment env, Executor exec, Player player, String message) { player.disconnect(message); - exec.logConsole("%s wurde vom Server geworfen", player.getUser()); + exec.log("%s wurde vom Server geworfen", player.getUser()); } } diff --git a/server/src/main/java/server/command/commands/CommandMilk.java b/server/src/main/java/server/command/commands/CommandMilk.java index faa3206..6cc2883 100644 --- a/server/src/main/java/server/command/commands/CommandMilk.java +++ b/server/src/main/java/server/command/commands/CommandMilk.java @@ -32,17 +32,17 @@ public class CommandMilk extends Command { if(type != null && entity.hasEffect(type)) { int amplifier = entity.getEffect(type).getAmplifier(); entity.removeEffect(type); - exec.logConsole("%s von %s entfernt", type.getDisplay(amplifier), entity.getCommandName()); + exec.log("%s von %s entfernt", type.getDisplay(amplifier), entity.getCommandName()); done++; } else if(type == null && !entity.getEffects().isEmpty()) { entity.clearEffects(negative); - exec.logConsole("Alle Effekte von %s entfernt", entity.getCommandName()); + exec.log("Alle Effekte von %s entfernt", entity.getCommandName()); done++; } } if(done > 1) - exec.logConsole(type == null ? "Alle Effekte von %d Objekten entfernt" : "%d Effekte entfernt", entities.size()); + exec.log(type == null ? "Alle Effekte von %d Objekten entfernt" : "%d Effekte entfernt", entities.size()); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandOfflinetp.java b/server/src/main/java/server/command/commands/CommandOfflinetp.java index 1de1335..55a3dba 100644 --- a/server/src/main/java/server/command/commands/CommandOfflinetp.java +++ b/server/src/main/java/server/command/commands/CommandOfflinetp.java @@ -34,7 +34,7 @@ public class CommandOfflinetp extends Command { throw new RunException("Spieler '%s' konnte nicht gefunden werden", user); for(Entity entity : entities) { entity.teleport(pos); - exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); + exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); } return entities.size(); } diff --git a/server/src/main/java/server/command/commands/CommandPasswd.java b/server/src/main/java/server/command/commands/CommandPasswd.java index b9e467d..6b3085b 100644 --- a/server/src/main/java/server/command/commands/CommandPasswd.java +++ b/server/src/main/java/server/command/commands/CommandPasswd.java @@ -50,20 +50,20 @@ public class CommandPasswd extends Command { protected void accept() { User plr = env.getServer().getUser(user.getUser()); if(!((Player)exec).isAdmin() || plr == null || (plr.isAdmin() && plr != exec) || (plr.getPasswordHash() == null && plr == exec) || (plr.getPubkey() != null && plr == exec)) { - exec.logConsole(TextColor.DRED + "Ein Fehler ist aufgetreten"); + exec.log(TextColor.DRED + "Ein Fehler ist aufgetreten"); return; } if(this.checkField != null && !MessageDigest.isEqual(EncryptUtil.hashPassword(this.checkField.get(), plr.getPasswordHash().second()), plr.getPasswordHash().first())) { - exec.logConsole(TextColor.RED + "Falsches Passwort eingegeben"); + exec.log(TextColor.RED + "Falsches Passwort eingegeben"); return; } if(!this.passwordField.get().equals(this.confirmField.get())) { - exec.logConsole(TextColor.RED + "Passwörter stimmen nicht überein"); + exec.log(TextColor.RED + "Passwörter stimmen nicht überein"); return; } plr.setPasswordHash(EncryptUtil.hashPassword(this.passwordField.get())); plr.setPubkey(null); - exec.logConsole(TextColor.GREEN + "Passwort" + (plr != exec ? " für %s" : "") + " gesetzt", plr.getUser()); + exec.log(TextColor.GREEN + "Passwort" + (plr != exec ? " für %s" : "") + " gesetzt", plr.getUser()); } }); } @@ -74,7 +74,7 @@ public class CommandPasswd extends Command { throw new RunException("Das Passwort ist zu kurz, mindestens 8 Zeichen sind erforderlich"); user.setPasswordHash(EncryptUtil.hashPassword(password)); user.setPubkey(null); - exec.logConsole(TextColor.GREEN + "Passwort für %s gesetzt", user.getUser()); + exec.log(TextColor.GREEN + "Passwort für %s gesetzt", user.getUser()); } } } diff --git a/server/src/main/java/server/command/commands/CommandPlayers.java b/server/src/main/java/server/command/commands/CommandPlayers.java index 1bddfe3..fe2bcb9 100644 --- a/server/src/main/java/server/command/commands/CommandPlayers.java +++ b/server/src/main/java/server/command/commands/CommandPlayers.java @@ -21,13 +21,13 @@ public class CommandPlayers extends Command { public void exec(CommandEnvironment env, Executor exec, boolean coords) { List players = env.getServer().getPlayers(); if(players.isEmpty()) { - exec.logConsole(TextColor.DGRAY + "Es sind keine Spieler online"); + exec.log(TextColor.DGRAY + "Es sind keine Spieler online"); return; } - exec.logConsole(TextColor.GREEN + "Es " + (players.size() == 1 ? "ist" : "sind") + " " + TextColor.YELLOW + "%d" + TextColor.GREEN + " Spieler online", players.size()); + exec.log(TextColor.GREEN + "Es " + (players.size() == 1 ? "ist" : "sind") + " " + TextColor.YELLOW + "%d" + TextColor.GREEN + " Spieler online", players.size()); for(Player player : players) { EntityNPC entity = player.getPresentEntity(); - exec.logConsole("%s%s" + TextColor.GRAY + ": '%s" + TextColor.GRAY + "'" + (coords ? " [" + TextColor.ORANGE + "%s @ %d, %d, %d" + TextColor.GRAY + "]" : ""), player.isAdmin() ? TextColor.RED : TextColor.NEON, player.getUser(), entity == null ? TextColor.DGRAY + "<->" : TextColor.ACID + entity.getCommandName(), entity == null ? null : entity.worldObj.dimension.getFormattedName(false), entity == null ? null : ExtMath.floord(entity.posX), entity == null ? null : ExtMath.floord(entity.posY), entity == null ? null : ExtMath.floord(entity.posZ)); + exec.log("%s%s" + TextColor.GRAY + ": '%s" + TextColor.GRAY + "'" + (coords ? " [" + TextColor.ORANGE + "%s @ %d, %d, %d" + TextColor.GRAY + "]" : ""), player.isAdmin() ? TextColor.RED : TextColor.NEON, player.getUser(), entity == null ? TextColor.DGRAY + "<->" : TextColor.ACID + entity.getCommandName(), entity == null ? null : entity.worldObj.dimension.getFormattedName(false), entity == null ? null : ExtMath.floord(entity.posX), entity == null ? null : ExtMath.floord(entity.posY), entity == null ? null : ExtMath.floord(entity.posZ)); } } } diff --git a/server/src/main/java/server/command/commands/CommandPotion.java b/server/src/main/java/server/command/commands/CommandPotion.java index bdfa531..87bf9da 100644 --- a/server/src/main/java/server/command/commands/CommandPotion.java +++ b/server/src/main/java/server/command/commands/CommandPotion.java @@ -39,14 +39,14 @@ public class CommandPotion extends Command { entity.addEffect(effect); } if(type.isInstant() || duration == 0) - exec.logConsole("%s an %s gegeben", type.getDisplay(strength - 1), entity.getCommandName()); + exec.log("%s an %s gegeben", type.getDisplay(strength - 1), entity.getCommandName()); else - exec.logConsole("%s für %d Sekunden an %s gegeben", type.getDisplay(strength - 1), duration, entity.getCommandName()); + exec.log("%s für %d Sekunden an %s gegeben", type.getDisplay(strength - 1), duration, entity.getCommandName()); done++; } } if(done > 1) - exec.logConsole("%d Effekte vergeben", done); + exec.log("%d Effekte vergeben", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandPubkey.java b/server/src/main/java/server/command/commands/CommandPubkey.java index bc4a208..74384ab 100644 --- a/server/src/main/java/server/command/commands/CommandPubkey.java +++ b/server/src/main/java/server/command/commands/CommandPubkey.java @@ -48,11 +48,11 @@ public class CommandPubkey extends Command { protected void accept() { User plr = env.getServer().getUser(user.getUser()); if(!((Player)exec).isAdmin() || plr == null || (plr.isAdmin() && plr != exec)) { - exec.logConsole(TextColor.DRED + "Ein Fehler ist aufgetreten"); + exec.log(TextColor.DRED + "Ein Fehler ist aufgetreten"); return; } if(this.checkField != null && plr.getPasswordHash() != null && !MessageDigest.isEqual(EncryptUtil.hashPassword(this.checkField.get(), plr.getPasswordHash().second()), plr.getPasswordHash().first())) { - exec.logConsole(TextColor.RED + "Falsches Passwort eingegeben"); + exec.log(TextColor.RED + "Falsches Passwort eingegeben"); return; } Pair key; @@ -60,12 +60,12 @@ public class CommandPubkey extends Command { key = EncryptUtil.parseArmoredPubkey(this.keyField.get()); } catch(IllegalArgumentException e) { - exec.logConsole(TextColor.RED + "Ungültiger Schlüssel"); + exec.log(TextColor.RED + "Ungültiger Schlüssel"); return; } plr.setPasswordHash(null); plr.setPubkey(key.first()); - exec.logConsole(TextColor.GREEN + "Schlüssel" + (plr != exec ? " für %s" : "") + " gesetzt", plr.getUser()); + exec.log(TextColor.GREEN + "Schlüssel" + (plr != exec ? " für %s" : "") + " gesetzt", plr.getUser()); } }); } @@ -81,7 +81,7 @@ public class CommandPubkey extends Command { } user.setPasswordHash(null); user.setPubkey(key.first()); - exec.logConsole(TextColor.GREEN + "Schlüssel für %s gesetzt", user.getUser()); + exec.log(TextColor.GREEN + "Schlüssel für %s gesetzt", user.getUser()); } } } diff --git a/server/src/main/java/server/command/commands/CommandRegister.java b/server/src/main/java/server/command/commands/CommandRegister.java index dc1eaab..5e315f5 100644 --- a/server/src/main/java/server/command/commands/CommandRegister.java +++ b/server/src/main/java/server/command/commands/CommandRegister.java @@ -45,18 +45,18 @@ public class CommandRegister extends Command { protected void accept() { if(!((Player)exec).isAdmin() || env.getServer().getUser(username) != null || env.getServer().loadPlayerData(username) != null) { - exec.logConsole(TextColor.DRED + "Ein Fehler ist aufgetreten"); + exec.log(TextColor.DRED + "Ein Fehler ist aufgetreten"); return; } if(!this.passwordField.get().equals(this.confirmField.get())) { - exec.logConsole(TextColor.RED + "Passwörter stimmen nicht überein"); + exec.log(TextColor.RED + "Passwörter stimmen nicht überein"); return; } User user = new User(username); user.setPasswordHash(EncryptUtil.hashPassword(this.passwordField.get())); user.setAdmin(admin); env.getServer().addUser(user); - exec.logConsole(TextColor.GREEN + "Spieler %s registriert", username); + exec.log(TextColor.GREEN + "Spieler %s registriert", username); } }); } @@ -69,7 +69,7 @@ public class CommandRegister extends Command { user.setPasswordHash(EncryptUtil.hashPassword(password)); user.setAdmin(admin); env.getServer().addUser(user); - exec.logConsole(TextColor.GREEN + "Spieler %s registriert", username); + exec.log(TextColor.GREEN + "Spieler %s registriert", username); } } } diff --git a/server/src/main/java/server/command/commands/CommandRegkey.java b/server/src/main/java/server/command/commands/CommandRegkey.java index 0c635f5..451c0b3 100644 --- a/server/src/main/java/server/command/commands/CommandRegkey.java +++ b/server/src/main/java/server/command/commands/CommandRegkey.java @@ -48,7 +48,7 @@ public class CommandRegkey extends Command { protected void accept() { if(!((Player)exec).isAdmin() || env.getServer().getUser(username) != null || env.getServer().loadPlayerData(username) != null) { - exec.logConsole(TextColor.DRED + "Ein Fehler ist aufgetreten"); + exec.log(TextColor.DRED + "Ein Fehler ist aufgetreten"); return; } Pair key; @@ -56,14 +56,14 @@ public class CommandRegkey extends Command { key = EncryptUtil.parseArmoredPubkey(this.keyField.get()); } catch(IllegalArgumentException e) { - exec.logConsole(TextColor.RED + "Ungültiger Schlüssel"); + exec.log(TextColor.RED + "Ungültiger Schlüssel"); return; } User user = new User(username); user.setPubkey(key.first()); user.setAdmin(admin); env.getServer().addUser(user); - exec.logConsole(TextColor.GREEN + "Spieler %s registriert", username); + exec.log(TextColor.GREEN + "Spieler %s registriert", username); } }); } @@ -81,7 +81,7 @@ public class CommandRegkey extends Command { user.setPubkey(key.first()); user.setAdmin(admin); env.getServer().addUser(user); - exec.logConsole(TextColor.GREEN + "Spieler %s registriert", username); + exec.log(TextColor.GREEN + "Spieler %s registriert", username); } } } diff --git a/server/src/main/java/server/command/commands/CommandRemove.java b/server/src/main/java/server/command/commands/CommandRemove.java index 1c7de10..56044bc 100644 --- a/server/src/main/java/server/command/commands/CommandRemove.java +++ b/server/src/main/java/server/command/commands/CommandRemove.java @@ -26,12 +26,12 @@ public class CommandRemove extends Command { entity.kill(); else entity.setDead(); - exec.logConsole(kill ? "%s getötet" : "%s entfernt", entity.getCommandName()); + exec.log(kill ? "%s getötet" : "%s entfernt", entity.getCommandName()); done++; } } if(done > 1) - exec.logConsole(kill ? "%d Objekte getötet" : "%d Objekte entfernt", done); + exec.log(kill ? "%d Objekte getötet" : "%d Objekte entfernt", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandRevoke.java b/server/src/main/java/server/command/commands/CommandRevoke.java index 2b09323..cea782a 100644 --- a/server/src/main/java/server/command/commands/CommandRevoke.java +++ b/server/src/main/java/server/command/commands/CommandRevoke.java @@ -20,7 +20,7 @@ public class CommandRevoke extends Command { throw new RunException("Dieser Befehl kann nur der Konsole ausgeführt werden"); user.setAdmin(false); if(user.isOnline()) - ((Player)user).logConsole("Der Host hat deine Administatorrechte entfernt"); - exec.logConsole("%s ist jetzt kein Admin mehr", user.getUser()); + ((Player)user).log("Der Host hat deine Administatorrechte entfernt"); + exec.log("%s ist jetzt kein Admin mehr", user.getUser()); } } diff --git a/server/src/main/java/server/command/commands/CommandRunas.java b/server/src/main/java/server/command/commands/CommandRunas.java new file mode 100644 index 0000000..caae85b --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandRunas.java @@ -0,0 +1,26 @@ +package server.command.commands; + +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.UserPolicy; +import server.network.Player; + +public class CommandRunas extends Command { + public CommandRunas() { + super("~"); + + this.addPlayer("player", false, UserPolicy.NON_ADMINS_NOT_SELF); + this.addString("command", false); + } + + public void exec(CommandEnvironment env, Executor exec, Player player, String command) { + try { + player.setForcedExec(exec); + env.execute(command, player); + } + finally { + player.setForcedExec(null); + } + } +} diff --git a/server/src/main/java/server/command/commands/CommandAt.java b/server/src/main/java/server/command/commands/CommandRunat.java similarity index 69% rename from server/src/main/java/server/command/commands/CommandAt.java rename to server/src/main/java/server/command/commands/CommandRunat.java index c20e451..0acbeb9 100644 --- a/server/src/main/java/server/command/commands/CommandAt.java +++ b/server/src/main/java/server/command/commands/CommandRunat.java @@ -6,11 +6,10 @@ import common.entity.Entity; import server.command.Command; import server.command.CommandEnvironment; import server.command.Executor; -import server.command.FixedExecutor; import server.command.UserPolicy; -public class CommandAt extends Command { - public CommandAt() { +public class CommandRunat extends Command { + public CommandRunat() { super("@"); this.addEntityList("entities", false, UserPolicy.NON_ADMINS_NOT_SELF); @@ -21,12 +20,18 @@ public class CommandAt extends Command { int done = 0; for(Entity entity : entities) { if(entity.isEntityAlive()) { - env.execute(command, new FixedExecutor(exec, entity.getPos())); + try { + exec.setExecPos(entity.getPos()); + env.execute(command, exec); + } + finally { + exec.setExecPos(null); + } done++; } } if(done > 1) - exec.logConsole("%d Objekte gefunden", done); + exec.log("Befehl bei %d Objekten ausgeführt", done); return done; } } diff --git a/server/src/main/java/server/command/commands/CommandSave.java b/server/src/main/java/server/command/commands/CommandSave.java index fc2491e..36e9b02 100644 --- a/server/src/main/java/server/command/commands/CommandSave.java +++ b/server/src/main/java/server/command/commands/CommandSave.java @@ -20,16 +20,16 @@ public class CommandSave extends Command { public void exec(CommandEnvironment env, Executor exec, boolean message, boolean flush) { if(message) env.getServer().sendPacket(new SPacketMessage(TextColor.RED + "Speichere Serverdaten, der Server könnte kurz einfrieren", Type.FEED)); - exec.logConsole(TextColor.ORANGE + "Speichere Spielerdaten ..."); + exec.log(TextColor.ORANGE + "Speichere Spielerdaten ..."); env.getServer().saveAllPlayerData(true); - exec.logConsole(TextColor.ORANGE + "Speichere Weltdaten ..."); + exec.log(TextColor.ORANGE + "Speichere Weltdaten ..."); env.getServer().saveAllWorlds(true); env.getServer().resetSaveTimer(); if(flush) { - exec.logConsole(TextColor.ORANGE + "Beende E/A ..."); + exec.log(TextColor.ORANGE + "Beende E/A ..."); Region.finishWrite(); } - exec.logConsole(TextColor.DGREEN + "Alle Serverdaten wurden gespeichert"); + exec.log(TextColor.DGREEN + "Alle Serverdaten wurden gespeichert"); if(message) env.getServer().sendPacket(new SPacketMessage(TextColor.GREEN + "Die Serverdaten wurden gespeichert", Type.FEED)); } diff --git a/server/src/main/java/server/command/commands/CommandSeed.java b/server/src/main/java/server/command/commands/CommandSeed.java index f3e4ddb..1879edc 100644 --- a/server/src/main/java/server/command/commands/CommandSeed.java +++ b/server/src/main/java/server/command/commands/CommandSeed.java @@ -17,8 +17,8 @@ public class CommandSeed extends Command { public Object exec(CommandEnvironment env, Executor exec, WorldServer world, boolean dump) { if(dump) - exec.logConsole("Daten: %s", world.dimension.dumpTags().format(4)); - exec.logConsole("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed()); + exec.log("Daten: %s", world.dimension.dumpTags().format(4)); + exec.log("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed()); return world.dimension.getSeed(); } } diff --git a/server/src/main/java/server/command/commands/CommandSpawn.java b/server/src/main/java/server/command/commands/CommandSpawn.java index 74c72d7..dbb77ad 100644 --- a/server/src/main/java/server/command/commands/CommandSpawn.java +++ b/server/src/main/java/server/command/commands/CommandSpawn.java @@ -55,7 +55,7 @@ public class CommandSpawn extends Command { tag != null && tag.hasInt("damage") ? tag.getInt("damage") : 0, tag != null && tag.hasBool("fire") && tag.getBool("fire"), exec.isPlayer() && tag != null && tag.hasBool("summoned") && tag.getBool("summoned") ? ((Player)exec).getPresentEntity() : null); } - exec.logConsole("%sBlitz bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); + exec.log("%sBlitz bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); return null; } else { @@ -82,7 +82,7 @@ public class CommandSpawn extends Command { } spawned.add("#" + entity.getId()); } - exec.logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); + exec.log("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); return Util.buildLines(",", spawned); } } diff --git a/server/src/main/java/server/command/commands/CommandSv.java b/server/src/main/java/server/command/commands/CommandSv.java index b22b03b..a6acbbf 100644 --- a/server/src/main/java/server/command/commands/CommandSv.java +++ b/server/src/main/java/server/command/commands/CommandSv.java @@ -59,9 +59,9 @@ public class CommandSv extends Command { if(value != null) throw new RunException("Kann keinen Wert ohne eine Variable angeben"); for(Entry entry : env.getServer().getVariables().entrySet()) { - exec.logConsole(this.formatVariable(entry.getKey(), entry.getValue(), "=", true)); + exec.log(this.formatVariable(entry.getKey(), entry.getValue(), "=", true)); } - exec.logConsole(TextColor.GREEN + "SVARs insgesamt registriert: %d", env.getServer().getVariables().size()); + exec.log(TextColor.GREEN + "SVARs insgesamt registriert: %d", env.getServer().getVariables().size()); return null; } SVar sv = env.getServer().getVariables().get(variable); @@ -94,7 +94,7 @@ public class CommandSv extends Command { } sv.set(value, false, true); } - exec.logConsole(this.formatVariable(variable, sv, value == null ? "=" : "->", false)); + exec.log(this.formatVariable(variable, sv, value == null ? "=" : "->", false)); return sv.noDef && sv.def.equals(sv.get()) ? null : sv.get(); } } diff --git a/server/src/main/java/server/command/commands/CommandTele.java b/server/src/main/java/server/command/commands/CommandTele.java index 98c7db2..8baf2f2 100644 --- a/server/src/main/java/server/command/commands/CommandTele.java +++ b/server/src/main/java/server/command/commands/CommandTele.java @@ -27,7 +27,7 @@ public class CommandTele extends Command { public Object exec(CommandEnvironment env, Executor exec, Vec3 position, Dimension dim, Double yaw, Double pitch, List entities) { for(Entity entity : entities) { entity.teleport(position.xCoord, position.yCoord, position.zCoord, yaw == null ? entity.rotYaw : yaw.floatValue(), pitch == null ? entity.rotPitch : pitch.floatValue(), dim.getDimensionId()); - exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)position.xCoord, (int)position.yCoord, (int)position.zCoord, dim.getFormattedName(false)); + exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)position.xCoord, (int)position.yCoord, (int)position.zCoord, dim.getFormattedName(false)); } return entities.size(); } diff --git a/server/src/main/java/server/command/commands/CommandTime.java b/server/src/main/java/server/command/commands/CommandTime.java index 0953cf6..bcbbf59 100644 --- a/server/src/main/java/server/command/commands/CommandTime.java +++ b/server/src/main/java/server/command/commands/CommandTime.java @@ -90,7 +90,7 @@ public class CommandTime extends Command { dim.setDayTime(time); dim.resetWeather(); } - exec.logConsole("Zeit auf %s gesetzt", ItemSpaceNavigator.formatImperialTime(world, false)); + exec.log("Zeit auf %s gesetzt", ItemSpaceNavigator.formatImperialTime(world, false)); return time; } } diff --git a/server/src/main/java/server/command/commands/CommandTp.java b/server/src/main/java/server/command/commands/CommandTp.java index f4ec737..cc4595b 100644 --- a/server/src/main/java/server/command/commands/CommandTp.java +++ b/server/src/main/java/server/command/commands/CommandTp.java @@ -23,7 +23,7 @@ public class CommandTp extends Command { Position pos = target.getPos(); for(Entity entity : entities) { entity.teleport(pos); - exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); + exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); } return entities.size(); } diff --git a/server/src/main/java/server/command/commands/CommandUsers.java b/server/src/main/java/server/command/commands/CommandUsers.java index 212ac13..74da5a0 100644 --- a/server/src/main/java/server/command/commands/CommandUsers.java +++ b/server/src/main/java/server/command/commands/CommandUsers.java @@ -15,12 +15,12 @@ public class CommandUsers extends Command { public void exec(CommandEnvironment env, Executor exec) { Collection users = env.getServer().getUsers(); if(users.isEmpty()) { - exec.logConsole(TextColor.DGRAY + "Es sind keine Spieler registriert"); + exec.log(TextColor.DGRAY + "Es sind keine Spieler registriert"); return; } - exec.logConsole(TextColor.GREEN + "Es " + (users.size() == 1 ? "ist" : "sind") + " " + TextColor.YELLOW + "%d" + TextColor.GREEN + " Spieler registriert", users.size()); + exec.log(TextColor.GREEN + "Es " + (users.size() == 1 ? "ist" : "sind") + " " + TextColor.YELLOW + "%d" + TextColor.GREEN + " Spieler registriert", users.size()); for(User user : users) { - exec.logConsole("%s%s" + TextColor.GRAY + ": %s" + TextColor.GRAY + ", %s", user.isAdmin() ? TextColor.RED : TextColor.NEON, user.getUser(), user.isOnline() ? TextColor.DGREEN + "Online" : TextColor.DGRAY + "Offline", user.getPubkey() != null ? TextColor.YELLOW + "Pubkey" : (user.getPasswordHash() != null ? TextColor.MAGENTA + "Passwort" : TextColor.BLACK + "Kein Login")); + exec.log("%s%s" + TextColor.GRAY + ": %s" + TextColor.GRAY + ", %s", user.isAdmin() ? TextColor.RED : TextColor.NEON, user.getUser(), user.isOnline() ? TextColor.DGREEN + "Online" : TextColor.DGRAY + "Offline", user.getPubkey() != null ? TextColor.YELLOW + "Pubkey" : (user.getPasswordHash() != null ? TextColor.MAGENTA + "Passwort" : TextColor.BLACK + "Kein Login")); } } } diff --git a/server/src/main/java/server/command/commands/CommandWarp.java b/server/src/main/java/server/command/commands/CommandWarp.java index f2e7cf7..85bc447 100644 --- a/server/src/main/java/server/command/commands/CommandWarp.java +++ b/server/src/main/java/server/command/commands/CommandWarp.java @@ -48,7 +48,7 @@ public class CommandWarp extends Command { // } for(Entity entity : entities) { entity.teleport(pos); - exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); + exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x(), (int)pos.y(), (int)pos.z(), UniverseRegistry.getDimension(pos.dim()).getFormattedName(false)); } return entities.size(); } diff --git a/server/src/main/java/server/command/commands/CommandWeather.java b/server/src/main/java/server/command/commands/CommandWeather.java index 2c3d0fc..25313c6 100644 --- a/server/src/main/java/server/command/commands/CommandWeather.java +++ b/server/src/main/java/server/command/commands/CommandWeather.java @@ -26,6 +26,6 @@ public class CommandWeather extends Command { world.setWeather(weather); if(!transition) world.resetWeather(); - exec.logConsole("Wetter in %s zu %s geändert", world.dimension.getFormattedName(false), weather.getDisplay()); + exec.log("Wetter in %s zu %s geändert", world.dimension.getFormattedName(false), weather.getDisplay()); } } diff --git a/server/src/main/java/server/command/commands/CommandWorld.java b/server/src/main/java/server/command/commands/CommandWorld.java index 8819d59..316fc18 100644 --- a/server/src/main/java/server/command/commands/CommandWorld.java +++ b/server/src/main/java/server/command/commands/CommandWorld.java @@ -33,7 +33,7 @@ public class CommandWorld extends Command { pos = pos.up(); } entity.teleport(pos, world.dimension.getDimensionId()); - exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), world.dimension.getFormattedName(false)); + exec.log("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), pos.getX(), pos.getY(), pos.getZ(), world.dimension.getFormattedName(false)); } return entities.size(); } diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 962faf1..134abab 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -204,8 +204,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer private final List loadedChunks = new LinkedList(); private final List destroyedItemsNetCache = new LinkedList(); -// private final Set statsQueue = Sets.newHashSet(); -// private final Map stats = Maps.newConcurrentMap(); + + private Position forcedPos; + private Executor forcedExec; public Player(Server server, NetConnection connection, String user) { @@ -1900,12 +1901,35 @@ public class Player extends User implements ICrafting, Executor, IPlayer // return Lists.newArrayList(); } - public void logConsole(String msg) { - this.addConsole(msg); + public void setForcedExec(Executor forced) { + this.forcedExec = forced; + } + + public void setExecPos(Position pos) { + this.forcedPos = pos; + } + + public void log(String msg) { + if(this.forcedExec != null) + this.forcedExec.log(TextColor.ACID + "Als " + TextColor.GREEN + "%s" + TextColor.DGRAY + ": " + TextColor.RESET + "%s", this.getUser(), msg); + else + this.addConsole(msg); } public Position getExecPos() { - return this.entity != null ? this.entity.getPos() : null; + return this.forcedPos != null ? this.forcedPos : (this.entity != null ? this.entity.getPos() : null); + } + + public Entity getPointedEntity() { + return this.pointedEntity != -1 && this.entity != null ? this.entity.worldObj.getEntityByID(this.pointedEntity) : null; + } + + public BlockPos getPointedPosition() { + return this.pointedPosition; + } + + public boolean isPlayer() { + return true; } public void processMessage(CPacketMessage packetIn) @@ -3059,14 +3083,6 @@ public class Player extends User implements ICrafting, Executor, IPlayer this.getNextFormId(); this.sendPacket(new SPacketDisplayForm(this.currentFormId, form.getTitle(), form.getInputList())); } - - public Entity getPointedEntity() { - return this.pointedEntity != -1 && this.entity != null ? this.entity.worldObj.getEntityByID(this.pointedEntity) : null; - } - - public BlockPos getPointedPosition() { - return this.pointedPosition; - } public List getLoadedChunkList() { return this.loadedChunks;