add some commands
This commit is contained in:
parent
a9770ecea1
commit
89e5775632
4 changed files with 148 additions and 0 deletions
|
@ -265,5 +265,8 @@ public class CommandEnvironment {
|
|||
this.registerExecutable(new CommandMagic());
|
||||
this.registerExecutable(new CommandGod());
|
||||
this.registerExecutable(new CommandNoclip());
|
||||
this.registerExecutable(new CommandRename());
|
||||
this.registerExecutable(new CommandRepair());
|
||||
this.registerExecutable(new CommandMore());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package server.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import server.command.Command;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.Executor;
|
||||
import server.command.UserPolicy;
|
||||
|
||||
public class CommandMore extends Command {
|
||||
public CommandMore() {
|
||||
super("more");
|
||||
|
||||
this.setParamsOptional();
|
||||
this.addFlag("all", 'a');
|
||||
this.setParamsRequired();
|
||||
this.addPlayerEntityList("players", 'p', true, UserPolicy.NON_ADMINS_OR_SELF);
|
||||
}
|
||||
|
||||
private int addItems(ItemStack stack) {
|
||||
int diff = stack.getMaxStackSize() - stack.size;
|
||||
stack.size = stack.getMaxStackSize();
|
||||
return diff;
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, boolean all, List<EntityNPC> players) {
|
||||
int done = 0;
|
||||
int added = 0;
|
||||
for(EntityNPC player : players) {
|
||||
int add = 0;
|
||||
if(all) {
|
||||
for(ItemStack item : player.inventory.mainInventory) {
|
||||
if(item != null)
|
||||
add += this.addItems(item);
|
||||
}
|
||||
for(ItemStack item : player.inventory.armorInventory) {
|
||||
if(item != null)
|
||||
add += this.addItems(item);
|
||||
}
|
||||
}
|
||||
else if(player.getHeldItem() != null) {
|
||||
add += this.addItems(player.getHeldItem());
|
||||
}
|
||||
if(add > 0) {
|
||||
exec.log("%d " + (add == 1 ? "Gegenstand" : "Gegenstände") + " wurde" + (add == 1 ? "" : "n") + " dem Inventar von %s hinzugefügt", add, player.getCommandName());
|
||||
done++;
|
||||
}
|
||||
added += add;
|
||||
}
|
||||
if(done > 1)
|
||||
exec.log("%d Gegenstände wurden dem Inventar von %d Spielern hinzugefügt", added, done);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package server.command.commands;
|
||||
|
||||
import common.item.ItemStack;
|
||||
import server.command.Command;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.Executor;
|
||||
import server.command.UserPolicy;
|
||||
|
||||
public class CommandRename extends Command {
|
||||
public CommandRename() {
|
||||
super("rename");
|
||||
|
||||
this.setParamsOptional();
|
||||
this.addString("name", false, 1, 30, null);
|
||||
this.setParamsRequired();
|
||||
this.addPlayerItem("player", 'p', true, UserPolicy.NON_ADMINS_OR_SELF);
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, String name, ItemStack stack) {
|
||||
String prev = stack.getDisplayName();
|
||||
if(name == null)
|
||||
stack.clearCustomName();
|
||||
else
|
||||
stack.setStackDisplayName(name);
|
||||
if(!prev.equals(stack.getDisplayName()))
|
||||
exec.log("Gegenstand '%s' wurde zu '%s' umbenannt", prev, stack.getDisplayName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package server.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import server.command.Command;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.Executor;
|
||||
import server.command.UserPolicy;
|
||||
|
||||
public class CommandRepair extends Command {
|
||||
public CommandRepair() {
|
||||
super("repair");
|
||||
|
||||
this.setParamsOptional();
|
||||
this.addFlag("all", 'a');
|
||||
this.setParamsRequired();
|
||||
this.addPlayerEntityList("players", 'p', true, UserPolicy.NON_ADMINS_OR_SELF);
|
||||
}
|
||||
|
||||
private boolean fixItem(ItemStack stack) {
|
||||
boolean flag = false;
|
||||
if(stack.getRepairCost() != 0) {
|
||||
stack.setRepairCost(0);
|
||||
flag = true;
|
||||
}
|
||||
if(stack.getItem().getMaxDamage() > 0 && stack.getItemDamage() != 0) {
|
||||
stack.setItemDamage(0);
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, boolean all, List<EntityNPC> players) {
|
||||
int done = 0;
|
||||
int repaired = 0;
|
||||
for(EntityNPC player : players) {
|
||||
int rep = 0;
|
||||
if(all) {
|
||||
for(ItemStack item : player.inventory.mainInventory) {
|
||||
if(item != null && this.fixItem(item))
|
||||
rep++;
|
||||
}
|
||||
for(ItemStack item : player.inventory.armorInventory) {
|
||||
if(item != null && this.fixItem(item))
|
||||
rep++;
|
||||
}
|
||||
}
|
||||
else if(player.getHeldItem() != null && this.fixItem(player.getHeldItem())) {
|
||||
rep++;
|
||||
}
|
||||
if(rep > 0) {
|
||||
exec.log("%d " + (rep == 1 ? "Gegenstand" : "Gegenstände") + " im Inventar von %s wurde" + (rep == 1 ? "" : "n") + " repariert", rep, player.getCommandName());
|
||||
done++;
|
||||
}
|
||||
repaired += rep;
|
||||
}
|
||||
if(done > 1)
|
||||
exec.log("%d Gegenstände im Inventar von %d Spielern wurden repariert", repaired, done);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue