add god+noclip command, fix completion list bug

This commit is contained in:
Sen 2025-06-17 14:27:55 +02:00
parent f579eee88b
commit a9770ecea1
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
9 changed files with 115 additions and 32 deletions

View file

@ -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();
}
}

View file

@ -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());
}
}

View file

@ -45,7 +45,7 @@ public class PlayerEntityListParser extends PlayerEntityParser {
}
public Collection<String> getCompletions(CommandEnvironment env) {
Collection<String> comp = super.getCompletions(env);
Collection<String> comp = Lists.newArrayList(super.getCompletions(env));
comp.add("*");
return comp;
}

View file

@ -38,7 +38,7 @@ public class PlayerListParser extends PlayerParser {
}
public Collection<String> getCompletions(CommandEnvironment env) {
Collection<String> comp = super.getCompletions(env);
Collection<String> comp = Lists.newArrayList(super.getCompletions(env));
comp.add("*");
return comp;
}

View file

@ -29,7 +29,7 @@ public class PlayerParser extends CompletingParser {
}
public Collection<String> 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) {

View file

@ -30,7 +30,7 @@ public class UserParser extends CompletingParser {
}
public Collection<String> 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) {

View file

@ -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<EntityNPC> 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());
}
}

View file

@ -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<EntityNPC> 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);
}
}

View file

@ -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;