From a9770ecea155b35b259216fdf9a95f3f7d908d97 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 17 Jun 2025 14:27:55 +0200 Subject: [PATCH] add god+noclip command, fix completion list bug --- .../java/common/entity/npc/EntityNPC.java | 32 ++++++++++++++++ .../server/command/CommandEnvironment.java | 2 + .../command/PlayerEntityListParser.java | 2 +- .../java/server/command/PlayerListParser.java | 2 +- .../java/server/command/PlayerParser.java | 2 +- .../main/java/server/command/UserParser.java | 2 +- .../server/command/commands/CommandGod.java | 35 +++++++++++++++++ .../command/commands/CommandNoclip.java | 38 +++++++++++++++++++ .../src/main/java/server/network/Player.java | 32 ++-------------- 9 files changed, 115 insertions(+), 32 deletions(-) create mode 100644 server/src/main/java/server/command/commands/CommandGod.java create mode 100644 server/src/main/java/server/command/commands/CommandNoclip.java diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 9c8728f..83a970f 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -4630,4 +4630,36 @@ public abstract class EntityNPC extends EntityLiving public EntityType getType() { return EntityType.NPC; } + + public void setGodMode(boolean god) { + this.fallDistance = 0.0F; + if(!god) { + this.removeEffect(Potion.HASTE); + this.removeEffect(Potion.RESISTANCE); + this.removeEffect(Potion.FIRE_RESISTANCE); + this.removeEffect(Potion.FLYING); + this.removeEffect(Potion.MANA_GENERATION); + } + else { + this.extinguish(); + this.setHealth(this.getMaxHealth()); + this.setManaPoints(this.getMaxMana()); + this.clearEffects(false); + this.addEffect(new PotionEffect(Potion.HASTE, Integer.MAX_VALUE, 255, false, false)); + this.addEffect(new PotionEffect(Potion.RESISTANCE, Integer.MAX_VALUE, 255, false, false)); + this.addEffect(new PotionEffect(Potion.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false)); + this.addEffect(new PotionEffect(Potion.FLYING, Integer.MAX_VALUE, 1, false, false)); + this.addEffect(new PotionEffect(Potion.MANA_GENERATION, Integer.MAX_VALUE, 255, false, false)); + } + } + + public void setNoclip(boolean noclip) { + if(noclip) + this.mountEntity(null); + this.noclip = noclip; + this.flying &= this.hasEffect(Potion.FLYING) || this.noclip || this.canNaturallyFly(); + this.fallDistance = 0.0F; + if(this.connection != null) + this.connection.sendPlayerAbilities(); + } } diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index 0f9b257..5e35734 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -263,5 +263,7 @@ public class CommandEnvironment { this.registerExecutable(new CommandRunas()); this.registerExecutable(new CommandExp()); this.registerExecutable(new CommandMagic()); + this.registerExecutable(new CommandGod()); + this.registerExecutable(new CommandNoclip()); } } diff --git a/server/src/main/java/server/command/PlayerEntityListParser.java b/server/src/main/java/server/command/PlayerEntityListParser.java index 75a077d..cf0c39d 100644 --- a/server/src/main/java/server/command/PlayerEntityListParser.java +++ b/server/src/main/java/server/command/PlayerEntityListParser.java @@ -45,7 +45,7 @@ public class PlayerEntityListParser extends PlayerEntityParser { } public Collection getCompletions(CommandEnvironment env) { - Collection comp = super.getCompletions(env); + Collection comp = Lists.newArrayList(super.getCompletions(env)); comp.add("*"); return comp; } diff --git a/server/src/main/java/server/command/PlayerListParser.java b/server/src/main/java/server/command/PlayerListParser.java index 5f9e7e2..1b8d6be 100644 --- a/server/src/main/java/server/command/PlayerListParser.java +++ b/server/src/main/java/server/command/PlayerListParser.java @@ -38,7 +38,7 @@ public class PlayerListParser extends PlayerParser { } public Collection getCompletions(CommandEnvironment env) { - Collection comp = super.getCompletions(env); + Collection comp = Lists.newArrayList(super.getCompletions(env)); comp.add("*"); return comp; } diff --git a/server/src/main/java/server/command/PlayerParser.java b/server/src/main/java/server/command/PlayerParser.java index 8a915cd..f01f9b6 100644 --- a/server/src/main/java/server/command/PlayerParser.java +++ b/server/src/main/java/server/command/PlayerParser.java @@ -29,7 +29,7 @@ public class PlayerParser extends CompletingParser { } public Collection getCompletions(CommandEnvironment env) { - return Filter.filter(env.getServer().getAllPlayerNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getPlayer(user))); + return Filter.filter(env.getServer().getAllPlayerNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getPlayer(user))); // add Lists.newArrayList if modifying! } public Class getTypeClass(boolean required) { diff --git a/server/src/main/java/server/command/UserParser.java b/server/src/main/java/server/command/UserParser.java index 69761b4..da291e9 100644 --- a/server/src/main/java/server/command/UserParser.java +++ b/server/src/main/java/server/command/UserParser.java @@ -30,7 +30,7 @@ public class UserParser extends CompletingParser { } public Collection getCompletions(CommandEnvironment env) { - return Filter.filter(env.getServer().getAllUserNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getUser(user))); + return Filter.filter(env.getServer().getAllUserNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getUser(user))); // add Lists.newArrayList if modifying! } public Class getTypeClass(boolean required) { diff --git a/server/src/main/java/server/command/commands/CommandGod.java b/server/src/main/java/server/command/commands/CommandGod.java new file mode 100644 index 0000000..ef5c51f --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandGod.java @@ -0,0 +1,35 @@ +package server.command.commands; + +import java.util.List; + +import common.color.TextColor; +import common.entity.npc.EntityNPC; +import common.potion.Potion; +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.UserPolicy; + +public class CommandGod extends Command { + public CommandGod() { + super("god"); + + this.addPlayerEntityList("players", true, UserPolicy.NON_ADMINS_OR_SELF); + this.setParamsOptional(); + this.addFlag("remove", 'r'); + this.addFlag("quiet", 'q'); + } + + public void exec(CommandEnvironment env, Executor exec, List players, boolean remove, boolean quiet) { + remove = !remove && exec.isPlayer() && players.size() == 1 && players.get(0).connection == exec ? players.get(0).hasEffect(Potion.HASTE) && players.get(0).getEffect(Potion.HASTE).getAmplifier() == 255 : remove; + for(EntityNPC player : players) { + player.setGodMode(!remove); + if(!quiet) + player.connection.addFeed(!remove ? (TextColor.GREEN + "Statuseffekte wurden hinzugefügt") : (TextColor.RED + "Statuseffekte wurden entfernt")); + if(quiet || player.connection != exec) + exec.log("Statuseffekte " + (!remove ? "an %s gegeben" : "von %s entfernt"), player.getCommandName()); + } + if(players.size() > 1) + exec.log("Statuseffekte " + (!remove ? "an %d Spieler gegeben" : "von %d Spielern entfernt"), players.size()); + } +} diff --git a/server/src/main/java/server/command/commands/CommandNoclip.java b/server/src/main/java/server/command/commands/CommandNoclip.java new file mode 100644 index 0000000..46edf72 --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandNoclip.java @@ -0,0 +1,38 @@ +package server.command.commands; + +import java.util.List; + +import common.color.TextColor; +import common.entity.npc.EntityNPC; +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.UserPolicy; + +public class CommandNoclip extends Command { + public CommandNoclip() { + super("noclip"); + + this.addPlayerEntityList("players", true, UserPolicy.NON_ADMINS_OR_SELF); + this.setParamsOptional(); + this.addFlag("remove", 'r'); + this.addFlag("quiet", 'q'); + } + + public void exec(CommandEnvironment env, Executor exec, List players, boolean remove, boolean quiet) { + int done = 0; + remove = !remove && exec.isPlayer() && players.size() == 1 && players.get(0).connection == exec ? players.get(0).noclip : remove; + for(EntityNPC player : players) { + if(player.noclip == !remove) + continue; + player.setNoclip(!remove); + if(!quiet) + player.connection.addFeed((!remove ? TextColor.GREEN : TextColor.RED) + "NoClip wurde " + (!remove ? "eingeschaltet" : "ausgeschaltet")); + if(quiet || player.connection != exec) + exec.log("NoClip für %s " + (!remove ? "eingeschaltet" : "ausgeschaltet"), player.getCommandName()); + done++; + } + if(done > 1) + exec.log("NoClip von %d Spielern " + (!remove ? "eingeschaltet" : "ausgeschaltet"), done); + } +} diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 85338fd..139fd28 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -2674,39 +2674,15 @@ public class Player extends User implements ICrafting, Executor, IPlayer case GOD: if(this.isAdmin()) { -// this.playerEntity.setCheat(!this.playerEntity.godmode); - this.entity.fallDistance = 0.0F; - if(this.entity.hasEffect(Potion.HASTE) && this.entity.getEffect(Potion.HASTE).getAmplifier() == 255) { - this.entity.removeEffect(Potion.HASTE); - this.entity.removeEffect(Potion.RESISTANCE); - this.entity.removeEffect(Potion.FIRE_RESISTANCE); - this.entity.removeEffect(Potion.FLYING); - this.entity.removeEffect(Potion.MANA_GENERATION); - this.addFeed(TextColor.RED + "Statuseffekte wurden entfernt"); - } - else { - this.entity.extinguish(); - this.entity.setHealth(this.entity.getMaxHealth()); - this.entity.setManaPoints(this.entity.getMaxMana()); - this.entity.clearEffects(false); - this.entity.addEffect(new PotionEffect(Potion.HASTE, Integer.MAX_VALUE, 255, false, false)); - this.entity.addEffect(new PotionEffect(Potion.RESISTANCE, Integer.MAX_VALUE, 255, false, false)); - this.entity.addEffect(new PotionEffect(Potion.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false)); - this.entity.addEffect(new PotionEffect(Potion.FLYING, Integer.MAX_VALUE, 1, false, false)); - this.entity.addEffect(new PotionEffect(Potion.MANA_GENERATION, Integer.MAX_VALUE, 255, false, false)); - this.addFeed(TextColor.GREEN + "Statuseffekte wurden hinzugefügt"); - } + boolean god = !this.entity.hasEffect(Potion.HASTE) || this.entity.getEffect(Potion.HASTE).getAmplifier() != 255; + this.entity.setGodMode(god); + this.addFeed(god ? (TextColor.GREEN + "Statuseffekte wurden hinzugefügt") : (TextColor.RED + "Statuseffekte wurden entfernt")); } break; case NOCLIP: if(this.isAdmin()) { - if(!this.entity.noclip) - this.entity.mountEntity(null); - this.entity.noclip ^= true; - this.entity.flying &= this.entity.hasEffect(Potion.FLYING) || this.entity.noclip || this.entity.canNaturallyFly(); - this.entity.fallDistance = 0.0F; - this.sendPlayerAbilities(); + this.entity.setNoclip(!this.entity.noclip); this.addFeed((this.entity.noclip ? TextColor.GREEN : TextColor.RED) + "NoClip ist jetzt " + (this.entity.noclip ? "eingeschaltet" : "ausgeschaltet")); } break;