base mod created
This commit is contained in:
@@ -0,0 +1,491 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.advancements.CriterionProgress;
|
||||
import net.minecraft.advancements.PlayerAdvancements;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class AdvancementCommand extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "advancement";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.advancement.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.advancement.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
AdvancementCommand.ActionType advancementcommand$actiontype = AdvancementCommand.ActionType.byName(args[0]);
|
||||
|
||||
if (advancementcommand$actiontype != null)
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
throw advancementcommand$actiontype.wrongUsage();
|
||||
}
|
||||
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, args[1]);
|
||||
AdvancementCommand.Mode advancementcommand$mode = AdvancementCommand.Mode.byName(args[2]);
|
||||
|
||||
if (advancementcommand$mode == null)
|
||||
{
|
||||
throw advancementcommand$actiontype.wrongUsage();
|
||||
}
|
||||
|
||||
this.perform(server, sender, args, entityplayermp, advancementcommand$actiontype, advancementcommand$mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"test".equals(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.advancement.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if (args.length == 3)
|
||||
{
|
||||
this.testAdvancement(sender, getPlayer(server, sender, args[1]), findAdvancement(server, args[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length != 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.advancement.test.usage", new Object[0]);
|
||||
}
|
||||
|
||||
this.testCriterion(sender, getPlayer(server, sender, args[1]), findAdvancement(server, args[2]), args[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void perform(MinecraftServer server, ICommandSender sender, String[] args, EntityPlayerMP player, AdvancementCommand.ActionType p_193516_5_, AdvancementCommand.Mode p_193516_6_) throws CommandException
|
||||
{
|
||||
if (p_193516_6_ == AdvancementCommand.Mode.EVERYTHING)
|
||||
{
|
||||
if (args.length == 3)
|
||||
{
|
||||
int j = p_193516_5_.perform(player, server.getAdvancementManager().getAdvancements());
|
||||
|
||||
if (j == 0)
|
||||
{
|
||||
throw p_193516_6_.fail(p_193516_5_, player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
p_193516_6_.success(sender, this, p_193516_5_, player.getName(), j);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw p_193516_6_.usage(p_193516_5_);
|
||||
}
|
||||
}
|
||||
else if (args.length < 4)
|
||||
{
|
||||
throw p_193516_6_.usage(p_193516_5_);
|
||||
}
|
||||
else
|
||||
{
|
||||
Advancement advancement = findAdvancement(server, args[3]);
|
||||
|
||||
if (p_193516_6_ == AdvancementCommand.Mode.ONLY && args.length == 5)
|
||||
{
|
||||
String s = args[4];
|
||||
|
||||
if (!advancement.getCriteria().keySet().contains(s))
|
||||
{
|
||||
throw new CommandException("commands.advancement.criterionNotFound", new Object[] {advancement.getId(), args[4]});
|
||||
}
|
||||
|
||||
if (!p_193516_5_.performCriterion(player, advancement, s))
|
||||
{
|
||||
throw new CommandException(p_193516_5_.baseTranslationKey + ".criterion.failed", new Object[] {advancement.getId(), player.getName(), s});
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, p_193516_5_.baseTranslationKey + ".criterion.success", new Object[] {advancement.getId(), player.getName(), s});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length != 4)
|
||||
{
|
||||
throw p_193516_6_.usage(p_193516_5_);
|
||||
}
|
||||
|
||||
List<Advancement> list = this.getAdvancements(advancement, p_193516_6_);
|
||||
int i = p_193516_5_.perform(player, list);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
throw p_193516_6_.fail(p_193516_5_, advancement.getId(), player.getName());
|
||||
}
|
||||
|
||||
p_193516_6_.success(sender, this, p_193516_5_, advancement.getId(), player.getName(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addChildren(Advancement p_193515_1_, List<Advancement> p_193515_2_)
|
||||
{
|
||||
for (Advancement advancement : p_193515_1_.getChildren())
|
||||
{
|
||||
p_193515_2_.add(advancement);
|
||||
this.addChildren(advancement, p_193515_2_);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Advancement> getAdvancements(Advancement p_193514_1_, AdvancementCommand.Mode p_193514_2_)
|
||||
{
|
||||
List<Advancement> list = Lists.<Advancement>newArrayList();
|
||||
|
||||
if (p_193514_2_.parents)
|
||||
{
|
||||
for (Advancement advancement = p_193514_1_.getParent(); advancement != null; advancement = advancement.getParent())
|
||||
{
|
||||
list.add(advancement);
|
||||
}
|
||||
}
|
||||
|
||||
list.add(p_193514_1_);
|
||||
|
||||
if (p_193514_2_.children)
|
||||
{
|
||||
this.addChildren(p_193514_1_, list);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void testCriterion(ICommandSender p_192554_1_, EntityPlayerMP p_192554_2_, Advancement p_192554_3_, String p_192554_4_) throws CommandException
|
||||
{
|
||||
PlayerAdvancements playeradvancements = p_192554_2_.getAdvancements();
|
||||
CriterionProgress criterionprogress = playeradvancements.getProgress(p_192554_3_).getCriterionProgress(p_192554_4_);
|
||||
|
||||
if (criterionprogress == null)
|
||||
{
|
||||
throw new CommandException("commands.advancement.criterionNotFound", new Object[] {p_192554_3_.getId(), p_192554_4_});
|
||||
}
|
||||
else if (!criterionprogress.isObtained())
|
||||
{
|
||||
throw new CommandException("commands.advancement.test.criterion.notDone", new Object[] {p_192554_2_.getName(), p_192554_3_.getId(), p_192554_4_});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(p_192554_1_, this, "commands.advancement.test.criterion.success", new Object[] {p_192554_2_.getName(), p_192554_3_.getId(), p_192554_4_});
|
||||
}
|
||||
}
|
||||
|
||||
private void testAdvancement(ICommandSender p_192552_1_, EntityPlayerMP p_192552_2_, Advancement p_192552_3_) throws CommandException
|
||||
{
|
||||
AdvancementProgress advancementprogress = p_192552_2_.getAdvancements().getProgress(p_192552_3_);
|
||||
|
||||
if (!advancementprogress.isDone())
|
||||
{
|
||||
throw new CommandException("commands.advancement.test.advancement.notDone", new Object[] {p_192552_2_.getName(), p_192552_3_.getId()});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(p_192552_1_, this, "commands.advancement.test.advancement.success", new Object[] {p_192552_2_.getName(), p_192552_3_.getId()});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"grant", "revoke", "test"});
|
||||
}
|
||||
else
|
||||
{
|
||||
AdvancementCommand.ActionType advancementcommand$actiontype = AdvancementCommand.ActionType.byName(args[0]);
|
||||
|
||||
if (advancementcommand$actiontype != null)
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
if (args.length == 3)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, AdvancementCommand.Mode.NAMES);
|
||||
}
|
||||
|
||||
AdvancementCommand.Mode advancementcommand$mode = AdvancementCommand.Mode.byName(args[2]);
|
||||
|
||||
if (advancementcommand$mode != null && advancementcommand$mode != AdvancementCommand.Mode.EVERYTHING)
|
||||
{
|
||||
if (args.length == 4)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, this.getAdvancementNames(server));
|
||||
}
|
||||
|
||||
if (args.length == 5 && advancementcommand$mode == AdvancementCommand.Mode.ONLY)
|
||||
{
|
||||
Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(args[3]));
|
||||
|
||||
if (advancement != null)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, advancement.getCriteria().keySet());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("test".equals(args[0]))
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
if (args.length == 3)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, this.getAdvancementNames(server));
|
||||
}
|
||||
|
||||
if (args.length == 4)
|
||||
{
|
||||
Advancement advancement1 = server.getAdvancementManager().getAdvancement(new ResourceLocation(args[2]));
|
||||
|
||||
if (advancement1 != null)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, advancement1.getCriteria().keySet());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private List<ResourceLocation> getAdvancementNames(MinecraftServer server)
|
||||
{
|
||||
List<ResourceLocation> list = Lists.<ResourceLocation>newArrayList();
|
||||
|
||||
for (Advancement advancement : server.getAdvancementManager().getAdvancements())
|
||||
{
|
||||
list.add(advancement.getId());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return args.length > 1 && ("grant".equals(args[0]) || "revoke".equals(args[0]) || "test".equals(args[0])) && index == 1;
|
||||
}
|
||||
|
||||
public static Advancement findAdvancement(MinecraftServer server, String id) throws CommandException
|
||||
{
|
||||
Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(id));
|
||||
|
||||
if (advancement == null)
|
||||
{
|
||||
throw new CommandException("commands.advancement.advancementNotFound", new Object[] {id});
|
||||
}
|
||||
else
|
||||
{
|
||||
return advancement;
|
||||
}
|
||||
}
|
||||
|
||||
static enum ActionType
|
||||
{
|
||||
GRANT("grant")
|
||||
{
|
||||
protected boolean perform(EntityPlayerMP p_193537_1_, Advancement p_193537_2_)
|
||||
{
|
||||
AdvancementProgress advancementprogress = p_193537_1_.getAdvancements().getProgress(p_193537_2_);
|
||||
|
||||
if (advancementprogress.isDone())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : advancementprogress.getRemaningCriteria())
|
||||
{
|
||||
p_193537_1_.getAdvancements().grantCriterion(p_193537_2_, s);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected boolean performCriterion(EntityPlayerMP p_193535_1_, Advancement p_193535_2_, String p_193535_3_)
|
||||
{
|
||||
return p_193535_1_.getAdvancements().grantCriterion(p_193535_2_, p_193535_3_);
|
||||
}
|
||||
},
|
||||
REVOKE("revoke")
|
||||
{
|
||||
protected boolean perform(EntityPlayerMP p_193537_1_, Advancement p_193537_2_)
|
||||
{
|
||||
AdvancementProgress advancementprogress = p_193537_1_.getAdvancements().getProgress(p_193537_2_);
|
||||
|
||||
if (!advancementprogress.hasProgress())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : advancementprogress.getCompletedCriteria())
|
||||
{
|
||||
p_193537_1_.getAdvancements().revokeCriterion(p_193537_2_, s);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected boolean performCriterion(EntityPlayerMP p_193535_1_, Advancement p_193535_2_, String p_193535_3_)
|
||||
{
|
||||
return p_193535_1_.getAdvancements().revokeCriterion(p_193535_2_, p_193535_3_);
|
||||
}
|
||||
};
|
||||
|
||||
final String name;
|
||||
final String baseTranslationKey;
|
||||
|
||||
private ActionType(String nameIn)
|
||||
{
|
||||
this.name = nameIn;
|
||||
this.baseTranslationKey = "commands.advancement." + nameIn;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static AdvancementCommand.ActionType byName(String nameIn)
|
||||
{
|
||||
for (AdvancementCommand.ActionType advancementcommand$actiontype : values())
|
||||
{
|
||||
if (advancementcommand$actiontype.name.equals(nameIn))
|
||||
{
|
||||
return advancementcommand$actiontype;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
CommandException wrongUsage()
|
||||
{
|
||||
return new CommandException(this.baseTranslationKey + ".usage", new Object[0]);
|
||||
}
|
||||
|
||||
public int perform(EntityPlayerMP p_193532_1_, Iterable<Advancement> p_193532_2_)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (Advancement advancement : p_193532_2_)
|
||||
{
|
||||
if (this.perform(p_193532_1_, advancement))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
protected abstract boolean perform(EntityPlayerMP p_193537_1_, Advancement p_193537_2_);
|
||||
|
||||
protected abstract boolean performCriterion(EntityPlayerMP p_193535_1_, Advancement p_193535_2_, String p_193535_3_);
|
||||
}
|
||||
|
||||
static enum Mode
|
||||
{
|
||||
ONLY("only", false, false),
|
||||
THROUGH("through", true, true),
|
||||
FROM("from", false, true),
|
||||
UNTIL("until", true, false),
|
||||
EVERYTHING("everything", true, true);
|
||||
|
||||
static final String[] NAMES = new String[values().length];
|
||||
final String name;
|
||||
final boolean parents;
|
||||
final boolean children;
|
||||
|
||||
private Mode(String p_i47556_3_, boolean p_i47556_4_, boolean p_i47556_5_)
|
||||
{
|
||||
this.name = p_i47556_3_;
|
||||
this.parents = p_i47556_4_;
|
||||
this.children = p_i47556_5_;
|
||||
}
|
||||
|
||||
CommandException fail(AdvancementCommand.ActionType p_193543_1_, Object... p_193543_2_)
|
||||
{
|
||||
return new CommandException(p_193543_1_.baseTranslationKey + "." + this.name + ".failed", p_193543_2_);
|
||||
}
|
||||
|
||||
CommandException usage(AdvancementCommand.ActionType p_193544_1_)
|
||||
{
|
||||
return new CommandException(p_193544_1_.baseTranslationKey + "." + this.name + ".usage", new Object[0]);
|
||||
}
|
||||
|
||||
void success(ICommandSender sender, AdvancementCommand p_193546_2_, AdvancementCommand.ActionType type, Object... args)
|
||||
{
|
||||
CommandBase.notifyCommandListener(sender, p_193546_2_, type.baseTranslationKey + "." + this.name + ".success", args);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static AdvancementCommand.Mode byName(String nameIn)
|
||||
{
|
||||
for (AdvancementCommand.Mode advancementcommand$mode : values())
|
||||
{
|
||||
if (advancementcommand$mode.name.equals(nameIn))
|
||||
{
|
||||
return advancementcommand$mode;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for (int i = 0; i < values().length; ++i)
|
||||
{
|
||||
NAMES[i] = values()[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,986 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.primitives.Doubles;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
public abstract class CommandBase implements ICommand
|
||||
{
|
||||
private static ICommandListener commandListener;
|
||||
private static final Splitter COMMA_SPLITTER = Splitter.on(',');
|
||||
private static final Splitter EQUAL_SPLITTER = Splitter.on('=').limit(2);
|
||||
|
||||
/**
|
||||
* Convert a JsonParseException into a user-friendly exception
|
||||
*/
|
||||
protected static SyntaxErrorException toSyntaxException(JsonParseException e)
|
||||
{
|
||||
Throwable throwable = ExceptionUtils.getRootCause(e);
|
||||
String s = "";
|
||||
|
||||
if (throwable != null)
|
||||
{
|
||||
s = throwable.getMessage();
|
||||
|
||||
if (s.contains("setLenient"))
|
||||
{
|
||||
s = s.substring(s.indexOf("to accept ") + 10);
|
||||
}
|
||||
}
|
||||
|
||||
return new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {s});
|
||||
}
|
||||
|
||||
public static NBTTagCompound entityToNBT(Entity theEntity)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = theEntity.writeToNBT(new NBTTagCompound());
|
||||
|
||||
if (theEntity instanceof EntityPlayer)
|
||||
{
|
||||
ItemStack itemstack = ((EntityPlayer)theEntity).inventory.getCurrentItem();
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
nbttagcompound.setTag("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of aliases for this command. <b>Never return null!</b>
|
||||
*/
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return sender.canUseCommand(this.getRequiredPermissionLevel(), this.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
public static int parseInt(String input) throws NumberInvalidException
|
||||
{
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(input);
|
||||
}
|
||||
catch (NumberFormatException var2)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseInt(String input, int min) throws NumberInvalidException
|
||||
{
|
||||
return parseInt(input, min, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static int parseInt(String input, int min, int max) throws NumberInvalidException
|
||||
{
|
||||
int i = parseInt(input);
|
||||
|
||||
if (i < min)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {i, min});
|
||||
}
|
||||
else if (i > max)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {i, max});
|
||||
}
|
||||
else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static long parseLong(String input) throws NumberInvalidException
|
||||
{
|
||||
try
|
||||
{
|
||||
return Long.parseLong(input);
|
||||
}
|
||||
catch (NumberFormatException var2)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
||||
}
|
||||
}
|
||||
|
||||
public static long parseLong(String input, long min, long max) throws NumberInvalidException
|
||||
{
|
||||
long i = parseLong(input);
|
||||
|
||||
if (i < min)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {i, min});
|
||||
}
|
||||
else if (i > max)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {i, max});
|
||||
}
|
||||
else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockPos parseBlockPos(ICommandSender sender, String[] args, int startIndex, boolean centerBlock) throws NumberInvalidException
|
||||
{
|
||||
BlockPos blockpos = sender.getPosition();
|
||||
return new BlockPos(parseDouble((double)blockpos.getX(), args[startIndex], -30000000, 30000000, centerBlock), parseDouble((double)blockpos.getY(), args[startIndex + 1], 0, 256, false), parseDouble((double)blockpos.getZ(), args[startIndex + 2], -30000000, 30000000, centerBlock));
|
||||
}
|
||||
|
||||
public static double parseDouble(String input) throws NumberInvalidException
|
||||
{
|
||||
try
|
||||
{
|
||||
double d0 = Double.parseDouble(input);
|
||||
|
||||
if (!Doubles.isFinite(d0))
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
||||
}
|
||||
else
|
||||
{
|
||||
return d0;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException var3)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
||||
}
|
||||
}
|
||||
|
||||
public static double parseDouble(String input, double min) throws NumberInvalidException
|
||||
{
|
||||
return parseDouble(input, min, Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static double parseDouble(String input, double min, double max) throws NumberInvalidException
|
||||
{
|
||||
double d0 = parseDouble(input);
|
||||
|
||||
if (d0 < min)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {String.format("%.2f", d0), String.format("%.2f", min)});
|
||||
}
|
||||
else if (d0 > max)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {String.format("%.2f", d0), String.format("%.2f", max)});
|
||||
}
|
||||
else
|
||||
{
|
||||
return d0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean parseBoolean(String input) throws CommandException
|
||||
{
|
||||
if (!"true".equals(input) && !"1".equals(input))
|
||||
{
|
||||
if (!"false".equals(input) && !"0".equals(input))
|
||||
{
|
||||
throw new CommandException("commands.generic.boolean.invalid", new Object[] {input});
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given ICommandSender as a EntityPlayer or throw an exception.
|
||||
*/
|
||||
public static EntityPlayerMP getCommandSenderAsPlayer(ICommandSender sender) throws PlayerNotFoundException
|
||||
{
|
||||
if (sender instanceof EntityPlayerMP)
|
||||
{
|
||||
return (EntityPlayerMP)sender;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.player.unspecified");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<EntityPlayerMP> getPlayers(MinecraftServer p_193513_0_, ICommandSender p_193513_1_, String p_193513_2_) throws CommandException
|
||||
{
|
||||
List<EntityPlayerMP> list = EntitySelector.getPlayers(p_193513_1_, p_193513_2_);
|
||||
return (List<EntityPlayerMP>)(list.isEmpty() ? Lists.newArrayList(getPlayer(p_193513_0_, (EntityPlayerMP)null, p_193513_2_)) : list);
|
||||
}
|
||||
|
||||
public static EntityPlayerMP getPlayer(MinecraftServer server, ICommandSender sender, String target) throws PlayerNotFoundException, CommandException
|
||||
{
|
||||
return getPlayer(server, EntitySelector.matchOnePlayer(sender, target), target);
|
||||
}
|
||||
|
||||
private static EntityPlayerMP getPlayer(MinecraftServer p_193512_0_, @Nullable EntityPlayerMP p_193512_1_, String p_193512_2_) throws CommandException
|
||||
{
|
||||
if (p_193512_1_ == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
p_193512_1_ = p_193512_0_.getPlayerList().getPlayerByUUID(UUID.fromString(p_193512_2_));
|
||||
}
|
||||
catch (IllegalArgumentException var4)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (p_193512_1_ == null)
|
||||
{
|
||||
p_193512_1_ = p_193512_0_.getPlayerList().getPlayerByUsername(p_193512_2_);
|
||||
}
|
||||
|
||||
if (p_193512_1_ == null)
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.player.notFound", new Object[] {p_193512_2_});
|
||||
}
|
||||
else
|
||||
{
|
||||
return p_193512_1_;
|
||||
}
|
||||
}
|
||||
|
||||
public static Entity getEntity(MinecraftServer server, ICommandSender sender, String target) throws EntityNotFoundException, CommandException
|
||||
{
|
||||
return getEntity(server, sender, target, Entity.class);
|
||||
}
|
||||
|
||||
public static <T extends Entity> T getEntity(MinecraftServer server, ICommandSender sender, String target, Class <? extends T > targetClass) throws EntityNotFoundException, CommandException
|
||||
{
|
||||
Entity entity = EntitySelector.matchOneEntity(sender, target, targetClass);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = server.getPlayerList().getPlayerByUsername(target);
|
||||
}
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(target);
|
||||
entity = server.getEntityFromUuid(uuid);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = server.getPlayerList().getPlayerByUUID(uuid);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException var6)
|
||||
{
|
||||
if (target.split("-").length == 5)
|
||||
{
|
||||
throw new EntityNotFoundException("commands.generic.entity.invalidUuid", new Object[] {target});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity != null && targetClass.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
return (T)entity;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EntityNotFoundException(target);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Entity> getEntityList(MinecraftServer server, ICommandSender sender, String target) throws EntityNotFoundException, CommandException
|
||||
{
|
||||
return (List<Entity>)(EntitySelector.isSelector(target) ? EntitySelector.matchEntities(sender, target, Entity.class) : Lists.newArrayList(getEntity(server, sender, target)));
|
||||
}
|
||||
|
||||
public static String getPlayerName(MinecraftServer server, ICommandSender sender, String target) throws PlayerNotFoundException, CommandException
|
||||
{
|
||||
try
|
||||
{
|
||||
return getPlayer(server, sender, target).getName();
|
||||
}
|
||||
catch (CommandException commandexception)
|
||||
{
|
||||
if (EntitySelector.isSelector(target))
|
||||
{
|
||||
throw commandexception;
|
||||
}
|
||||
else
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getEntityName(MinecraftServer server, ICommandSender sender, String target) throws EntityNotFoundException, CommandException
|
||||
{
|
||||
try
|
||||
{
|
||||
return getPlayer(server, sender, target).getName();
|
||||
}
|
||||
catch (PlayerNotFoundException var6)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getEntity(server, sender, target).getCachedUniqueIdString();
|
||||
}
|
||||
catch (EntityNotFoundException entitynotfoundexception)
|
||||
{
|
||||
if (EntitySelector.isSelector(target))
|
||||
{
|
||||
throw entitynotfoundexception;
|
||||
}
|
||||
else
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ITextComponent getChatComponentFromNthArg(ICommandSender sender, String[] args, int index) throws CommandException, PlayerNotFoundException
|
||||
{
|
||||
return getChatComponentFromNthArg(sender, args, index, false);
|
||||
}
|
||||
|
||||
public static ITextComponent getChatComponentFromNthArg(ICommandSender sender, String[] args, int index, boolean p_147176_3_) throws PlayerNotFoundException, CommandException
|
||||
{
|
||||
ITextComponent itextcomponent = new TextComponentString("");
|
||||
|
||||
for (int i = index; i < args.length; ++i)
|
||||
{
|
||||
if (i > index)
|
||||
{
|
||||
itextcomponent.appendText(" ");
|
||||
}
|
||||
|
||||
ITextComponent itextcomponent1 = net.minecraftforge.common.ForgeHooks.newChatWithLinks(args[i]); // Forge: links for messages
|
||||
|
||||
if (p_147176_3_)
|
||||
{
|
||||
ITextComponent itextcomponent2 = EntitySelector.matchEntitiesToTextComponent(sender, args[i]);
|
||||
|
||||
if (itextcomponent2 == null)
|
||||
{
|
||||
if (EntitySelector.isSelector(args[i]))
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.selector.notFound", new Object[] {args[i]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
itextcomponent1 = itextcomponent2;
|
||||
}
|
||||
}
|
||||
|
||||
itextcomponent.appendSibling(itextcomponent1);
|
||||
}
|
||||
|
||||
return itextcomponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a string starting at startPos
|
||||
*/
|
||||
public static String buildString(String[] args, int startPos)
|
||||
{
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
for (int i = startPos; i < args.length; ++i)
|
||||
{
|
||||
if (i > startPos)
|
||||
{
|
||||
stringbuilder.append(" ");
|
||||
}
|
||||
|
||||
String s = args[i];
|
||||
stringbuilder.append(s);
|
||||
}
|
||||
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public static CommandBase.CoordinateArg parseCoordinate(double base, String selectorArg, boolean centerBlock) throws NumberInvalidException
|
||||
{
|
||||
return parseCoordinate(base, selectorArg, -30000000, 30000000, centerBlock);
|
||||
}
|
||||
|
||||
public static CommandBase.CoordinateArg parseCoordinate(double base, String selectorArg, int min, int max, boolean centerBlock) throws NumberInvalidException
|
||||
{
|
||||
boolean flag = selectorArg.startsWith("~");
|
||||
|
||||
if (flag && Double.isNaN(base))
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {base});
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0 = 0.0D;
|
||||
|
||||
if (!flag || selectorArg.length() > 1)
|
||||
{
|
||||
boolean flag1 = selectorArg.contains(".");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
selectorArg = selectorArg.substring(1);
|
||||
}
|
||||
|
||||
d0 += parseDouble(selectorArg);
|
||||
|
||||
if (!flag1 && !flag && centerBlock)
|
||||
{
|
||||
d0 += 0.5D;
|
||||
}
|
||||
}
|
||||
|
||||
double d1 = d0 + (flag ? base : 0.0D);
|
||||
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
if (d1 < (double)min)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {String.format("%.2f", d1), min});
|
||||
}
|
||||
|
||||
if (d1 > (double)max)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {String.format("%.2f", d1), max});
|
||||
}
|
||||
}
|
||||
|
||||
return new CommandBase.CoordinateArg(d1, d0, flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static double parseDouble(double base, String input, boolean centerBlock) throws NumberInvalidException
|
||||
{
|
||||
return parseDouble(base, input, -30000000, 30000000, centerBlock);
|
||||
}
|
||||
|
||||
public static double parseDouble(double base, String input, int min, int max, boolean centerBlock) throws NumberInvalidException
|
||||
{
|
||||
boolean flag = input.startsWith("~");
|
||||
|
||||
if (flag && Double.isNaN(base))
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {base});
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0 = flag ? base : 0.0D;
|
||||
|
||||
if (!flag || input.length() > 1)
|
||||
{
|
||||
boolean flag1 = input.contains(".");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
input = input.substring(1);
|
||||
}
|
||||
|
||||
d0 += parseDouble(input);
|
||||
|
||||
if (!flag1 && !flag && centerBlock)
|
||||
{
|
||||
d0 += 0.5D;
|
||||
}
|
||||
}
|
||||
|
||||
if (min != 0 || max != 0)
|
||||
{
|
||||
if (d0 < (double)min)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {String.format("%.2f", d0), min});
|
||||
}
|
||||
|
||||
if (d0 > (double)max)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {String.format("%.2f", d0), max});
|
||||
}
|
||||
}
|
||||
|
||||
return d0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Item specified by the given text string. First checks the item registry, then tries by parsing the
|
||||
* string as an integer ID (deprecated). Warns the sender if we matched by parsing the ID. Throws if the item
|
||||
* wasn't found. Returns the item if it was found.
|
||||
*/
|
||||
public static Item getItemByText(ICommandSender sender, String id) throws NumberInvalidException
|
||||
{
|
||||
ResourceLocation resourcelocation = new ResourceLocation(id);
|
||||
Item item = Item.REGISTRY.getObject(resourcelocation);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
throw new NumberInvalidException("commands.give.item.notFound", new Object[] {resourcelocation});
|
||||
}
|
||||
else
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Block specified by the given text string. First checks the block registry, then tries by parsing the
|
||||
* string as an integer ID (deprecated). Warns the sender if we matched by parsing the ID. Throws if the block
|
||||
* wasn't found. Returns the block if it was found.
|
||||
*/
|
||||
public static Block getBlockByText(ICommandSender sender, String id) throws NumberInvalidException
|
||||
{
|
||||
ResourceLocation resourcelocation = new ResourceLocation(id);
|
||||
|
||||
if (!Block.REGISTRY.containsKey(resourcelocation))
|
||||
{
|
||||
throw new NumberInvalidException("commands.give.block.notFound", new Object[] {resourcelocation});
|
||||
}
|
||||
else
|
||||
{
|
||||
return Block.REGISTRY.getObject(resourcelocation);
|
||||
}
|
||||
}
|
||||
|
||||
public static IBlockState convertArgToBlockState(Block p_190794_0_, String p_190794_1_) throws NumberInvalidException, InvalidBlockStateException
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = Integer.parseInt(p_190794_1_);
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {i, Integer.valueOf(0)});
|
||||
}
|
||||
else if (i > 15)
|
||||
{
|
||||
throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {i, Integer.valueOf(15)});
|
||||
}
|
||||
else
|
||||
{
|
||||
return p_190794_0_.getStateFromMeta(Integer.parseInt(p_190794_1_));
|
||||
}
|
||||
}
|
||||
catch (RuntimeException var7)
|
||||
{
|
||||
try
|
||||
{
|
||||
Map < IProperty<?>, Comparable<? >> map = getBlockStatePropertyValueMap(p_190794_0_, p_190794_1_);
|
||||
IBlockState iblockstate = p_190794_0_.getDefaultState();
|
||||
|
||||
for (Entry < IProperty<?>, Comparable<? >> entry : map.entrySet())
|
||||
{
|
||||
iblockstate = getBlockState(iblockstate, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return iblockstate;
|
||||
}
|
||||
catch (RuntimeException var6)
|
||||
{
|
||||
throw new InvalidBlockStateException("commands.generic.blockstate.invalid", new Object[] {p_190794_1_, Block.REGISTRY.getNameForObject(p_190794_0_)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> IBlockState getBlockState(IBlockState p_190793_0_, IProperty<T> p_190793_1_, Comparable<?> p_190793_2_)
|
||||
{
|
||||
return p_190793_0_.withProperty(p_190793_1_, (T)p_190793_2_);
|
||||
}
|
||||
|
||||
public static Predicate<IBlockState> convertArgToBlockStatePredicate(final Block p_190791_0_, String p_190791_1_) throws InvalidBlockStateException
|
||||
{
|
||||
if (!"*".equals(p_190791_1_) && !"-1".equals(p_190791_1_))
|
||||
{
|
||||
try
|
||||
{
|
||||
final int i = Integer.parseInt(p_190791_1_);
|
||||
return new Predicate<IBlockState>()
|
||||
{
|
||||
public boolean apply(@Nullable IBlockState p_apply_1_)
|
||||
{
|
||||
return i == p_apply_1_.getBlock().getMetaFromState(p_apply_1_);
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (RuntimeException var3)
|
||||
{
|
||||
final Map < IProperty<?>, Comparable<? >> map = getBlockStatePropertyValueMap(p_190791_0_, p_190791_1_);
|
||||
return new Predicate<IBlockState>()
|
||||
{
|
||||
public boolean apply(@Nullable IBlockState p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ != null && p_190791_0_ == p_apply_1_.getBlock())
|
||||
{
|
||||
for (Entry < IProperty<?>, Comparable<? >> entry : map.entrySet())
|
||||
{
|
||||
if (!p_apply_1_.getValue(entry.getKey()).equals(entry.getValue()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Predicates.alwaysTrue();
|
||||
}
|
||||
}
|
||||
|
||||
private static Map < IProperty<?>, Comparable<? >> getBlockStatePropertyValueMap(Block p_190795_0_, String p_190795_1_) throws InvalidBlockStateException
|
||||
{
|
||||
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newHashMap();
|
||||
|
||||
if ("default".equals(p_190795_1_))
|
||||
{
|
||||
return p_190795_0_.getDefaultState().getProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockStateContainer blockstatecontainer = p_190795_0_.getBlockState();
|
||||
Iterator iterator = COMMA_SPLITTER.split(p_190795_1_).iterator();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!iterator.hasNext())
|
||||
{
|
||||
return map;
|
||||
}
|
||||
|
||||
String s = (String)iterator.next();
|
||||
Iterator<String> iterator1 = EQUAL_SPLITTER.split(s).iterator();
|
||||
|
||||
if (!iterator1.hasNext())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
IProperty<?> iproperty = blockstatecontainer.getProperty(iterator1.next());
|
||||
|
||||
if (iproperty == null || !iterator1.hasNext())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Comparable<?> comparable = getValueHelper(iproperty, iterator1.next());
|
||||
|
||||
if (comparable == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
map.put(iproperty, comparable);
|
||||
}
|
||||
|
||||
throw new InvalidBlockStateException("commands.generic.blockstate.invalid", new Object[] {p_190795_1_, Block.REGISTRY.getNameForObject(p_190795_0_)});
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends Comparable<T>> T getValueHelper(IProperty<T> p_190792_0_, String p_190792_1_)
|
||||
{
|
||||
return (T)(p_190792_0_.parseValue(p_190792_1_).orNull());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a linguistic series joining the input objects together. Examples: 1) {} --> "", 2) {"Steve"} -->
|
||||
* "Steve", 3) {"Steve", "Phil"} --> "Steve and Phil", 4) {"Steve", "Phil", "Mark"} --> "Steve, Phil and Mark"
|
||||
*/
|
||||
public static String joinNiceString(Object[] elements)
|
||||
{
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < elements.length; ++i)
|
||||
{
|
||||
String s = elements[i].toString();
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
if (i == elements.length - 1)
|
||||
{
|
||||
stringbuilder.append(" and ");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringbuilder.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
stringbuilder.append(s);
|
||||
}
|
||||
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public static ITextComponent join(List<ITextComponent> components)
|
||||
{
|
||||
ITextComponent itextcomponent = new TextComponentString("");
|
||||
|
||||
for (int i = 0; i < components.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
if (i == components.size() - 1)
|
||||
{
|
||||
itextcomponent.appendText(" and ");
|
||||
}
|
||||
else if (i > 0)
|
||||
{
|
||||
itextcomponent.appendText(", ");
|
||||
}
|
||||
}
|
||||
|
||||
itextcomponent.appendSibling(components.get(i));
|
||||
}
|
||||
|
||||
return itextcomponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a linguistic series joining together the elements of the given collection. Examples: 1) {} --> "", 2)
|
||||
* {"Steve"} --> "Steve", 3) {"Steve", "Phil"} --> "Steve and Phil", 4) {"Steve", "Phil", "Mark"} --> "Steve, Phil
|
||||
* and Mark"
|
||||
*/
|
||||
public static String joinNiceStringFromCollection(Collection<String> strings)
|
||||
{
|
||||
return joinNiceString(strings.toArray(new String[strings.size()]));
|
||||
}
|
||||
|
||||
public static List<String> getTabCompletionCoordinate(String[] inputArgs, int index, @Nullable BlockPos pos)
|
||||
{
|
||||
if (pos == null)
|
||||
{
|
||||
return Lists.newArrayList("~");
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = inputArgs.length - 1;
|
||||
String s;
|
||||
|
||||
if (i == index)
|
||||
{
|
||||
s = Integer.toString(pos.getX());
|
||||
}
|
||||
else if (i == index + 1)
|
||||
{
|
||||
s = Integer.toString(pos.getY());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != index + 2)
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
s = Integer.toString(pos.getZ());
|
||||
}
|
||||
|
||||
return Lists.newArrayList(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getTabCompletionCoordinateXZ(String[] inputArgs, int index, @Nullable BlockPos lookedPos)
|
||||
{
|
||||
if (lookedPos == null)
|
||||
{
|
||||
return Lists.newArrayList("~");
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = inputArgs.length - 1;
|
||||
String s;
|
||||
|
||||
if (i == index)
|
||||
{
|
||||
s = Integer.toString(lookedPos.getX());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != index + 1)
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
s = Integer.toString(lookedPos.getZ());
|
||||
}
|
||||
|
||||
return Lists.newArrayList(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given substring is exactly equal to the start of the given string (case insensitive).
|
||||
*/
|
||||
public static boolean doesStringStartWith(String original, String region)
|
||||
{
|
||||
return region.regionMatches(true, 0, original, 0, original.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List of strings (chosen from the given strings) which the last word in the given string array is a
|
||||
* beginning-match for. (Tab completion).
|
||||
*/
|
||||
public static List<String> getListOfStringsMatchingLastWord(String[] args, String... possibilities)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, Arrays.asList(possibilities));
|
||||
}
|
||||
|
||||
public static List<String> getListOfStringsMatchingLastWord(String[] inputArgs, Collection<?> possibleCompletions)
|
||||
{
|
||||
String s = inputArgs[inputArgs.length - 1];
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
|
||||
if (!possibleCompletions.isEmpty())
|
||||
{
|
||||
for (String s1 : Iterables.transform(possibleCompletions, Functions.toStringFunction()))
|
||||
{
|
||||
if (doesStringStartWith(s, s1))
|
||||
{
|
||||
list.add(s1);
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
for (Object object : possibleCompletions)
|
||||
{
|
||||
if (object instanceof ResourceLocation && doesStringStartWith(s, ((ResourceLocation)object).getResourcePath()))
|
||||
{
|
||||
list.add(String.valueOf(object));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void notifyCommandListener(ICommandSender sender, ICommand command, String translationKey, Object... translationArgs)
|
||||
{
|
||||
notifyCommandListener(sender, command, 0, translationKey, translationArgs);
|
||||
}
|
||||
|
||||
public static void notifyCommandListener(ICommandSender sender, ICommand command, int flags, String translationKey, Object... translationArgs)
|
||||
{
|
||||
if (commandListener != null)
|
||||
{
|
||||
commandListener.notifyListener(sender, command, flags, translationKey, translationArgs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command listener responsable for notifying server operators when asked to by commands
|
||||
*/
|
||||
public static void setCommandListener(ICommandListener listener)
|
||||
{
|
||||
commandListener = listener;
|
||||
}
|
||||
|
||||
public int compareTo(ICommand p_compareTo_1_)
|
||||
{
|
||||
return this.getName().compareTo(p_compareTo_1_.getName());
|
||||
}
|
||||
|
||||
public static class CoordinateArg
|
||||
{
|
||||
private final double result;
|
||||
private final double amount;
|
||||
private final boolean isRelative;
|
||||
|
||||
protected CoordinateArg(double resultIn, double amountIn, boolean relative)
|
||||
{
|
||||
this.result = resultIn;
|
||||
this.amount = amountIn;
|
||||
this.isRelative = relative;
|
||||
}
|
||||
|
||||
public double getResult()
|
||||
{
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public double getAmount()
|
||||
{
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public boolean isRelative()
|
||||
{
|
||||
return this.isRelative;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandBlockData extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "blockdata";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.blockdata.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (!world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = world.getBlockState(blockpos);
|
||||
TileEntity tileentity = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity == null)
|
||||
{
|
||||
throw new CommandException("commands.blockdata.notValid", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
|
||||
NBTTagCompound nbttagcompound2;
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound2 = JsonToNBT.getTagFromJson(buildString(args, 3));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
|
||||
nbttagcompound.merge(nbttagcompound2);
|
||||
nbttagcompound.setInteger("x", blockpos.getX());
|
||||
nbttagcompound.setInteger("y", blockpos.getY());
|
||||
nbttagcompound.setInteger("z", blockpos.getZ());
|
||||
|
||||
if (nbttagcompound.equals(nbttagcompound1))
|
||||
{
|
||||
throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
|
||||
}
|
||||
else
|
||||
{
|
||||
tileentity.readFromNBT(nbttagcompound);
|
||||
tileentity.markDirty();
|
||||
world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
|
||||
notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length > 0 && args.length <= 3 ? getTabCompletionCoordinate(args, 0, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandClearInventory extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "clear";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.clear.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
EntityPlayerMP entityplayermp = args.length == 0 ? getCommandSenderAsPlayer(sender) : getPlayer(server, sender, args[0]);
|
||||
Item item = args.length >= 2 ? getItemByText(sender, args[1]) : null;
|
||||
int i = args.length >= 3 ? parseInt(args[2], -1) : -1;
|
||||
int j = args.length >= 4 ? parseInt(args[3], -1) : -1;
|
||||
NBTTagCompound nbttagcompound = null;
|
||||
|
||||
if (args.length >= 5)
|
||||
{
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 4));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.clear.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 2 && item == null)
|
||||
{
|
||||
throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
int k = entityplayermp.inventory.clearMatchingItems(item, i, j, nbttagcompound);
|
||||
entityplayermp.inventoryContainer.detectAndSendChanges();
|
||||
|
||||
if (!entityplayermp.capabilities.isCreativeMode)
|
||||
{
|
||||
entityplayermp.updateHeldItem();
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, k);
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.clear.testing", new Object[] {entityplayermp.getName(), k}));
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.clear.success", new Object[] {entityplayermp.getName(), k});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, Item.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.NextTickListEntry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
|
||||
public class CommandClone extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "clone";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.clone.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 9)
|
||||
{
|
||||
throw new WrongUsageException("commands.clone.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
||||
BlockPos blockpos2 = parseBlockPos(sender, args, 6, false);
|
||||
StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1);
|
||||
StructureBoundingBox structureboundingbox1 = new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.getLength()));
|
||||
int i = structureboundingbox.getXSize() * structureboundingbox.getYSize() * structureboundingbox.getZSize();
|
||||
|
||||
if (i > 32768)
|
||||
{
|
||||
throw new CommandException("commands.clone.tooManyBlocks", new Object[] {i, Integer.valueOf(32768)});
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = false;
|
||||
Block block = null;
|
||||
Predicate<IBlockState> predicate = null;
|
||||
|
||||
if ((args.length < 11 || !"force".equals(args[10]) && !"move".equals(args[10])) && structureboundingbox.intersectsWith(structureboundingbox1))
|
||||
{
|
||||
throw new CommandException("commands.clone.noOverlap", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length >= 11 && "move".equals(args[10]))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (structureboundingbox.minY >= 0 && structureboundingbox.maxY < 256 && structureboundingbox1.minY >= 0 && structureboundingbox1.maxY < 256)
|
||||
{
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1))
|
||||
{
|
||||
boolean flag1 = false;
|
||||
|
||||
if (args.length >= 10)
|
||||
{
|
||||
if ("masked".equals(args[9]))
|
||||
{
|
||||
flag1 = true;
|
||||
}
|
||||
else if ("filtered".equals(args[9]))
|
||||
{
|
||||
if (args.length < 12)
|
||||
{
|
||||
throw new WrongUsageException("commands.clone.usage", new Object[0]);
|
||||
}
|
||||
|
||||
block = getBlockByText(sender, args[11]);
|
||||
|
||||
if (args.length >= 13)
|
||||
{
|
||||
predicate = convertArgToBlockStatePredicate(block, args[12]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<CommandClone.StaticCloneData> list = Lists.<CommandClone.StaticCloneData>newArrayList();
|
||||
List<CommandClone.StaticCloneData> list1 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
||||
List<CommandClone.StaticCloneData> list2 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
||||
Deque<BlockPos> deque = Lists.<BlockPos>newLinkedList();
|
||||
BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX, structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minZ - structureboundingbox.minZ);
|
||||
|
||||
for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j)
|
||||
{
|
||||
for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k)
|
||||
{
|
||||
for (int l = structureboundingbox.minX; l <= structureboundingbox.maxX; ++l)
|
||||
{
|
||||
BlockPos blockpos4 = new BlockPos(l, k, j);
|
||||
BlockPos blockpos5 = blockpos4.add(blockpos3);
|
||||
IBlockState iblockstate = world.getBlockState(blockpos4);
|
||||
|
||||
if ((!flag1 || iblockstate.getBlock() != Blocks.AIR) && (block == null || iblockstate.getBlock() == block && (predicate == null || predicate.apply(iblockstate))))
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(blockpos4);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
|
||||
list1.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, nbttagcompound));
|
||||
deque.addLast(blockpos4);
|
||||
}
|
||||
else if (!iblockstate.isFullBlock() && !iblockstate.isFullCube())
|
||||
{
|
||||
list2.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, (NBTTagCompound)null));
|
||||
deque.addFirst(blockpos4);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, (NBTTagCompound)null));
|
||||
deque.addLast(blockpos4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
for (BlockPos blockpos6 : deque)
|
||||
{
|
||||
TileEntity tileentity1 = world.getTileEntity(blockpos6);
|
||||
|
||||
if (tileentity1 instanceof IInventory)
|
||||
{
|
||||
((IInventory)tileentity1).clear();
|
||||
}
|
||||
|
||||
world.setBlockState(blockpos6, Blocks.BARRIER.getDefaultState(), 2);
|
||||
}
|
||||
|
||||
for (BlockPos blockpos7 : deque)
|
||||
{
|
||||
world.setBlockState(blockpos7, Blocks.AIR.getDefaultState(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
List<CommandClone.StaticCloneData> list3 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
||||
list3.addAll(list);
|
||||
list3.addAll(list1);
|
||||
list3.addAll(list2);
|
||||
List<CommandClone.StaticCloneData> list4 = Lists.<CommandClone.StaticCloneData>reverse(list3);
|
||||
|
||||
for (CommandClone.StaticCloneData commandclone$staticclonedata : list4)
|
||||
{
|
||||
TileEntity tileentity2 = world.getTileEntity(commandclone$staticclonedata.pos);
|
||||
|
||||
if (tileentity2 instanceof IInventory)
|
||||
{
|
||||
((IInventory)tileentity2).clear();
|
||||
}
|
||||
|
||||
world.setBlockState(commandclone$staticclonedata.pos, Blocks.BARRIER.getDefaultState(), 2);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
for (CommandClone.StaticCloneData commandclone$staticclonedata1 : list3)
|
||||
{
|
||||
if (world.setBlockState(commandclone$staticclonedata1.pos, commandclone$staticclonedata1.blockState, 2))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
for (CommandClone.StaticCloneData commandclone$staticclonedata2 : list1)
|
||||
{
|
||||
TileEntity tileentity3 = world.getTileEntity(commandclone$staticclonedata2.pos);
|
||||
|
||||
if (commandclone$staticclonedata2.nbt != null && tileentity3 != null)
|
||||
{
|
||||
commandclone$staticclonedata2.nbt.setInteger("x", commandclone$staticclonedata2.pos.getX());
|
||||
commandclone$staticclonedata2.nbt.setInteger("y", commandclone$staticclonedata2.pos.getY());
|
||||
commandclone$staticclonedata2.nbt.setInteger("z", commandclone$staticclonedata2.pos.getZ());
|
||||
tileentity3.readFromNBT(commandclone$staticclonedata2.nbt);
|
||||
tileentity3.markDirty();
|
||||
}
|
||||
|
||||
world.setBlockState(commandclone$staticclonedata2.pos, commandclone$staticclonedata2.blockState, 2);
|
||||
}
|
||||
|
||||
for (CommandClone.StaticCloneData commandclone$staticclonedata3 : list4)
|
||||
{
|
||||
world.notifyNeighborsRespectDebug(commandclone$staticclonedata3.pos, commandclone$staticclonedata3.blockState.getBlock(), false);
|
||||
}
|
||||
|
||||
List<NextTickListEntry> list5 = world.getPendingBlockUpdates(structureboundingbox, false);
|
||||
|
||||
if (list5 != null)
|
||||
{
|
||||
for (NextTickListEntry nextticklistentry : list5)
|
||||
{
|
||||
if (structureboundingbox.isVecInside(nextticklistentry.position))
|
||||
{
|
||||
BlockPos blockpos8 = nextticklistentry.position.add(blockpos3);
|
||||
world.scheduleBlockUpdate(blockpos8, nextticklistentry.getBlock(), (int)(nextticklistentry.scheduledTime - world.getWorldInfo().getWorldTotalTime()), nextticklistentry.priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i <= 0)
|
||||
{
|
||||
throw new CommandException("commands.clone.failed", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
|
||||
notifyCommandListener(sender, this, "commands.clone.success", new Object[] {i});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.clone.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.clone.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length > 0 && args.length <= 3)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 0, targetPos);
|
||||
}
|
||||
else if (args.length > 3 && args.length <= 6)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 3, targetPos);
|
||||
}
|
||||
else if (args.length > 6 && args.length <= 9)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 6, targetPos);
|
||||
}
|
||||
else if (args.length == 10)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"replace", "masked", "filtered"});
|
||||
}
|
||||
else if (args.length == 11)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"normal", "force", "move"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 12 && "filtered".equals(args[9]) ? getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
static class StaticCloneData
|
||||
{
|
||||
public final BlockPos pos;
|
||||
public final IBlockState blockState;
|
||||
public final NBTTagCompound nbt;
|
||||
|
||||
public StaticCloneData(BlockPos posIn, IBlockState stateIn, NBTTagCompound compoundIn)
|
||||
{
|
||||
this.pos = posIn;
|
||||
this.blockState = stateIn;
|
||||
this.nbt = compoundIn;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
|
||||
public class CommandCompare extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "testforblocks";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.compare.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 9)
|
||||
{
|
||||
throw new WrongUsageException("commands.compare.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
||||
BlockPos blockpos2 = parseBlockPos(sender, args, 6, false);
|
||||
StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1);
|
||||
StructureBoundingBox structureboundingbox1 = new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.getLength()));
|
||||
int i = structureboundingbox.getXSize() * structureboundingbox.getYSize() * structureboundingbox.getZSize();
|
||||
|
||||
if (i > 524288)
|
||||
{
|
||||
throw new CommandException("commands.compare.tooManyBlocks", new Object[] {i, 524288});
|
||||
}
|
||||
else if (structureboundingbox.minY >= 0 && structureboundingbox.maxY < 256 && structureboundingbox1.minY >= 0 && structureboundingbox1.maxY < 256)
|
||||
{
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1))
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
if (args.length > 9 && "masked".equals(args[9]))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX, structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minZ - structureboundingbox.minZ);
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();
|
||||
|
||||
for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j)
|
||||
{
|
||||
for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k)
|
||||
{
|
||||
for (int l = structureboundingbox.minX; l <= structureboundingbox.maxX; ++l)
|
||||
{
|
||||
blockpos$mutableblockpos.setPos(l, k, j);
|
||||
blockpos$mutableblockpos1.setPos(l + blockpos3.getX(), k + blockpos3.getY(), j + blockpos3.getZ());
|
||||
boolean flag1 = false;
|
||||
IBlockState iblockstate = world.getBlockState(blockpos$mutableblockpos);
|
||||
|
||||
if (!flag || iblockstate.getBlock() != Blocks.AIR)
|
||||
{
|
||||
if (iblockstate == world.getBlockState(blockpos$mutableblockpos1))
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(blockpos$mutableblockpos);
|
||||
TileEntity tileentity1 = world.getTileEntity(blockpos$mutableblockpos1);
|
||||
|
||||
if (tileentity != null && tileentity1 != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
|
||||
nbttagcompound.removeTag("x");
|
||||
nbttagcompound.removeTag("y");
|
||||
nbttagcompound.removeTag("z");
|
||||
NBTTagCompound nbttagcompound1 = tileentity1.writeToNBT(new NBTTagCompound());
|
||||
nbttagcompound1.removeTag("x");
|
||||
nbttagcompound1.removeTag("y");
|
||||
nbttagcompound1.removeTag("z");
|
||||
|
||||
if (!nbttagcompound.equals(nbttagcompound1))
|
||||
{
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
else if (tileentity != null)
|
||||
{
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flag1 = true;
|
||||
}
|
||||
|
||||
++i;
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
throw new CommandException("commands.compare.failed", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
|
||||
notifyCommandListener(sender, this, "commands.compare.success", new Object[] {i});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.compare.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.compare.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length > 0 && args.length <= 3)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 0, targetPos);
|
||||
}
|
||||
else if (args.length > 3 && args.length <= 6)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 3, targetPos);
|
||||
}
|
||||
else if (args.length > 6 && args.length <= 9)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 6, targetPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 10 ? getListOfStringsMatchingLastWord(args, new String[] {"masked", "all"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class CommandDebug extends CommandBase
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
/** The time (in milliseconds) that profiling was started */
|
||||
private long profileStartTime;
|
||||
/** The tick number that profiling was started on */
|
||||
private int profileStartTick;
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "debug";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.debug.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.debug.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("start".equals(args[0]))
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.debug.usage", new Object[0]);
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.debug.start", new Object[0]);
|
||||
server.enableProfiling();
|
||||
this.profileStartTime = MinecraftServer.getCurrentTimeMillis();
|
||||
this.profileStartTick = server.getTickCounter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"stop".equals(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.debug.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.debug.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if (!server.profiler.profilingEnabled)
|
||||
{
|
||||
throw new CommandException("commands.debug.notStarted", new Object[0]);
|
||||
}
|
||||
|
||||
long i = MinecraftServer.getCurrentTimeMillis();
|
||||
int j = server.getTickCounter();
|
||||
long k = i - this.profileStartTime;
|
||||
int l = j - this.profileStartTick;
|
||||
this.saveProfilerResults(k, l, server);
|
||||
server.profiler.profilingEnabled = false;
|
||||
notifyCommandListener(sender, this, "commands.debug.stop", new Object[] {String.format("%.2f", (float)k / 1000.0F), l});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProfilerResults(long timeSpan, int tickSpan, MinecraftServer server)
|
||||
{
|
||||
File file1 = new File(server.getFile("debug"), "profile-results-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + ".txt");
|
||||
file1.getParentFile().mkdirs();
|
||||
Writer writer = null;
|
||||
|
||||
try
|
||||
{
|
||||
writer = new OutputStreamWriter(new FileOutputStream(file1), StandardCharsets.UTF_8);
|
||||
writer.write(this.getProfilerResults(timeSpan, tickSpan, server));
|
||||
}
|
||||
catch (Throwable throwable)
|
||||
{
|
||||
LOGGER.error("Could not save profiler results to {}", file1, throwable);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private String getProfilerResults(long timeSpan, int tickSpan, MinecraftServer server)
|
||||
{
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
stringbuilder.append("---- Minecraft Profiler Results ----\n");
|
||||
stringbuilder.append("// ");
|
||||
stringbuilder.append(getWittyComment());
|
||||
stringbuilder.append("\n\n");
|
||||
stringbuilder.append("Time span: ").append(timeSpan).append(" ms\n");
|
||||
stringbuilder.append("Tick span: ").append(tickSpan).append(" ticks\n");
|
||||
stringbuilder.append("// This is approximately ").append(String.format("%.2f", (float)tickSpan / ((float)timeSpan / 1000.0F))).append(" ticks per second. It should be ").append((int)20).append(" ticks per second\n\n");
|
||||
stringbuilder.append("--- BEGIN PROFILE DUMP ---\n\n");
|
||||
this.appendProfilerResults(0, "root", stringbuilder, server);
|
||||
stringbuilder.append("--- END PROFILE DUMP ---\n\n");
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
private void appendProfilerResults(int depth, String sectionName, StringBuilder builder, MinecraftServer server)
|
||||
{
|
||||
List<Profiler.Result> list = server.profiler.getProfilingData(sectionName);
|
||||
|
||||
if (list != null && list.size() >= 3)
|
||||
{
|
||||
for (int i = 1; i < list.size(); ++i)
|
||||
{
|
||||
Profiler.Result profiler$result = list.get(i);
|
||||
builder.append(String.format("[%02d] ", depth));
|
||||
|
||||
for (int j = 0; j < depth; ++j)
|
||||
{
|
||||
builder.append("| ");
|
||||
}
|
||||
|
||||
builder.append(profiler$result.profilerName).append(" - ").append(String.format("%.2f", profiler$result.usePercentage)).append("%/").append(String.format("%.2f", profiler$result.totalUsePercentage)).append("%\n");
|
||||
|
||||
if (!"unspecified".equals(profiler$result.profilerName))
|
||||
{
|
||||
try
|
||||
{
|
||||
this.appendProfilerResults(depth + 1, sectionName + "." + profiler$result.profilerName, builder, server);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
builder.append("[[ EXCEPTION ").append((Object)exception).append(" ]]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random witty comment
|
||||
*/
|
||||
private static String getWittyComment()
|
||||
{
|
||||
String[] astring = new String[] {"Shiny numbers!", "Am I not running fast enough? :(", "I'm working as hard as I can!", "Will I ever be good enough for you? :(", "Speedy. Zoooooom!", "Hello world", "40% better than a crash report.", "Now with extra numbers", "Now with less numbers", "Now with the same numbers", "You should add flames to things, it makes them go faster!", "Do you feel the need for... optimization?", "*cracks redstone whip*", "Maybe if you treated it better then it'll have more motivation to work faster! Poor server."};
|
||||
|
||||
try
|
||||
{
|
||||
return astring[(int)(System.nanoTime() % (long)astring.length)];
|
||||
}
|
||||
catch (Throwable var2)
|
||||
{
|
||||
return "Witty comment unavailable :(";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"start", "stop"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.GameType;
|
||||
|
||||
public class CommandDefaultGameMode extends CommandGameMode
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "defaultgamemode";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.defaultgamemode.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length <= 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.defaultgamemode.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameType gametype = this.getGameModeFromCommand(sender, args[0]);
|
||||
this.setDefaultGameType(gametype, server);
|
||||
notifyCommandListener(sender, this, "commands.defaultgamemode.success", new Object[] {new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0])});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default game type for the server. Also propogate the changes to all players if the server is set to force
|
||||
* game mode
|
||||
*/
|
||||
protected void setDefaultGameType(GameType gameType, MinecraftServer server)
|
||||
{
|
||||
server.setGameType(gameType);
|
||||
|
||||
if (server.getForceGamemode())
|
||||
{
|
||||
for (EntityPlayerMP entityplayermp : server.getPlayerList().getPlayers())
|
||||
{
|
||||
entityplayermp.setGameType(gameType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.EnumDifficulty;
|
||||
|
||||
public class CommandDifficulty extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "difficulty";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.difficulty.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length <= 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.difficulty.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnumDifficulty enumdifficulty = this.getDifficultyFromCommand(args[0]);
|
||||
server.setDifficultyForAllWorlds(enumdifficulty);
|
||||
notifyCommandListener(sender, this, "commands.difficulty.success", new Object[] {new TextComponentTranslation(enumdifficulty.getDifficultyResourceKey(), new Object[0])});
|
||||
}
|
||||
}
|
||||
|
||||
protected EnumDifficulty getDifficultyFromCommand(String difficultyString) throws CommandException, NumberInvalidException
|
||||
{
|
||||
if (!"peaceful".equalsIgnoreCase(difficultyString) && !"p".equalsIgnoreCase(difficultyString))
|
||||
{
|
||||
if (!"easy".equalsIgnoreCase(difficultyString) && !"e".equalsIgnoreCase(difficultyString))
|
||||
{
|
||||
if (!"normal".equalsIgnoreCase(difficultyString) && !"n".equalsIgnoreCase(difficultyString))
|
||||
{
|
||||
return !"hard".equalsIgnoreCase(difficultyString) && !"h".equalsIgnoreCase(difficultyString) ? EnumDifficulty.getDifficultyEnum(parseInt(difficultyString, 0, 3)) : EnumDifficulty.HARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumDifficulty.NORMAL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumDifficulty.EASY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumDifficulty.PEACEFUL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"peaceful", "easy", "normal", "hard"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandEffect extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "effect";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.effect.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.effect.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityLivingBase entitylivingbase = (EntityLivingBase)getEntity(server, sender, args[0], EntityLivingBase.class);
|
||||
|
||||
if ("clear".equals(args[1]))
|
||||
{
|
||||
if (entitylivingbase.getActivePotionEffects().isEmpty())
|
||||
{
|
||||
throw new CommandException("commands.effect.failure.notActive.all", new Object[] {entitylivingbase.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entitylivingbase.clearActivePotions();
|
||||
notifyCommandListener(sender, this, "commands.effect.success.removed.all", new Object[] {entitylivingbase.getName()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Potion potion;
|
||||
|
||||
try
|
||||
{
|
||||
potion = Potion.getPotionById(parseInt(args[1], 1));
|
||||
}
|
||||
catch (NumberInvalidException var11)
|
||||
{
|
||||
potion = Potion.getPotionFromResourceLocation(args[1]);
|
||||
}
|
||||
|
||||
if (potion == null)
|
||||
{
|
||||
throw new NumberInvalidException("commands.effect.notFound", new Object[] {args[1]});
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 600;
|
||||
int j = 30;
|
||||
int k = 0;
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
j = parseInt(args[2], 0, 1000000);
|
||||
|
||||
if (potion.isInstant())
|
||||
{
|
||||
i = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = j * 20;
|
||||
}
|
||||
}
|
||||
else if (potion.isInstant())
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (args.length >= 4)
|
||||
{
|
||||
k = parseInt(args[3], 0, 255);
|
||||
}
|
||||
|
||||
boolean flag = true;
|
||||
|
||||
if (args.length >= 5 && "true".equalsIgnoreCase(args[4]))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
PotionEffect potioneffect = new PotionEffect(potion, i, k, false, flag);
|
||||
entitylivingbase.addPotionEffect(potioneffect);
|
||||
notifyCommandListener(sender, this, "commands.effect.success", new Object[] {new TextComponentTranslation(potioneffect.getEffectName(), new Object[0]), Potion.getIdFromPotion(potion), k, entitylivingbase.getName(), j});
|
||||
}
|
||||
else if (entitylivingbase.isPotionActive(potion))
|
||||
{
|
||||
entitylivingbase.removePotionEffect(potion);
|
||||
notifyCommandListener(sender, this, "commands.effect.success.removed", new Object[] {new TextComponentTranslation(potion.getName(), new Object[0]), entitylivingbase.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.effect.failure.notActive", new Object[] {new TextComponentTranslation(potion.getName(), new Object[0]), entitylivingbase.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, Potion.REGISTRY.getKeys());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 5 ? getListOfStringsMatchingLastWord(args, new String[] {"true", "false"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandEnchant extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "enchant";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.enchant.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.enchant.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityLivingBase entitylivingbase = (EntityLivingBase)getEntity(server, sender, args[0], EntityLivingBase.class);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
|
||||
Enchantment enchantment;
|
||||
|
||||
try
|
||||
{
|
||||
enchantment = Enchantment.getEnchantmentByID(parseInt(args[1], 0));
|
||||
}
|
||||
catch (NumberInvalidException var12)
|
||||
{
|
||||
enchantment = Enchantment.getEnchantmentByLocation(args[1]);
|
||||
}
|
||||
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new NumberInvalidException("commands.enchant.notFound", new Object[] {args[1]});
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 1;
|
||||
ItemStack itemstack = entitylivingbase.getHeldItemMainhand();
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
throw new CommandException("commands.enchant.noItem", new Object[0]);
|
||||
}
|
||||
else if (!enchantment.canApply(itemstack))
|
||||
{
|
||||
throw new CommandException("commands.enchant.cantEnchant", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length >= 3)
|
||||
{
|
||||
i = parseInt(args[2], enchantment.getMinLevel(), enchantment.getMaxLevel());
|
||||
}
|
||||
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
NBTTagList nbttaglist = itemstack.getEnchantmentTagList();
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
{
|
||||
int k = nbttaglist.getCompoundTagAt(j).getShort("id");
|
||||
|
||||
if (Enchantment.getEnchantmentByID(k) != null)
|
||||
{
|
||||
Enchantment enchantment1 = Enchantment.getEnchantmentByID(k);
|
||||
|
||||
if (!enchantment.isCompatibleWith(enchantment1))
|
||||
{
|
||||
throw new CommandException("commands.enchant.cantCombine", new Object[] {enchantment.getTranslatedName(i), enchantment1.getTranslatedName(nbttaglist.getCompoundTagAt(j).getShort("lvl"))});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
itemstack.addEnchantment(enchantment, i);
|
||||
notifyCommandListener(sender, this, "commands.enchant.success", new Object[0]);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, Enchantment.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CommandEntityData extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "entitydata";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.entitydata.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[0]);
|
||||
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = entityToNBT(entity);
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
|
||||
NBTTagCompound nbttagcompound2;
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound2 = JsonToNBT.getTagFromJson(buildString(args, 1));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
|
||||
UUID uuid = entity.getUniqueID();
|
||||
nbttagcompound.merge(nbttagcompound2);
|
||||
entity.setUniqueId(uuid);
|
||||
|
||||
if (nbttagcompound.equals(nbttagcompound1))
|
||||
{
|
||||
throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.readFromNBT(nbttagcompound);
|
||||
notifyCommandListener(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class CommandException extends Exception
|
||||
{
|
||||
private final Object[] errorObjects;
|
||||
|
||||
public CommandException(String message, Object... objects)
|
||||
{
|
||||
super(message);
|
||||
this.errorObjects = objects;
|
||||
}
|
||||
|
||||
public Object[] getErrorObjects()
|
||||
{
|
||||
return this.errorObjects;
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandExecuteAt extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "execute";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.execute.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.execute.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[0], Entity.class);
|
||||
double d0 = parseDouble(entity.posX, args[1], false);
|
||||
double d1 = parseDouble(entity.posY, args[2], false);
|
||||
double d2 = parseDouble(entity.posZ, args[3], false);
|
||||
new BlockPos(d0, d1, d2);
|
||||
int i = 4;
|
||||
|
||||
if ("detect".equals(args[4]) && args.length > 10)
|
||||
{
|
||||
World world = entity.getEntityWorld();
|
||||
double d3 = parseDouble(d0, args[5], false);
|
||||
double d4 = parseDouble(d1, args[6], false);
|
||||
double d5 = parseDouble(d2, args[7], false);
|
||||
Block block = getBlockByText(sender, args[8]);
|
||||
BlockPos blockpos = new BlockPos(d3, d4, d5);
|
||||
|
||||
if (!world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.execute.failed", new Object[] {"detect", entity.getName()});
|
||||
}
|
||||
|
||||
IBlockState iblockstate = world.getBlockState(blockpos);
|
||||
|
||||
if (iblockstate.getBlock() != block)
|
||||
{
|
||||
throw new CommandException("commands.execute.failed", new Object[] {"detect", entity.getName()});
|
||||
}
|
||||
|
||||
if (!CommandBase.convertArgToBlockStatePredicate(block, args[9]).apply(iblockstate))
|
||||
{
|
||||
throw new CommandException("commands.execute.failed", new Object[] {"detect", entity.getName()});
|
||||
}
|
||||
|
||||
i = 10;
|
||||
}
|
||||
|
||||
String s = buildString(args, i);
|
||||
ICommandSender icommandsender = CommandSenderWrapper.create(sender).withEntity(entity, new Vec3d(d0, d1, d2)).withSendCommandFeedback(server.worlds[0].getGameRules().getBoolean("commandBlockOutput"));
|
||||
ICommandManager icommandmanager = server.getCommandManager();
|
||||
|
||||
try
|
||||
{
|
||||
int j = icommandmanager.executeCommand(icommandsender, s);
|
||||
|
||||
if (j < 1)
|
||||
{
|
||||
throw new CommandException("commands.execute.allInvocationsFailed", new Object[] {s});
|
||||
}
|
||||
}
|
||||
catch (Throwable var23)
|
||||
{
|
||||
throw new CommandException("commands.execute.failed", new Object[] {s, entity.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else if (args.length > 1 && args.length <= 4)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 1, targetPos);
|
||||
}
|
||||
else if (args.length > 5 && args.length <= 8 && "detect".equals(args[4]))
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 5, targetPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 9 && "detect".equals(args[4]) ? getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandFill extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "fill";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.fill.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 7)
|
||||
{
|
||||
throw new WrongUsageException("commands.fill.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
||||
Block block = CommandBase.getBlockByText(sender, args[6]);
|
||||
IBlockState iblockstate;
|
||||
|
||||
if (args.length >= 8)
|
||||
{
|
||||
iblockstate = convertArgToBlockState(block, args[7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
iblockstate = block.getDefaultState();
|
||||
}
|
||||
|
||||
BlockPos blockpos2 = new BlockPos(Math.min(blockpos.getX(), blockpos1.getX()), Math.min(blockpos.getY(), blockpos1.getY()), Math.min(blockpos.getZ(), blockpos1.getZ()));
|
||||
BlockPos blockpos3 = new BlockPos(Math.max(blockpos.getX(), blockpos1.getX()), Math.max(blockpos.getY(), blockpos1.getY()), Math.max(blockpos.getZ(), blockpos1.getZ()));
|
||||
int i = (blockpos3.getX() - blockpos2.getX() + 1) * (blockpos3.getY() - blockpos2.getY() + 1) * (blockpos3.getZ() - blockpos2.getZ() + 1);
|
||||
|
||||
if (i > 32768)
|
||||
{
|
||||
throw new CommandException("commands.fill.tooManyBlocks", new Object[] {i, Integer.valueOf(32768)});
|
||||
}
|
||||
else if (blockpos2.getY() >= 0 && blockpos3.getY() < 256)
|
||||
{
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
for (int j = blockpos2.getZ(); j <= blockpos3.getZ(); j += 16)
|
||||
{
|
||||
for (int k = blockpos2.getX(); k <= blockpos3.getX(); k += 16)
|
||||
{
|
||||
if (!world.isBlockLoaded(new BlockPos(k, blockpos3.getY() - blockpos2.getY(), j)))
|
||||
{
|
||||
throw new CommandException("commands.fill.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
boolean flag = false;
|
||||
|
||||
if (args.length >= 10 && block.hasTileEntity(iblockstate))
|
||||
{
|
||||
String s = buildString(args, 9);
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(s);
|
||||
flag = true;
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.fill.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
List<BlockPos> list = Lists.<BlockPos>newArrayList();
|
||||
i = 0;
|
||||
|
||||
for (int l = blockpos2.getZ(); l <= blockpos3.getZ(); ++l)
|
||||
{
|
||||
for (int i1 = blockpos2.getY(); i1 <= blockpos3.getY(); ++i1)
|
||||
{
|
||||
for (int j1 = blockpos2.getX(); j1 <= blockpos3.getX(); ++j1)
|
||||
{
|
||||
BlockPos blockpos4 = new BlockPos(j1, i1, l);
|
||||
|
||||
if (args.length >= 9)
|
||||
{
|
||||
if (!"outline".equals(args[8]) && !"hollow".equals(args[8]))
|
||||
{
|
||||
if ("destroy".equals(args[8]))
|
||||
{
|
||||
world.destroyBlock(blockpos4, true);
|
||||
}
|
||||
else if ("keep".equals(args[8]))
|
||||
{
|
||||
if (!world.isAirBlock(blockpos4))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if ("replace".equals(args[8]) && !block.hasTileEntity(iblockstate) && args.length > 9)
|
||||
{
|
||||
Block block1 = CommandBase.getBlockByText(sender, args[9]);
|
||||
|
||||
if (world.getBlockState(blockpos4).getBlock() != block1 || args.length > 10 && !"-1".equals(args[10]) && !"*".equals(args[10]) && !CommandBase.convertArgToBlockStatePredicate(block1, args[10]).apply(world.getBlockState(blockpos4)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (j1 != blockpos2.getX() && j1 != blockpos3.getX() && i1 != blockpos2.getY() && i1 != blockpos3.getY() && l != blockpos2.getZ() && l != blockpos3.getZ())
|
||||
{
|
||||
if ("hollow".equals(args[8]))
|
||||
{
|
||||
world.setBlockState(blockpos4, Blocks.AIR.getDefaultState(), 2);
|
||||
list.add(blockpos4);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity tileentity1 = world.getTileEntity(blockpos4);
|
||||
|
||||
if (tileentity1 != null && tileentity1 instanceof IInventory)
|
||||
{
|
||||
((IInventory)tileentity1).clear();
|
||||
}
|
||||
|
||||
if (world.setBlockState(blockpos4, iblockstate, 2))
|
||||
{
|
||||
list.add(blockpos4);
|
||||
++i;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(blockpos4);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
nbttagcompound.setInteger("x", blockpos4.getX());
|
||||
nbttagcompound.setInteger("y", blockpos4.getY());
|
||||
nbttagcompound.setInteger("z", blockpos4.getZ());
|
||||
tileentity.readFromNBT(nbttagcompound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockPos blockpos5 : list)
|
||||
{
|
||||
Block block2 = world.getBlockState(blockpos5).getBlock();
|
||||
world.notifyNeighborsRespectDebug(blockpos5, block2, false);
|
||||
}
|
||||
|
||||
if (i <= 0)
|
||||
{
|
||||
throw new CommandException("commands.fill.failed", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
|
||||
notifyCommandListener(sender, this, "commands.fill.success", new Object[] {i});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.fill.outOfWorld", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length > 0 && args.length <= 3)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 0, targetPos);
|
||||
}
|
||||
else if (args.length > 3 && args.length <= 6)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 3, targetPos);
|
||||
}
|
||||
else if (args.length == 7)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys());
|
||||
}
|
||||
else if (args.length == 9)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"replace", "destroy", "keep", "hollow", "outline"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 10 && "replace".equals(args[8]) ? getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandFunction extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "function";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.function.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length != 1 && args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.function.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceLocation resourcelocation = new ResourceLocation(args[0]);
|
||||
FunctionObject functionobject = server.getFunctionManager().getFunction(resourcelocation);
|
||||
|
||||
if (functionobject == null)
|
||||
{
|
||||
throw new CommandException("commands.function.unknown", new Object[] {resourcelocation});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length == 3)
|
||||
{
|
||||
String s = args[1];
|
||||
boolean flag;
|
||||
|
||||
if ("if".equals(s))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"unless".equals(s))
|
||||
{
|
||||
throw new WrongUsageException("commands.function.usage", new Object[0]);
|
||||
}
|
||||
|
||||
flag = false;
|
||||
}
|
||||
|
||||
boolean flag1 = false;
|
||||
|
||||
try
|
||||
{
|
||||
flag1 = !getEntityList(server, sender, args[2]).isEmpty();
|
||||
}
|
||||
catch (EntityNotFoundException var10)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (flag != flag1)
|
||||
{
|
||||
throw new CommandException("commands.function.skipped", new Object[] {resourcelocation});
|
||||
}
|
||||
}
|
||||
|
||||
int i = server.getFunctionManager().execute(functionobject, CommandSenderWrapper.create(sender).computePositionVector().withPermissionLevel(2).withSendCommandFeedback(false));
|
||||
notifyCommandListener(sender, this, "commands.function.success", new Object[] {resourcelocation, i});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getFunctionManager().getFunctions().keySet());
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"if", "unless"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 3 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
|
||||
public class CommandGameMode extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "gamemode";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.gamemode.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length <= 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameType gametype = this.getGameModeFromCommand(sender, args[0]);
|
||||
EntityPlayer entityplayer = args.length >= 2 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);
|
||||
entityplayer.setGameType(gametype);
|
||||
ITextComponent itextcomponent = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
|
||||
|
||||
if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback"))
|
||||
{
|
||||
entityplayer.sendMessage(new TextComponentTranslation("gameMode.changed", new Object[] {itextcomponent}));
|
||||
}
|
||||
|
||||
if (entityplayer == sender)
|
||||
{
|
||||
notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", new Object[] {itextcomponent});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", new Object[] {entityplayer.getName(), itextcomponent});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Game Mode specified in the command.
|
||||
*/
|
||||
protected GameType getGameModeFromCommand(ICommandSender sender, String gameModeString) throws CommandException, NumberInvalidException
|
||||
{
|
||||
GameType gametype = GameType.parseGameTypeWithDefault(gameModeString, GameType.NOT_SET);
|
||||
return gametype == GameType.NOT_SET ? WorldSettings.getGameTypeById(parseInt(gameModeString, 0, GameType.values().length - 2)) : gametype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"survival", "creative", "adventure", "spectator"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketEntityStatus;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.GameRules;
|
||||
|
||||
public class CommandGameRule extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "gamerule";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.gamerule.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
GameRules gamerules = this.getOverWorldGameRules(server);
|
||||
String s = args.length > 0 ? args[0] : "";
|
||||
String s1 = args.length > 1 ? buildString(args, 1) : "";
|
||||
|
||||
switch (args.length)
|
||||
{
|
||||
case 0:
|
||||
sender.sendMessage(new TextComponentString(joinNiceString(gamerules.getRules())));
|
||||
break;
|
||||
case 1:
|
||||
|
||||
if (!gamerules.hasRule(s))
|
||||
{
|
||||
throw new CommandException("commands.gamerule.norule", new Object[] {s});
|
||||
}
|
||||
|
||||
String s2 = gamerules.getString(s);
|
||||
sender.sendMessage((new TextComponentString(s)).appendText(" = ").appendText(s2));
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, gamerules.getInt(s));
|
||||
break;
|
||||
default:
|
||||
|
||||
if (gamerules.areSameType(s, GameRules.ValueType.BOOLEAN_VALUE) && !"true".equals(s1) && !"false".equals(s1))
|
||||
{
|
||||
throw new CommandException("commands.generic.boolean.invalid", new Object[] {s1});
|
||||
}
|
||||
|
||||
gamerules.setOrCreateGameRule(s, s1);
|
||||
notifyGameRuleChange(gamerules, s, server);
|
||||
notifyCommandListener(sender, this, "commands.gamerule.success", new Object[] {s, s1});
|
||||
}
|
||||
}
|
||||
|
||||
public static void notifyGameRuleChange(GameRules rules, String p_184898_1_, MinecraftServer server)
|
||||
{
|
||||
if ("reducedDebugInfo".equals(p_184898_1_))
|
||||
{
|
||||
byte b0 = (byte)(rules.getBoolean(p_184898_1_) ? 22 : 23);
|
||||
|
||||
for (EntityPlayerMP entityplayermp : server.getPlayerList().getPlayers())
|
||||
{
|
||||
entityplayermp.connection.sendPacket(new SPacketEntityStatus(entityplayermp, b0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, this.getOverWorldGameRules(server).getRules());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
GameRules gamerules = this.getOverWorldGameRules(server);
|
||||
|
||||
if (gamerules.areSameType(args[0], GameRules.ValueType.BOOLEAN_VALUE))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"true", "false"});
|
||||
}
|
||||
|
||||
if (gamerules.areSameType(args[0], GameRules.ValueType.FUNCTION))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getFunctionManager().getFunctions().keySet());
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the game rules for the overworld
|
||||
*/
|
||||
private GameRules getOverWorldGameRules(MinecraftServer server)
|
||||
{
|
||||
return server.getWorld(0).getGameRules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandGive extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "give";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.give.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.give.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
|
||||
Item item = getItemByText(sender, args[1]);
|
||||
int i = args.length >= 3 ? parseInt(args[2], 1, item.getItemStackLimit()) : 1;
|
||||
int j = args.length >= 4 ? parseInt(args[3]) : 0;
|
||||
ItemStack itemstack = new ItemStack(item, i, j);
|
||||
|
||||
if (args.length >= 5)
|
||||
{
|
||||
String s = buildString(args, 4);
|
||||
|
||||
try
|
||||
{
|
||||
itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
entityplayer.world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
entityplayer.inventoryContainer.detectAndSendChanges();
|
||||
}
|
||||
|
||||
if (flag && itemstack.isEmpty())
|
||||
{
|
||||
itemstack.setCount(1);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
|
||||
EntityItem entityitem1 = entityplayer.dropItem(itemstack, false);
|
||||
|
||||
if (entityitem1 != null)
|
||||
{
|
||||
entityitem1.makeFakeItem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.getCount());
|
||||
EntityItem entityitem = entityplayer.dropItem(itemstack, false);
|
||||
|
||||
if (entityitem != null)
|
||||
{
|
||||
entityitem.setNoPickupDelay();
|
||||
entityitem.setOwner(entityplayer.getName());
|
||||
}
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.give.success", new Object[] {itemstack.getTextComponent(), i, entityplayer.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, Item.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public abstract class CommandHandler implements ICommandManager
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
/** Map of Strings to the ICommand objects they represent */
|
||||
private final Map<String, ICommand> commandMap = Maps.<String, ICommand>newHashMap();
|
||||
/** The set of ICommand objects currently loaded. */
|
||||
private final Set<ICommand> commandSet = Sets.<ICommand>newHashSet();
|
||||
|
||||
/**
|
||||
* Attempt to execute a command. This method should return the number of times that the command was executed. If the
|
||||
* command does not exist or if the player does not have permission, 0 will be returned. A number greater than 1 can
|
||||
* be returned if a player selector is used.
|
||||
*/
|
||||
public int executeCommand(ICommandSender sender, String rawCommand)
|
||||
{
|
||||
rawCommand = rawCommand.trim();
|
||||
|
||||
if (rawCommand.startsWith("/"))
|
||||
{
|
||||
rawCommand = rawCommand.substring(1);
|
||||
}
|
||||
|
||||
String[] astring = rawCommand.split(" ");
|
||||
String s = astring[0];
|
||||
astring = dropFirstString(astring);
|
||||
ICommand icommand = this.commandMap.get(s);
|
||||
int i = 0;
|
||||
|
||||
try
|
||||
{
|
||||
int j = this.getUsernameIndex(icommand, astring);
|
||||
|
||||
if (icommand == null)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation("commands.generic.notFound", new Object[0]);
|
||||
textcomponenttranslation1.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation1);
|
||||
}
|
||||
else if (icommand.checkPermission(this.getServer(), sender))
|
||||
{
|
||||
net.minecraftforge.event.CommandEvent event = new net.minecraftforge.event.CommandEvent(icommand, sender, astring);
|
||||
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
if (event.getException() != null)
|
||||
{
|
||||
com.google.common.base.Throwables.throwIfUnchecked(event.getException());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (event.getParameters() != null) astring = event.getParameters();
|
||||
|
||||
if (j > -1)
|
||||
{
|
||||
List<Entity> list = EntitySelector.<Entity>matchEntities(sender, astring[j], Entity.class);
|
||||
String s1 = astring[j];
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, list.size());
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.selector.notFound", new Object[] {astring[j]});
|
||||
}
|
||||
|
||||
for (Entity entity : list)
|
||||
{
|
||||
astring[j] = entity.getCachedUniqueIdString();
|
||||
|
||||
if (this.tryExecute(sender, astring, icommand, rawCommand))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
astring[j] = s1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, 1);
|
||||
|
||||
if (this.tryExecute(sender, astring, icommand, rawCommand))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation2 = new TextComponentTranslation("commands.generic.permission", new Object[0]);
|
||||
textcomponenttranslation2.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation2);
|
||||
}
|
||||
}
|
||||
catch (CommandException commandexception)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(commandexception.getMessage(), commandexception.getErrorObjects());
|
||||
textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation);
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.SUCCESS_COUNT, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
protected boolean tryExecute(ICommandSender sender, String[] args, ICommand command, String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
command.execute(this.getServer(), sender, args);
|
||||
return true;
|
||||
}
|
||||
catch (WrongUsageException wrongusageexception)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation2 = new TextComponentTranslation("commands.generic.usage", new Object[] {new TextComponentTranslation(wrongusageexception.getMessage(), wrongusageexception.getErrorObjects())});
|
||||
textcomponenttranslation2.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation2);
|
||||
}
|
||||
catch (CommandException commandexception)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation(commandexception.getMessage(), commandexception.getErrorObjects());
|
||||
textcomponenttranslation1.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation1);
|
||||
}
|
||||
catch (Throwable throwable)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.generic.exception", new Object[0]);
|
||||
textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(textcomponenttranslation);
|
||||
LOGGER.warn("Couldn't process command: " + input, throwable);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract MinecraftServer getServer();
|
||||
|
||||
/**
|
||||
* adds the command and any aliases it has to the internal map of available commands
|
||||
*/
|
||||
public ICommand registerCommand(ICommand command)
|
||||
{
|
||||
this.commandMap.put(command.getName(), command);
|
||||
this.commandSet.add(command);
|
||||
|
||||
for (String s : command.getAliases())
|
||||
{
|
||||
ICommand icommand = this.commandMap.get(s);
|
||||
|
||||
if (icommand == null || !icommand.getName().equals(s))
|
||||
{
|
||||
this.commandMap.put(s, command);
|
||||
}
|
||||
}
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new array and sets elements 0..n-2 to be 0..n-1 of the input (n elements)
|
||||
*/
|
||||
private static String[] dropFirstString(String[] input)
|
||||
{
|
||||
String[] astring = new String[input.length - 1];
|
||||
System.arraycopy(input, 1, astring, 0, input.length - 1);
|
||||
return astring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of possible completion options for when the TAB key is pressed. This can be a list of commands if no
|
||||
* command is specified or a partial command is specified. It could also be a list of arguments for the command that
|
||||
* is specified.
|
||||
*/
|
||||
public List<String> getTabCompletions(ICommandSender sender, String input, @Nullable BlockPos pos)
|
||||
{
|
||||
String[] astring = input.split(" ", -1);
|
||||
String s = astring[0];
|
||||
|
||||
if (astring.length == 1)
|
||||
{
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
|
||||
for (Entry<String, ICommand> entry : this.commandMap.entrySet())
|
||||
{
|
||||
if (CommandBase.doesStringStartWith(s, entry.getKey()) && ((ICommand)entry.getValue()).checkPermission(this.getServer(), sender))
|
||||
{
|
||||
list.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (astring.length > 1)
|
||||
{
|
||||
ICommand icommand = this.commandMap.get(s);
|
||||
|
||||
if (icommand != null && icommand.checkPermission(this.getServer(), sender))
|
||||
{
|
||||
return icommand.getTabCompletions(this.getServer(), sender, dropFirstString(astring), pos);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of commands that the given command sender has access to execute.
|
||||
*/
|
||||
public List<ICommand> getPossibleCommands(ICommandSender sender)
|
||||
{
|
||||
List<ICommand> list = Lists.<ICommand>newArrayList();
|
||||
|
||||
for (ICommand icommand : this.commandSet)
|
||||
{
|
||||
if (icommand.checkPermission(this.getServer(), sender))
|
||||
{
|
||||
list.add(icommand);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Map of all the name to command pairs stored in this command manager.
|
||||
*/
|
||||
public Map<String, ICommand> getCommands()
|
||||
{
|
||||
return this.commandMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a command's first parameter index containing a valid username.
|
||||
*/
|
||||
private int getUsernameIndex(ICommand command, String[] args) throws CommandException
|
||||
{
|
||||
if (command == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < args.length; ++i)
|
||||
{
|
||||
if (command.isUsernameIndex(args, i) && EntitySelector.matchesMultiplePlayers(args[i]))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.CommandBlockBaseLogic;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
|
||||
public class CommandHelp extends CommandBase
|
||||
{
|
||||
private static final String[] SEARGE_SAYS = new String[] {"Yolo", "Ask for help on twitter", "/deop @p", "Scoreboard deleted, commands blocked", "Contact helpdesk for help", "/testfornoob @p", "/trigger warning", "Oh my god, it's full of stats", "/kill @p[name=!Searge]", "Have you tried turning it off and on again?", "Sorry, no help today"};
|
||||
private final Random rand = new Random();
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "help";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.help.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of aliases for this command. <b>Never return null!</b>
|
||||
*/
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Arrays.<String>asList("?");
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (sender instanceof CommandBlockBaseLogic)
|
||||
{
|
||||
sender.sendMessage((new TextComponentString("Searge says: ")).appendText(SEARGE_SAYS[this.rand.nextInt(SEARGE_SAYS.length) % SEARGE_SAYS.length]));
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ICommand> list = this.getSortedPossibleCommands(sender, server);
|
||||
int i = 7;
|
||||
int j = (list.size() - 1) / 7;
|
||||
int k = 0;
|
||||
|
||||
try
|
||||
{
|
||||
k = args.length == 0 ? 0 : parseInt(args[0], 1, j + 1) - 1;
|
||||
}
|
||||
catch (NumberInvalidException numberinvalidexception)
|
||||
{
|
||||
Map<String, ICommand> map = this.getCommandMap(server);
|
||||
ICommand icommand = map.get(args[0]);
|
||||
|
||||
if (icommand != null)
|
||||
{
|
||||
throw new WrongUsageException(icommand.getUsage(sender), new Object[0]);
|
||||
}
|
||||
|
||||
if (MathHelper.getInt(args[0], -1) == -1 && MathHelper.getInt(args[0], -2) == -2)
|
||||
{
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
throw numberinvalidexception;
|
||||
}
|
||||
|
||||
int l = Math.min((k + 1) * 7, list.size());
|
||||
TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation("commands.help.header", new Object[] {k + 1, j + 1});
|
||||
textcomponenttranslation1.getStyle().setColor(TextFormatting.DARK_GREEN);
|
||||
sender.sendMessage(textcomponenttranslation1);
|
||||
|
||||
for (int i1 = k * 7; i1 < l; ++i1)
|
||||
{
|
||||
ICommand icommand1 = list.get(i1);
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(icommand1.getUsage(sender), new Object[0]);
|
||||
textcomponenttranslation.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + icommand1.getName() + " "));
|
||||
sender.sendMessage(textcomponenttranslation);
|
||||
}
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation2 = new TextComponentTranslation("commands.help.footer", new Object[0]);
|
||||
textcomponenttranslation2.getStyle().setColor(TextFormatting.GREEN);
|
||||
sender.sendMessage(textcomponenttranslation2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ICommand> getSortedPossibleCommands(ICommandSender sender, MinecraftServer server)
|
||||
{
|
||||
List<ICommand> list = server.getCommandManager().getPossibleCommands(sender);
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
protected Map<String, ICommand> getCommandMap(MinecraftServer server)
|
||||
{
|
||||
return server.getCommandManager().getCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
Set<String> set = this.getCommandMap(server).keySet();
|
||||
return getListOfStringsMatchingLastWord(args, (String[])set.toArray(new String[set.size()]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandKill extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "kill";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.kill.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
EntityPlayer entityplayer = getCommandSenderAsPlayer(sender);
|
||||
entityplayer.onKillCommand();
|
||||
notifyCommandListener(sender, this, "commands.kill.successful", new Object[] {entityplayer.getDisplayName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[0]);
|
||||
entity.onKillCommand();
|
||||
notifyCommandListener(sender, this, "commands.kill.successful", new Object[] {entity.getDisplayName()});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandLocate extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "locate";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.locate.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.locate.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = args[0];
|
||||
BlockPos blockpos = sender.getEntityWorld().findNearestStructure(s, sender.getPosition(), false);
|
||||
|
||||
if (blockpos != null)
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.locate.success", new Object[] {s, blockpos.getX(), blockpos.getZ()}));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.locate.failure", new Object[] {s});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"Stronghold", "Monument", "Village", "Mansion", "EndCity", "Fortress", "Temple", "Mineshaft"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class CommandNotFoundException extends CommandException
|
||||
{
|
||||
public CommandNotFoundException()
|
||||
{
|
||||
this("commands.generic.notFound");
|
||||
}
|
||||
|
||||
public CommandNotFoundException(String message, Object... args)
|
||||
{
|
||||
super(message, args);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class CommandParticle extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "particle";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.particle.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 8)
|
||||
{
|
||||
throw new WrongUsageException("commands.particle.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = false;
|
||||
EnumParticleTypes enumparticletypes = EnumParticleTypes.getByName(args[0]);
|
||||
|
||||
if (enumparticletypes == null)
|
||||
{
|
||||
throw new CommandException("commands.particle.notFound", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = args[0];
|
||||
Vec3d vec3d = sender.getPositionVector();
|
||||
double d0 = (double)((float)parseDouble(vec3d.x, args[1], true));
|
||||
double d1 = (double)((float)parseDouble(vec3d.y, args[2], true));
|
||||
double d2 = (double)((float)parseDouble(vec3d.z, args[3], true));
|
||||
double d3 = (double)((float)parseDouble(args[4]));
|
||||
double d4 = (double)((float)parseDouble(args[5]));
|
||||
double d5 = (double)((float)parseDouble(args[6]));
|
||||
double d6 = (double)((float)parseDouble(args[7]));
|
||||
int i = 0;
|
||||
|
||||
if (args.length > 8)
|
||||
{
|
||||
i = parseInt(args[8], 0);
|
||||
}
|
||||
|
||||
boolean flag1 = false;
|
||||
|
||||
if (args.length > 9 && "force".equals(args[9]))
|
||||
{
|
||||
flag1 = true;
|
||||
}
|
||||
|
||||
EntityPlayerMP entityplayermp;
|
||||
|
||||
if (args.length > 10)
|
||||
{
|
||||
entityplayermp = getPlayer(server, sender, args[10]);
|
||||
}
|
||||
else
|
||||
{
|
||||
entityplayermp = null;
|
||||
}
|
||||
|
||||
int[] aint = new int[enumparticletypes.getArgumentCount()];
|
||||
|
||||
for (int j = 0; j < aint.length; ++j)
|
||||
{
|
||||
if (args.length > 11 + j)
|
||||
{
|
||||
try
|
||||
{
|
||||
aint[j] = Integer.parseInt(args[11 + j]);
|
||||
}
|
||||
catch (NumberFormatException var28)
|
||||
{
|
||||
throw new CommandException("commands.particle.invalidParam", new Object[] {args[11 + j]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (world instanceof WorldServer)
|
||||
{
|
||||
WorldServer worldserver = (WorldServer)world;
|
||||
|
||||
if (entityplayermp == null)
|
||||
{
|
||||
worldserver.spawnParticle(enumparticletypes, flag1, d0, d1, d2, i, d3, d4, d5, d6, aint);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldserver.spawnParticle(entityplayermp, enumparticletypes, flag1, d0, d1, d2, i, d3, d4, d5, d6, aint);
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.particle.success", new Object[] {s, Math.max(i, 1)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, EnumParticleTypes.getParticleNames());
|
||||
}
|
||||
else if (args.length > 1 && args.length <= 4)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 1, targetPos);
|
||||
}
|
||||
else if (args.length == 10)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"normal", "force"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 11 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketCustomSound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class CommandPlaySound extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "playsound";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.playsound.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException(this.getUsage(sender), new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
String s = args[i++];
|
||||
String s1 = args[i++];
|
||||
SoundCategory soundcategory = SoundCategory.getByName(s1);
|
||||
|
||||
if (soundcategory == null)
|
||||
{
|
||||
throw new CommandException("commands.playsound.unknownSoundSource", new Object[] {s1});
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, args[i++]);
|
||||
Vec3d vec3d = sender.getPositionVector();
|
||||
double d0 = args.length > i ? parseDouble(vec3d.x, args[i++], true) : vec3d.x;
|
||||
double d1 = args.length > i ? parseDouble(vec3d.y, args[i++], 0, 0, false) : vec3d.y;
|
||||
double d2 = args.length > i ? parseDouble(vec3d.z, args[i++], true) : vec3d.z;
|
||||
double d3 = args.length > i ? parseDouble(args[i++], 0.0D, 3.4028234663852886E38D) : 1.0D;
|
||||
double d4 = args.length > i ? parseDouble(args[i++], 0.0D, 2.0D) : 1.0D;
|
||||
double d5 = args.length > i ? parseDouble(args[i], 0.0D, 1.0D) : 0.0D;
|
||||
double d6 = d3 > 1.0D ? d3 * 16.0D : 16.0D;
|
||||
double d7 = entityplayermp.getDistance(d0, d1, d2);
|
||||
|
||||
if (d7 > d6)
|
||||
{
|
||||
if (d5 <= 0.0D)
|
||||
{
|
||||
throw new CommandException("commands.playsound.playerTooFar", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
|
||||
double d8 = d0 - entityplayermp.posX;
|
||||
double d9 = d1 - entityplayermp.posY;
|
||||
double d10 = d2 - entityplayermp.posZ;
|
||||
double d11 = Math.sqrt(d8 * d8 + d9 * d9 + d10 * d10);
|
||||
|
||||
if (d11 > 0.0D)
|
||||
{
|
||||
d0 = entityplayermp.posX + d8 / d11 * 2.0D;
|
||||
d1 = entityplayermp.posY + d9 / d11 * 2.0D;
|
||||
d2 = entityplayermp.posZ + d10 / d11 * 2.0D;
|
||||
}
|
||||
|
||||
d3 = d5;
|
||||
}
|
||||
|
||||
entityplayermp.connection.sendPacket(new SPacketCustomSound(s, soundcategory, d0, d1, d2, (float)d3, (float)d4));
|
||||
notifyCommandListener(sender, this, "commands.playsound.success", new Object[] {s, entityplayermp.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, SoundEvent.REGISTRY.getKeys());
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, SoundCategory.getSoundCategoryNames());
|
||||
}
|
||||
else if (args.length == 3)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length > 3 && args.length <= 6 ? getTabCompletionCoordinate(args, 3, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CommandReload extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "reload";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.reload.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.reload.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
server.reload();
|
||||
notifyCommandListener(sender, this, "commands.reload.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandReplaceItem extends CommandBase
|
||||
{
|
||||
private static final Map<String, Integer> SHORTCUTS = Maps.<String, Integer>newHashMap();
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "replaceitem";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.replaceitem.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.replaceitem.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag;
|
||||
|
||||
if ("entity".equals(args[0]))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"block".equals(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.replaceitem.usage", new Object[0]);
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if (args.length < 6)
|
||||
{
|
||||
throw new WrongUsageException("commands.replaceitem.block.usage", new Object[0]);
|
||||
}
|
||||
|
||||
i = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.replaceitem.entity.usage", new Object[0]);
|
||||
}
|
||||
|
||||
i = 2;
|
||||
}
|
||||
|
||||
String s = args[i];
|
||||
int j = this.getSlotForShortcut(args[i++]);
|
||||
Item item;
|
||||
|
||||
try
|
||||
{
|
||||
item = getItemByText(sender, args[i]);
|
||||
}
|
||||
catch (NumberInvalidException numberinvalidexception)
|
||||
{
|
||||
if (Block.getBlockFromName(args[i]) != Blocks.AIR)
|
||||
{
|
||||
throw numberinvalidexception;
|
||||
}
|
||||
|
||||
item = null;
|
||||
}
|
||||
|
||||
++i;
|
||||
int k = args.length > i ? parseInt(args[i++], 1, item.getItemStackLimit()) : 1;
|
||||
int l = args.length > i ? parseInt(args[i++]) : 0;
|
||||
ItemStack itemstack = new ItemStack(item, k, l);
|
||||
|
||||
if (args.length > i)
|
||||
{
|
||||
String s1 = buildString(args, i);
|
||||
|
||||
try
|
||||
{
|
||||
itemstack.setTagCompound(JsonToNBT.getTagFromJson(s1));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.replaceitem.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 1, false);
|
||||
World world = sender.getEntityWorld();
|
||||
TileEntity tileentity = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity == null || !(tileentity instanceof IInventory))
|
||||
{
|
||||
throw new CommandException("commands.replaceitem.noContainer", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
|
||||
IInventory iinventory = (IInventory)tileentity;
|
||||
|
||||
if (j >= 0 && j < iinventory.getSizeInventory())
|
||||
{
|
||||
iinventory.setInventorySlotContents(j, itemstack);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[1]);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
|
||||
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
((EntityPlayer)entity).inventoryContainer.detectAndSendChanges();
|
||||
}
|
||||
|
||||
if (!entity.replaceItemInInventory(j, itemstack))
|
||||
{
|
||||
throw new CommandException("commands.replaceitem.failed", new Object[] {s, k, itemstack.isEmpty() ? "Air" : itemstack.getTextComponent()});
|
||||
}
|
||||
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
((EntityPlayer)entity).inventoryContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, k);
|
||||
notifyCommandListener(sender, this, "commands.replaceitem.success", new Object[] {s, k, itemstack.isEmpty() ? "Air" : itemstack.getTextComponent()});
|
||||
}
|
||||
}
|
||||
|
||||
private int getSlotForShortcut(String shortcut) throws CommandException
|
||||
{
|
||||
if (!SHORTCUTS.containsKey(shortcut))
|
||||
{
|
||||
throw new CommandException("commands.generic.parameter.invalid", new Object[] {shortcut});
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((Integer)SHORTCUTS.get(shortcut)).intValue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"entity", "block"});
|
||||
}
|
||||
else if (args.length == 2 && "entity".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else if (args.length >= 2 && args.length <= 4 && "block".equals(args[0]))
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 1, targetPos);
|
||||
}
|
||||
else if ((args.length != 3 || !"entity".equals(args[0])) && (args.length != 5 || !"block".equals(args[0])))
|
||||
{
|
||||
return (args.length != 4 || !"entity".equals(args[0])) && (args.length != 6 || !"block".equals(args[0])) ? Collections.emptyList() : getListOfStringsMatchingLastWord(args, Item.REGISTRY.getKeys());
|
||||
}
|
||||
else
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, SHORTCUTS.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return args.length > 0 && "entity".equals(args[0]) && index == 1;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for (int i = 0; i < 54; ++i)
|
||||
{
|
||||
SHORTCUTS.put("slot.container." + i, Integer.valueOf(i));
|
||||
}
|
||||
|
||||
for (int j = 0; j < 9; ++j)
|
||||
{
|
||||
SHORTCUTS.put("slot.hotbar." + j, Integer.valueOf(j));
|
||||
}
|
||||
|
||||
for (int k = 0; k < 27; ++k)
|
||||
{
|
||||
SHORTCUTS.put("slot.inventory." + k, Integer.valueOf(9 + k));
|
||||
}
|
||||
|
||||
for (int l = 0; l < 27; ++l)
|
||||
{
|
||||
SHORTCUTS.put("slot.enderchest." + l, Integer.valueOf(200 + l));
|
||||
}
|
||||
|
||||
for (int i1 = 0; i1 < 8; ++i1)
|
||||
{
|
||||
SHORTCUTS.put("slot.villager." + i1, Integer.valueOf(300 + i1));
|
||||
}
|
||||
|
||||
for (int j1 = 0; j1 < 15; ++j1)
|
||||
{
|
||||
SHORTCUTS.put("slot.horse." + j1, Integer.valueOf(500 + j1));
|
||||
}
|
||||
|
||||
SHORTCUTS.put("slot.weapon", Integer.valueOf(98));
|
||||
SHORTCUTS.put("slot.weapon.mainhand", Integer.valueOf(98));
|
||||
SHORTCUTS.put("slot.weapon.offhand", Integer.valueOf(99));
|
||||
SHORTCUTS.put("slot.armor.head", Integer.valueOf(100 + EntityEquipmentSlot.HEAD.getIndex()));
|
||||
SHORTCUTS.put("slot.armor.chest", Integer.valueOf(100 + EntityEquipmentSlot.CHEST.getIndex()));
|
||||
SHORTCUTS.put("slot.armor.legs", Integer.valueOf(100 + EntityEquipmentSlot.LEGS.getIndex()));
|
||||
SHORTCUTS.put("slot.armor.feet", Integer.valueOf(100 + EntityEquipmentSlot.FEET.getIndex()));
|
||||
SHORTCUTS.put("slot.horse.saddle", Integer.valueOf(400));
|
||||
SHORTCUTS.put("slot.horse.armor", Integer.valueOf(401));
|
||||
SHORTCUTS.put("slot.horse.chest", Integer.valueOf(499));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.scoreboard.Score;
|
||||
import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandResultStats
|
||||
{
|
||||
/** The number of result command result types that are possible. */
|
||||
private static final int NUM_RESULT_TYPES = CommandResultStats.Type.values().length;
|
||||
private static final String[] STRING_RESULT_TYPES = new String[NUM_RESULT_TYPES];
|
||||
/** List of entityID who set a stat, username for a player, UUID for all entities */
|
||||
private String[] entitiesID;
|
||||
/** List of all the Objectives names */
|
||||
private String[] objectives;
|
||||
|
||||
public CommandResultStats()
|
||||
{
|
||||
this.entitiesID = STRING_RESULT_TYPES;
|
||||
this.objectives = STRING_RESULT_TYPES;
|
||||
}
|
||||
|
||||
public void setCommandStatForSender(MinecraftServer server, final ICommandSender sender, CommandResultStats.Type typeIn, int p_184932_4_)
|
||||
{
|
||||
String s = this.entitiesID[typeIn.getTypeID()];
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
ICommandSender icommandsender = new ICommandSender()
|
||||
{
|
||||
/**
|
||||
* Get the name of this object. For players this returns their username
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return sender.getName();
|
||||
}
|
||||
/**
|
||||
* Get the formatted ChatComponent that will be used for the sender's username in chat
|
||||
*/
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return sender.getDisplayName();
|
||||
}
|
||||
/**
|
||||
* Send a chat message to the CommandSender
|
||||
*/
|
||||
public void sendMessage(ITextComponent component)
|
||||
{
|
||||
sender.sendMessage(component);
|
||||
}
|
||||
/**
|
||||
* Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
|
||||
*/
|
||||
public boolean canUseCommand(int permLevel, String commandName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the
|
||||
* world, return the coordinates 0, 0, 0
|
||||
*/
|
||||
public BlockPos getPosition()
|
||||
{
|
||||
return sender.getPosition();
|
||||
}
|
||||
/**
|
||||
* Get the position vector. <b>{@code null} is not allowed!</b> If you are not an entity in the world,
|
||||
* return 0.0D, 0.0D, 0.0D
|
||||
*/
|
||||
public Vec3d getPositionVector()
|
||||
{
|
||||
return sender.getPositionVector();
|
||||
}
|
||||
/**
|
||||
* Get the world, if available. <b>{@code null} is not allowed!</b> If you are not an entity in the
|
||||
* world, return the overworld
|
||||
*/
|
||||
public World getEntityWorld()
|
||||
{
|
||||
return sender.getEntityWorld();
|
||||
}
|
||||
/**
|
||||
* Returns the entity associated with the command sender. MAY BE NULL!
|
||||
*/
|
||||
public Entity getCommandSenderEntity()
|
||||
{
|
||||
return sender.getCommandSenderEntity();
|
||||
}
|
||||
/**
|
||||
* Returns true if the command sender should be sent feedback about executed commands
|
||||
*/
|
||||
public boolean sendCommandFeedback()
|
||||
{
|
||||
return sender.sendCommandFeedback();
|
||||
}
|
||||
public void setCommandStat(CommandResultStats.Type type, int amount)
|
||||
{
|
||||
sender.setCommandStat(type, amount);
|
||||
}
|
||||
/**
|
||||
* Get the Minecraft server instance
|
||||
*/
|
||||
public MinecraftServer getServer()
|
||||
{
|
||||
return sender.getServer();
|
||||
}
|
||||
};
|
||||
String s1;
|
||||
|
||||
try
|
||||
{
|
||||
s1 = CommandBase.getEntityName(server, icommandsender, s);
|
||||
}
|
||||
catch (CommandException var12)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String s2 = this.objectives[typeIn.getTypeID()];
|
||||
|
||||
if (s2 != null)
|
||||
{
|
||||
Scoreboard scoreboard = sender.getEntityWorld().getScoreboard();
|
||||
ScoreObjective scoreobjective = scoreboard.getObjective(s2);
|
||||
|
||||
if (scoreobjective != null)
|
||||
{
|
||||
if (scoreboard.entityHasObjective(s1, scoreobjective))
|
||||
{
|
||||
Score score = scoreboard.getOrCreateScore(s1, scoreobjective);
|
||||
score.setScorePoints(p_184932_4_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readStatsFromNBT(NBTTagCompound tagcompound)
|
||||
{
|
||||
if (tagcompound.hasKey("CommandStats", 10))
|
||||
{
|
||||
NBTTagCompound nbttagcompound = tagcompound.getCompoundTag("CommandStats");
|
||||
|
||||
for (CommandResultStats.Type commandresultstats$type : CommandResultStats.Type.values())
|
||||
{
|
||||
String s = commandresultstats$type.getTypeName() + "Name";
|
||||
String s1 = commandresultstats$type.getTypeName() + "Objective";
|
||||
|
||||
if (nbttagcompound.hasKey(s, 8) && nbttagcompound.hasKey(s1, 8))
|
||||
{
|
||||
String s2 = nbttagcompound.getString(s);
|
||||
String s3 = nbttagcompound.getString(s1);
|
||||
setScoreBoardStat(this, commandresultstats$type, s2, s3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeStatsToNBT(NBTTagCompound tagcompound)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
|
||||
for (CommandResultStats.Type commandresultstats$type : CommandResultStats.Type.values())
|
||||
{
|
||||
String s = this.entitiesID[commandresultstats$type.getTypeID()];
|
||||
String s1 = this.objectives[commandresultstats$type.getTypeID()];
|
||||
|
||||
if (s != null && s1 != null)
|
||||
{
|
||||
nbttagcompound.setString(commandresultstats$type.getTypeName() + "Name", s);
|
||||
nbttagcompound.setString(commandresultstats$type.getTypeName() + "Objective", s1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!nbttagcompound.hasNoTags())
|
||||
{
|
||||
tagcompound.setTag("CommandStats", nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a stat in the scoreboard
|
||||
*/
|
||||
public static void setScoreBoardStat(CommandResultStats stats, CommandResultStats.Type resultType, @Nullable String entityID, @Nullable String objectiveName)
|
||||
{
|
||||
if (entityID != null && !entityID.isEmpty() && objectiveName != null && !objectiveName.isEmpty())
|
||||
{
|
||||
if (stats.entitiesID == STRING_RESULT_TYPES || stats.objectives == STRING_RESULT_TYPES)
|
||||
{
|
||||
stats.entitiesID = new String[NUM_RESULT_TYPES];
|
||||
stats.objectives = new String[NUM_RESULT_TYPES];
|
||||
}
|
||||
|
||||
stats.entitiesID[resultType.getTypeID()] = entityID;
|
||||
stats.objectives[resultType.getTypeID()] = objectiveName;
|
||||
}
|
||||
else
|
||||
{
|
||||
removeScoreBoardStat(stats, resultType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a stat from the scoreboard
|
||||
*/
|
||||
private static void removeScoreBoardStat(CommandResultStats resultStatsIn, CommandResultStats.Type resultTypeIn)
|
||||
{
|
||||
if (resultStatsIn.entitiesID != STRING_RESULT_TYPES && resultStatsIn.objectives != STRING_RESULT_TYPES)
|
||||
{
|
||||
resultStatsIn.entitiesID[resultTypeIn.getTypeID()] = null;
|
||||
resultStatsIn.objectives[resultTypeIn.getTypeID()] = null;
|
||||
boolean flag = true;
|
||||
|
||||
for (CommandResultStats.Type commandresultstats$type : CommandResultStats.Type.values())
|
||||
{
|
||||
if (resultStatsIn.entitiesID[commandresultstats$type.getTypeID()] != null && resultStatsIn.objectives[commandresultstats$type.getTypeID()] != null)
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
resultStatsIn.entitiesID = STRING_RESULT_TYPES;
|
||||
resultStatsIn.objectives = STRING_RESULT_TYPES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all stats in the CommandResultStats
|
||||
*/
|
||||
public void addAllStats(CommandResultStats resultStatsIn)
|
||||
{
|
||||
for (CommandResultStats.Type commandresultstats$type : CommandResultStats.Type.values())
|
||||
{
|
||||
setScoreBoardStat(this, commandresultstats$type, resultStatsIn.entitiesID[commandresultstats$type.getTypeID()], resultStatsIn.objectives[commandresultstats$type.getTypeID()]);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Type
|
||||
{
|
||||
SUCCESS_COUNT(0, "SuccessCount"),
|
||||
AFFECTED_BLOCKS(1, "AffectedBlocks"),
|
||||
AFFECTED_ENTITIES(2, "AffectedEntities"),
|
||||
AFFECTED_ITEMS(3, "AffectedItems"),
|
||||
QUERY_RESULT(4, "QueryResult");
|
||||
|
||||
/** The integer ID of the Result Type. */
|
||||
final int typeID;
|
||||
/** The string representation of the type. */
|
||||
final String typeName;
|
||||
|
||||
private Type(int id, String name)
|
||||
{
|
||||
this.typeID = id;
|
||||
this.typeName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the integer ID of the result type.
|
||||
*/
|
||||
public int getTypeID()
|
||||
{
|
||||
return this.typeID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of the type.
|
||||
*/
|
||||
public String getTypeName()
|
||||
{
|
||||
return this.typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of all possible Result Types.
|
||||
*/
|
||||
public static String[] getTypeNames()
|
||||
{
|
||||
String[] astring = new String[values().length];
|
||||
int i = 0;
|
||||
|
||||
for (CommandResultStats.Type commandresultstats$type : values())
|
||||
{
|
||||
astring[i++] = commandresultstats$type.getTypeName();
|
||||
}
|
||||
|
||||
return astring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Type indicated by the supplied name string.
|
||||
*/
|
||||
@Nullable
|
||||
public static CommandResultStats.Type getTypeByName(String name)
|
||||
{
|
||||
for (CommandResultStats.Type commandresultstats$type : values())
|
||||
{
|
||||
if (commandresultstats$type.getTypeName().equals(name))
|
||||
{
|
||||
return commandresultstats$type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandSenderWrapper implements ICommandSender
|
||||
{
|
||||
private final ICommandSender delegate;
|
||||
@Nullable
|
||||
private final Vec3d positionVector;
|
||||
@Nullable
|
||||
private final BlockPos position;
|
||||
@Nullable
|
||||
private final Integer permissionLevel;
|
||||
@Nullable
|
||||
private final Entity entity;
|
||||
@Nullable
|
||||
private final Boolean sendCommandFeedback;
|
||||
|
||||
public CommandSenderWrapper(ICommandSender delegateIn, @Nullable Vec3d positionVectorIn, @Nullable BlockPos positionIn, @Nullable Integer permissionLevelIn, @Nullable Entity entityIn, @Nullable Boolean sendCommandFeedbackIn)
|
||||
{
|
||||
this.delegate = delegateIn;
|
||||
this.positionVector = positionVectorIn;
|
||||
this.position = positionIn;
|
||||
this.permissionLevel = permissionLevelIn;
|
||||
this.entity = entityIn;
|
||||
this.sendCommandFeedback = sendCommandFeedbackIn;
|
||||
}
|
||||
|
||||
public static CommandSenderWrapper create(ICommandSender sender)
|
||||
{
|
||||
return sender instanceof CommandSenderWrapper ? (CommandSenderWrapper)sender : new CommandSenderWrapper(sender, (Vec3d)null, (BlockPos)null, (Integer)null, (Entity)null, (Boolean)null);
|
||||
}
|
||||
|
||||
public CommandSenderWrapper withEntity(Entity entityIn, Vec3d p_193997_2_)
|
||||
{
|
||||
return this.entity == entityIn && Objects.equals(this.positionVector, p_193997_2_) ? this : new CommandSenderWrapper(this.delegate, p_193997_2_, new BlockPos(p_193997_2_), this.permissionLevel, entityIn, this.sendCommandFeedback);
|
||||
}
|
||||
|
||||
public CommandSenderWrapper withPermissionLevel(int level)
|
||||
{
|
||||
return this.permissionLevel != null && this.permissionLevel.intValue() <= level ? this : new CommandSenderWrapper(this.delegate, this.positionVector, this.position, level, this.entity, this.sendCommandFeedback);
|
||||
}
|
||||
|
||||
public CommandSenderWrapper withSendCommandFeedback(boolean sendCommandFeedbackIn)
|
||||
{
|
||||
return this.sendCommandFeedback == null || this.sendCommandFeedback.booleanValue() && !sendCommandFeedbackIn ? new CommandSenderWrapper(this.delegate, this.positionVector, this.position, this.permissionLevel, this.entity, sendCommandFeedbackIn) : this;
|
||||
}
|
||||
|
||||
public CommandSenderWrapper computePositionVector()
|
||||
{
|
||||
return this.positionVector != null ? this : new CommandSenderWrapper(this.delegate, this.getPositionVector(), this.getPosition(), this.permissionLevel, this.entity, this.sendCommandFeedback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this object. For players this returns their username
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.entity != null ? this.entity.getName() : this.delegate.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted ChatComponent that will be used for the sender's username in chat
|
||||
*/
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return this.entity != null ? this.entity.getDisplayName() : this.delegate.getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a chat message to the CommandSender
|
||||
*/
|
||||
public void sendMessage(ITextComponent component)
|
||||
{
|
||||
if (this.sendCommandFeedback == null || this.sendCommandFeedback.booleanValue())
|
||||
{
|
||||
this.delegate.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
|
||||
*/
|
||||
public boolean canUseCommand(int permLevel, String commandName)
|
||||
{
|
||||
return this.permissionLevel != null && this.permissionLevel.intValue() < permLevel ? false : this.delegate.canUseCommand(permLevel, commandName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
|
||||
* the coordinates 0, 0, 0
|
||||
*/
|
||||
public BlockPos getPosition()
|
||||
{
|
||||
if (this.position != null)
|
||||
{
|
||||
return this.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.entity != null ? this.entity.getPosition() : this.delegate.getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position vector. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return 0.0D,
|
||||
* 0.0D, 0.0D
|
||||
*/
|
||||
public Vec3d getPositionVector()
|
||||
{
|
||||
if (this.positionVector != null)
|
||||
{
|
||||
return this.positionVector;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.entity != null ? this.entity.getPositionVector() : this.delegate.getPositionVector();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world, if available. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
|
||||
* the overworld
|
||||
*/
|
||||
public World getEntityWorld()
|
||||
{
|
||||
return this.entity != null ? this.entity.getEntityWorld() : this.delegate.getEntityWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity associated with the command sender. MAY BE NULL!
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getCommandSenderEntity()
|
||||
{
|
||||
return this.entity != null ? this.entity.getCommandSenderEntity() : this.delegate.getCommandSenderEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the command sender should be sent feedback about executed commands
|
||||
*/
|
||||
public boolean sendCommandFeedback()
|
||||
{
|
||||
return this.sendCommandFeedback != null ? this.sendCommandFeedback.booleanValue() : this.delegate.sendCommandFeedback();
|
||||
}
|
||||
|
||||
public void setCommandStat(CommandResultStats.Type type, int amount)
|
||||
{
|
||||
if (this.entity != null)
|
||||
{
|
||||
this.entity.setCommandStat(type, amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.delegate.setCommandStat(type, amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Minecraft server instance
|
||||
*/
|
||||
@Nullable
|
||||
public MinecraftServer getServer()
|
||||
{
|
||||
return this.delegate.getServer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandServerKick extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "kick";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.kick.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length > 0 && args[0].length() > 1)
|
||||
{
|
||||
EntityPlayerMP entityplayermp = server.getPlayerList().getPlayerByUsername(args[0]);
|
||||
|
||||
if (entityplayermp == null)
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.player.notFound", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length >= 2)
|
||||
{
|
||||
ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 1);
|
||||
entityplayermp.connection.disconnect(itextcomponent);
|
||||
notifyCommandListener(sender, this, "commands.kick.success.reason", new Object[] {entityplayermp.getName(), itextcomponent.getUnformattedText()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.kicked", new Object[0]));
|
||||
notifyCommandListener(sender, this, "commands.kick.success", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.kick.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length >= 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CommandSetPlayerTimeout extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "setidletimeout";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.setidletimeout.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.setidletimeout.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = parseInt(args[0], 0);
|
||||
server.setPlayerIdleTimeout(i);
|
||||
notifyCommandListener(sender, this, "commands.setidletimeout.success", new Object[] {i});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandSetSpawnpoint extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "spawnpoint";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.spawnpoint.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length > 1 && args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.spawnpoint.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp = args.length > 0 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender);
|
||||
BlockPos blockpos = args.length > 3 ? parseBlockPos(sender, args, 1, true) : entityplayermp.getPosition();
|
||||
|
||||
if (entityplayermp.world != null)
|
||||
{
|
||||
entityplayermp.setSpawnPoint(blockpos, true);
|
||||
notifyCommandListener(sender, this, "commands.spawnpoint.success", new Object[] {entityplayermp.getName(), blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length > 1 && args.length <= 4 ? getTabCompletionCoordinate(args, 1, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandShowSeed extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return server.isSinglePlayer() || super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "seed";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.seed.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
World world = (World)(sender instanceof EntityPlayer ? ((EntityPlayer)sender).world : server.getWorld(0));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.seed.success", new Object[] {world.getSeed()}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.scoreboard.Team;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandSpreadPlayers extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "spreadplayers";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.spreadplayers.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 6)
|
||||
{
|
||||
throw new WrongUsageException("commands.spreadplayers.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
BlockPos blockpos = sender.getPosition();
|
||||
double d0 = parseDouble((double)blockpos.getX(), args[i++], true);
|
||||
double d1 = parseDouble((double)blockpos.getZ(), args[i++], true);
|
||||
double d2 = parseDouble(args[i++], 0.0D);
|
||||
double d3 = parseDouble(args[i++], d2 + 1.0D);
|
||||
boolean flag = parseBoolean(args[i++]);
|
||||
List<Entity> list = Lists.<Entity>newArrayList();
|
||||
|
||||
while (i < args.length)
|
||||
{
|
||||
String s = args[i++];
|
||||
|
||||
if (EntitySelector.isSelector(s))
|
||||
{
|
||||
List<Entity> list1 = EntitySelector.<Entity>matchEntities(sender, s, Entity.class);
|
||||
|
||||
if (list1.isEmpty())
|
||||
{
|
||||
throw new EntityNotFoundException("commands.generic.selector.notFound", new Object[] {s});
|
||||
}
|
||||
|
||||
list.addAll(list1);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityplayer = server.getPlayerList().getPlayerByUsername(s);
|
||||
|
||||
if (entityplayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.generic.player.notFound", new Object[] {s});
|
||||
}
|
||||
|
||||
list.add(entityplayer);
|
||||
}
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, list.size());
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
throw new EntityNotFoundException("commands.spreadplayers.noop");
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.spreadplayers.spreading." + (flag ? "teams" : "players"), new Object[] {list.size(), d3, d0, d1, d2}));
|
||||
this.spread(sender, list, new CommandSpreadPlayers.Position(d0, d1), d2, d3, (list.get(0)).world, flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spread(ICommandSender sender, List<Entity> p_110669_2_, CommandSpreadPlayers.Position pos, double spreadDistance, double maxRange, World worldIn, boolean respectTeams) throws CommandException
|
||||
{
|
||||
Random random = new Random();
|
||||
double d0 = pos.x - maxRange;
|
||||
double d1 = pos.z - maxRange;
|
||||
double d2 = pos.x + maxRange;
|
||||
double d3 = pos.z + maxRange;
|
||||
CommandSpreadPlayers.Position[] acommandspreadplayers$position = this.createInitialPositions(random, respectTeams ? this.getNumberOfTeams(p_110669_2_) : p_110669_2_.size(), d0, d1, d2, d3);
|
||||
int i = this.spreadPositions(pos, spreadDistance, worldIn, random, d0, d1, d2, d3, acommandspreadplayers$position, respectTeams);
|
||||
double d4 = this.setPlayerPositions(p_110669_2_, worldIn, acommandspreadplayers$position, respectTeams);
|
||||
notifyCommandListener(sender, this, "commands.spreadplayers.success." + (respectTeams ? "teams" : "players"), new Object[] {acommandspreadplayers$position.length, pos.x, pos.z});
|
||||
|
||||
if (acommandspreadplayers$position.length > 1)
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.spreadplayers.info." + (respectTeams ? "teams" : "players"), new Object[] {String.format("%.2f", d4), i}));
|
||||
}
|
||||
}
|
||||
|
||||
private int getNumberOfTeams(List<Entity> p_110667_1_)
|
||||
{
|
||||
Set<Team> set = Sets.<Team>newHashSet();
|
||||
|
||||
for (Entity entity : p_110667_1_)
|
||||
{
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
set.add(entity.getTeam());
|
||||
}
|
||||
else
|
||||
{
|
||||
set.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
return set.size();
|
||||
}
|
||||
|
||||
private int spreadPositions(CommandSpreadPlayers.Position p_110668_1_, double p_110668_2_, World worldIn, Random random, double minX, double minZ, double maxX, double maxZ, CommandSpreadPlayers.Position[] p_110668_14_, boolean respectTeams) throws CommandException
|
||||
{
|
||||
boolean flag = true;
|
||||
double d0 = 3.4028234663852886E38D;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 10000 && flag; ++i)
|
||||
{
|
||||
flag = false;
|
||||
d0 = 3.4028234663852886E38D;
|
||||
|
||||
for (int j = 0; j < p_110668_14_.length; ++j)
|
||||
{
|
||||
CommandSpreadPlayers.Position commandspreadplayers$position = p_110668_14_[j];
|
||||
int k = 0;
|
||||
CommandSpreadPlayers.Position commandspreadplayers$position1 = new CommandSpreadPlayers.Position();
|
||||
|
||||
for (int l = 0; l < p_110668_14_.length; ++l)
|
||||
{
|
||||
if (j != l)
|
||||
{
|
||||
CommandSpreadPlayers.Position commandspreadplayers$position2 = p_110668_14_[l];
|
||||
double d1 = commandspreadplayers$position.dist(commandspreadplayers$position2);
|
||||
d0 = Math.min(d1, d0);
|
||||
|
||||
if (d1 < p_110668_2_)
|
||||
{
|
||||
++k;
|
||||
commandspreadplayers$position1.x += commandspreadplayers$position2.x - commandspreadplayers$position.x;
|
||||
commandspreadplayers$position1.z += commandspreadplayers$position2.z - commandspreadplayers$position.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
commandspreadplayers$position1.x /= (double)k;
|
||||
commandspreadplayers$position1.z /= (double)k;
|
||||
double d2 = (double)commandspreadplayers$position1.getLength();
|
||||
|
||||
if (d2 > 0.0D)
|
||||
{
|
||||
commandspreadplayers$position1.normalize();
|
||||
commandspreadplayers$position.moveAway(commandspreadplayers$position1);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandspreadplayers$position.randomize(random, minX, minZ, maxX, maxZ);
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (commandspreadplayers$position.clamp(minX, minZ, maxX, maxZ))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
for (CommandSpreadPlayers.Position commandspreadplayers$position3 : p_110668_14_)
|
||||
{
|
||||
if (!commandspreadplayers$position3.isSafe(worldIn))
|
||||
{
|
||||
commandspreadplayers$position3.randomize(random, minX, minZ, maxX, maxZ);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 10000)
|
||||
{
|
||||
throw new CommandException("commands.spreadplayers.failure." + (respectTeams ? "teams" : "players"), new Object[] {p_110668_14_.length, p_110668_1_.x, p_110668_1_.z, String.format("%.2f", d0)});
|
||||
}
|
||||
else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
private double setPlayerPositions(List<Entity> p_110671_1_, World worldIn, CommandSpreadPlayers.Position[] p_110671_3_, boolean p_110671_4_)
|
||||
{
|
||||
double d0 = 0.0D;
|
||||
int i = 0;
|
||||
Map<Team, CommandSpreadPlayers.Position> map = Maps.<Team, CommandSpreadPlayers.Position>newHashMap();
|
||||
|
||||
for (int j = 0; j < p_110671_1_.size(); ++j)
|
||||
{
|
||||
Entity entity = p_110671_1_.get(j);
|
||||
CommandSpreadPlayers.Position commandspreadplayers$position;
|
||||
|
||||
if (p_110671_4_)
|
||||
{
|
||||
Team team = entity instanceof EntityPlayer ? entity.getTeam() : null;
|
||||
|
||||
if (!map.containsKey(team))
|
||||
{
|
||||
map.put(team, p_110671_3_[i++]);
|
||||
}
|
||||
|
||||
commandspreadplayers$position = map.get(team);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandspreadplayers$position = p_110671_3_[i++];
|
||||
}
|
||||
|
||||
entity.setPositionAndUpdate((double)((float)MathHelper.floor(commandspreadplayers$position.x) + 0.5F), (double)commandspreadplayers$position.getSpawnY(worldIn), (double)MathHelper.floor(commandspreadplayers$position.z) + 0.5D);
|
||||
double d2 = Double.MAX_VALUE;
|
||||
|
||||
for (CommandSpreadPlayers.Position commandspreadplayers$position1 : p_110671_3_)
|
||||
{
|
||||
if (commandspreadplayers$position != commandspreadplayers$position1)
|
||||
{
|
||||
double d1 = commandspreadplayers$position.dist(commandspreadplayers$position1);
|
||||
d2 = Math.min(d1, d2);
|
||||
}
|
||||
}
|
||||
|
||||
d0 += d2;
|
||||
}
|
||||
|
||||
d0 = d0 / (double)p_110671_1_.size();
|
||||
return d0;
|
||||
}
|
||||
|
||||
private CommandSpreadPlayers.Position[] createInitialPositions(Random p_110670_1_, int p_110670_2_, double p_110670_3_, double p_110670_5_, double p_110670_7_, double p_110670_9_)
|
||||
{
|
||||
CommandSpreadPlayers.Position[] acommandspreadplayers$position = new CommandSpreadPlayers.Position[p_110670_2_];
|
||||
|
||||
for (int i = 0; i < acommandspreadplayers$position.length; ++i)
|
||||
{
|
||||
CommandSpreadPlayers.Position commandspreadplayers$position = new CommandSpreadPlayers.Position();
|
||||
commandspreadplayers$position.randomize(p_110670_1_, p_110670_3_, p_110670_5_, p_110670_7_, p_110670_9_);
|
||||
acommandspreadplayers$position[i] = commandspreadplayers$position;
|
||||
}
|
||||
|
||||
return acommandspreadplayers$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length >= 1 && args.length <= 2 ? getTabCompletionCoordinateXZ(args, 0, targetPos) : Collections.emptyList();
|
||||
}
|
||||
|
||||
static class Position
|
||||
{
|
||||
double x;
|
||||
double z;
|
||||
|
||||
Position()
|
||||
{
|
||||
}
|
||||
|
||||
Position(double xIn, double zIn)
|
||||
{
|
||||
this.x = xIn;
|
||||
this.z = zIn;
|
||||
}
|
||||
|
||||
double dist(CommandSpreadPlayers.Position pos)
|
||||
{
|
||||
double d0 = this.x - pos.x;
|
||||
double d1 = this.z - pos.z;
|
||||
return Math.sqrt(d0 * d0 + d1 * d1);
|
||||
}
|
||||
|
||||
void normalize()
|
||||
{
|
||||
double d0 = (double)this.getLength();
|
||||
this.x /= d0;
|
||||
this.z /= d0;
|
||||
}
|
||||
|
||||
float getLength()
|
||||
{
|
||||
return MathHelper.sqrt(this.x * this.x + this.z * this.z);
|
||||
}
|
||||
|
||||
public void moveAway(CommandSpreadPlayers.Position pos)
|
||||
{
|
||||
this.x -= pos.x;
|
||||
this.z -= pos.z;
|
||||
}
|
||||
|
||||
public boolean clamp(double p_111093_1_, double p_111093_3_, double p_111093_5_, double p_111093_7_)
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
if (this.x < p_111093_1_)
|
||||
{
|
||||
this.x = p_111093_1_;
|
||||
flag = true;
|
||||
}
|
||||
else if (this.x > p_111093_5_)
|
||||
{
|
||||
this.x = p_111093_5_;
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (this.z < p_111093_3_)
|
||||
{
|
||||
this.z = p_111093_3_;
|
||||
flag = true;
|
||||
}
|
||||
else if (this.z > p_111093_7_)
|
||||
{
|
||||
this.z = p_111093_7_;
|
||||
flag = true;
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
public int getSpawnY(World worldIn)
|
||||
{
|
||||
BlockPos blockpos = new BlockPos(this.x, 256.0D, this.z);
|
||||
|
||||
while (blockpos.getY() > 0)
|
||||
{
|
||||
blockpos = blockpos.down();
|
||||
|
||||
if (worldIn.getBlockState(blockpos).getMaterial() != Material.AIR)
|
||||
{
|
||||
return blockpos.getY() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 257;
|
||||
}
|
||||
|
||||
public boolean isSafe(World worldIn)
|
||||
{
|
||||
BlockPos blockpos = new BlockPos(this.x, 256.0D, this.z);
|
||||
|
||||
while (blockpos.getY() > 0)
|
||||
{
|
||||
blockpos = blockpos.down();
|
||||
Material material = worldIn.getBlockState(blockpos).getMaterial();
|
||||
|
||||
if (material != Material.AIR)
|
||||
{
|
||||
return !material.isLiquid() && material != Material.FIRE;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void randomize(Random rand, double p_111097_2_, double p_111097_4_, double p_111097_6_, double p_111097_8_)
|
||||
{
|
||||
this.x = MathHelper.nextDouble(rand, p_111097_2_, p_111097_6_);
|
||||
this.z = MathHelper.nextDouble(rand, p_111097_4_, p_111097_8_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock;
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandStats extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "stats";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.stats.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag;
|
||||
|
||||
if ("entity".equals(args[0]))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"block".equals(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.usage", new Object[0]);
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if (args.length < 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.block.usage", new Object[0]);
|
||||
}
|
||||
|
||||
i = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.entity.usage", new Object[0]);
|
||||
}
|
||||
|
||||
i = 2;
|
||||
}
|
||||
|
||||
String s = args[i++];
|
||||
|
||||
if ("set".equals(s))
|
||||
{
|
||||
if (args.length < i + 3)
|
||||
{
|
||||
if (i == 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.block.set.usage", new Object[0]);
|
||||
}
|
||||
|
||||
throw new WrongUsageException("commands.stats.entity.set.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"clear".equals(s))
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if (args.length < i + 1)
|
||||
{
|
||||
if (i == 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.stats.block.clear.usage", new Object[0]);
|
||||
}
|
||||
|
||||
throw new WrongUsageException("commands.stats.entity.clear.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
CommandResultStats.Type commandresultstats$type = CommandResultStats.Type.getTypeByName(args[i++]);
|
||||
|
||||
if (commandresultstats$type == null)
|
||||
{
|
||||
throw new CommandException("commands.stats.failed", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
World world = sender.getEntityWorld();
|
||||
CommandResultStats commandresultstats;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 1, false);
|
||||
TileEntity tileentity = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity == null)
|
||||
{
|
||||
throw new CommandException("commands.stats.noCompatibleBlock", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
|
||||
if (tileentity instanceof TileEntityCommandBlock)
|
||||
{
|
||||
commandresultstats = ((TileEntityCommandBlock)tileentity).getCommandResultStats();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(tileentity instanceof TileEntitySign))
|
||||
{
|
||||
throw new CommandException("commands.stats.noCompatibleBlock", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
|
||||
commandresultstats = ((TileEntitySign)tileentity).getStats();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[1]);
|
||||
commandresultstats = entity.getCommandStats();
|
||||
}
|
||||
|
||||
if ("set".equals(s))
|
||||
{
|
||||
String s1 = args[i++];
|
||||
String s2 = args[i];
|
||||
|
||||
if (s1.isEmpty() || s2.isEmpty())
|
||||
{
|
||||
throw new CommandException("commands.stats.failed", new Object[0]);
|
||||
}
|
||||
|
||||
CommandResultStats.setScoreBoardStat(commandresultstats, commandresultstats$type, s1, s2);
|
||||
notifyCommandListener(sender, this, "commands.stats.success", new Object[] {commandresultstats$type.getTypeName(), s2, s1});
|
||||
}
|
||||
else if ("clear".equals(s))
|
||||
{
|
||||
CommandResultStats.setScoreBoardStat(commandresultstats, commandresultstats$type, (String)null, (String)null);
|
||||
notifyCommandListener(sender, this, "commands.stats.cleared", new Object[] {commandresultstats$type.getTypeName()});
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
BlockPos blockpos1 = parseBlockPos(sender, args, 1, false);
|
||||
TileEntity tileentity1 = world.getTileEntity(blockpos1);
|
||||
tileentity1.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"entity", "block"});
|
||||
}
|
||||
else if (args.length == 2 && "entity".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else if (args.length >= 2 && args.length <= 4 && "block".equals(args[0]))
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 1, targetPos);
|
||||
}
|
||||
else if ((args.length != 3 || !"entity".equals(args[0])) && (args.length != 5 || !"block".equals(args[0])))
|
||||
{
|
||||
if ((args.length != 4 || !"entity".equals(args[0])) && (args.length != 6 || !"block".equals(args[0])))
|
||||
{
|
||||
return (args.length != 6 || !"entity".equals(args[0])) && (args.length != 8 || !"block".equals(args[0])) ? Collections.emptyList() : getListOfStringsMatchingLastWord(args, this.getObjectiveNames(server));
|
||||
}
|
||||
else
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, CommandResultStats.Type.getTypeNames());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"set", "clear"});
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> getObjectiveNames(MinecraftServer server)
|
||||
{
|
||||
Collection<ScoreObjective> collection = server.getWorld(0).getScoreboard().getScoreObjectives();
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
|
||||
for (ScoreObjective scoreobjective : collection)
|
||||
{
|
||||
if (!scoreobjective.getCriteria().isReadOnly())
|
||||
{
|
||||
list.add(scoreobjective.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return args.length > 0 && "entity".equals(args[0]) && index == 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandStopSound extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "stopsound";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.stopsound.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length >= 1 && args.length <= 3)
|
||||
{
|
||||
int i = 0;
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, args[i++]);
|
||||
String s = "";
|
||||
String s1 = "";
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
String s2 = args[i++];
|
||||
SoundCategory soundcategory = SoundCategory.getByName(s2);
|
||||
|
||||
if (soundcategory == null)
|
||||
{
|
||||
throw new CommandException("commands.stopsound.unknownSoundSource", new Object[] {s2});
|
||||
}
|
||||
|
||||
s = soundcategory.getName();
|
||||
}
|
||||
|
||||
if (args.length == 3)
|
||||
{
|
||||
s1 = args[i++];
|
||||
}
|
||||
|
||||
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
|
||||
packetbuffer.writeString(s);
|
||||
packetbuffer.writeString(s1);
|
||||
entityplayermp.connection.sendPacket(new SPacketCustomPayload("MC|StopSound", packetbuffer));
|
||||
|
||||
if (s.isEmpty() && s1.isEmpty())
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.stopsound.success.all", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
else if (s1.isEmpty())
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.stopsound.success.soundSource", new Object[] {s, entityplayermp.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.stopsound.success.individualSound", new Object[] {s1, s, entityplayermp.getName()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(this.getUsage(sender), new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, SoundCategory.getSoundCategoryNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 3 ? getListOfStringsMatchingLastWord(args, SoundEvent.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class CommandTP extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "tp";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.tp.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.tp.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
Entity entity;
|
||||
|
||||
if (args.length != 2 && args.length != 4 && args.length != 6)
|
||||
{
|
||||
entity = getCommandSenderAsPlayer(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = getEntity(server, sender, args[0]);
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (args.length != 1 && args.length != 2)
|
||||
{
|
||||
if (args.length < i + 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.tp.usage", new Object[0]);
|
||||
}
|
||||
else if (entity.world != null)
|
||||
{
|
||||
int j = 4096;
|
||||
int k = i + 1;
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(entity.posX, args[i], true);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(entity.posY, args[k++], -4096, 4096, false);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(entity.posZ, args[k++], true);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate((double)entity.rotationYaw, args.length > k ? args[k++] : "~", false);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate((double)entity.rotationPitch, args.length > k ? args[k] : "~", false);
|
||||
teleportEntityToCoordinates(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
|
||||
notifyCommandListener(sender, this, "commands.tp.success.coordinates", new Object[] {entity.getName(), commandbase$coordinatearg.getResult(), commandbase$coordinatearg1.getResult(), commandbase$coordinatearg2.getResult()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity1 = getEntity(server, sender, args[args.length - 1]);
|
||||
|
||||
if (entity1.world != entity.world)
|
||||
{
|
||||
throw new CommandException("commands.tp.notSameDimension", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.dismountRidingEntity();
|
||||
|
||||
if (entity instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP)entity).connection.setPlayerLocation(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.setLocationAndAngles(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.tp.success", new Object[] {entity.getName(), entity1.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports an entity to the specified coordinates
|
||||
*/
|
||||
private static void teleportEntityToCoordinates(Entity teleportingEntity, CommandBase.CoordinateArg argX, CommandBase.CoordinateArg argY, CommandBase.CoordinateArg argZ, CommandBase.CoordinateArg argYaw, CommandBase.CoordinateArg argPitch)
|
||||
{
|
||||
if (teleportingEntity instanceof EntityPlayerMP)
|
||||
{
|
||||
Set<SPacketPlayerPosLook.EnumFlags> set = EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class);
|
||||
|
||||
if (argX.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.X);
|
||||
}
|
||||
|
||||
if (argY.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.Y);
|
||||
}
|
||||
|
||||
if (argZ.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.Z);
|
||||
}
|
||||
|
||||
if (argPitch.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.X_ROT);
|
||||
}
|
||||
|
||||
if (argYaw.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.Y_ROT);
|
||||
}
|
||||
|
||||
float f = (float)argYaw.getAmount();
|
||||
|
||||
if (!argYaw.isRelative())
|
||||
{
|
||||
f = MathHelper.wrapDegrees(f);
|
||||
}
|
||||
|
||||
float f1 = (float)argPitch.getAmount();
|
||||
|
||||
if (!argPitch.isRelative())
|
||||
{
|
||||
f1 = MathHelper.wrapDegrees(f1);
|
||||
}
|
||||
|
||||
teleportingEntity.dismountRidingEntity();
|
||||
((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getAmount(), argY.getAmount(), argZ.getAmount(), f, f1, set);
|
||||
teleportingEntity.setRotationYawHead(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float f2 = (float)MathHelper.wrapDegrees(argYaw.getResult());
|
||||
float f3 = (float)MathHelper.wrapDegrees(argPitch.getResult());
|
||||
f3 = MathHelper.clamp(f3, -90.0F, 90.0F);
|
||||
teleportingEntity.setLocationAndAngles(argX.getResult(), argY.getResult(), argZ.getResult(), f2, f3);
|
||||
teleportingEntity.setRotationYawHead(f2);
|
||||
}
|
||||
|
||||
if (!(teleportingEntity instanceof EntityLivingBase) || !((EntityLivingBase)teleportingEntity).isElytraFlying())
|
||||
{
|
||||
teleportingEntity.motionY = 0.0D;
|
||||
teleportingEntity.onGround = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length != 1 && args.length != 2 ? Collections.emptyList() : getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class CommandTime extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "time";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.time.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
if ("set".equals(args[0]))
|
||||
{
|
||||
int i1;
|
||||
|
||||
if ("day".equals(args[1]))
|
||||
{
|
||||
i1 = 1000;
|
||||
}
|
||||
else if ("night".equals(args[1]))
|
||||
{
|
||||
i1 = 13000;
|
||||
}
|
||||
else
|
||||
{
|
||||
i1 = parseInt(args[1], 0);
|
||||
}
|
||||
|
||||
this.setAllWorldTimes(server, i1);
|
||||
notifyCommandListener(sender, this, "commands.time.set", new Object[] {i1});
|
||||
return;
|
||||
}
|
||||
|
||||
if ("add".equals(args[0]))
|
||||
{
|
||||
int l = parseInt(args[1], 0);
|
||||
this.incrementAllWorldTimes(server, l);
|
||||
notifyCommandListener(sender, this, "commands.time.added", new Object[] {l});
|
||||
return;
|
||||
}
|
||||
|
||||
if ("query".equals(args[0]))
|
||||
{
|
||||
if ("daytime".equals(args[1]))
|
||||
{
|
||||
int k = (int)(sender.getEntityWorld().getWorldTime() % 24000L);
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, k);
|
||||
notifyCommandListener(sender, this, "commands.time.query", new Object[] {k});
|
||||
return;
|
||||
}
|
||||
|
||||
if ("day".equals(args[1]))
|
||||
{
|
||||
int j = (int)(sender.getEntityWorld().getWorldTime() / 24000L % 2147483647L);
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, j);
|
||||
notifyCommandListener(sender, this, "commands.time.query", new Object[] {j});
|
||||
return;
|
||||
}
|
||||
|
||||
if ("gametime".equals(args[1]))
|
||||
{
|
||||
int i = (int)(sender.getEntityWorld().getTotalWorldTime() % 2147483647L);
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, i);
|
||||
notifyCommandListener(sender, this, "commands.time.query", new Object[] {i});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new WrongUsageException("commands.time.usage", new Object[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"set", "add", "query"});
|
||||
}
|
||||
else if (args.length == 2 && "set".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"day", "night"});
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 && "query".equals(args[0]) ? getListOfStringsMatchingLastWord(args, new String[] {"daytime", "gametime", "day"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setAllWorldTimes(MinecraftServer server, int time)
|
||||
{
|
||||
for (int i = 0; i < server.worlds.length; ++i)
|
||||
{
|
||||
server.worlds[i].setWorldTime((long)time);
|
||||
}
|
||||
}
|
||||
|
||||
protected void incrementAllWorldTimes(MinecraftServer server, int amount)
|
||||
{
|
||||
for (int i = 0; i < server.worlds.length; ++i)
|
||||
{
|
||||
WorldServer worldserver = server.worlds[i];
|
||||
worldserver.setWorldTime(worldserver.getWorldTime() + (long)amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketTitle;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class CommandTitle extends CommandBase
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "title";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.title.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
if ("title".equals(args[1]) || "subtitle".equals(args[1]) || "actionbar".equals(args[1]))
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage.title", new Object[0]);
|
||||
}
|
||||
|
||||
if ("times".equals(args[1]))
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage.times", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, args[0]);
|
||||
SPacketTitle.Type spackettitle$type = SPacketTitle.Type.byName(args[1]);
|
||||
|
||||
if (spackettitle$type != SPacketTitle.Type.CLEAR && spackettitle$type != SPacketTitle.Type.RESET)
|
||||
{
|
||||
if (spackettitle$type == SPacketTitle.Type.TIMES)
|
||||
{
|
||||
if (args.length != 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = parseInt(args[2]);
|
||||
int j = parseInt(args[3]);
|
||||
int k = parseInt(args[4]);
|
||||
SPacketTitle spackettitle2 = new SPacketTitle(i, j, k);
|
||||
entityplayermp.connection.sendPacket(spackettitle2);
|
||||
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
else if (args.length < 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = buildString(args, 2);
|
||||
ITextComponent itextcomponent;
|
||||
|
||||
try
|
||||
{
|
||||
itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
|
||||
}
|
||||
catch (JsonParseException jsonparseexception)
|
||||
{
|
||||
/**
|
||||
* Convert a JsonParseException into a user-friendly exception
|
||||
*/
|
||||
throw toSyntaxException(jsonparseexception);
|
||||
}
|
||||
|
||||
SPacketTitle spackettitle1 = new SPacketTitle(spackettitle$type, TextComponentUtils.processComponent(sender, itextcomponent, entityplayermp));
|
||||
entityplayermp.connection.sendPacket(spackettitle1);
|
||||
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
else if (args.length != 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.title.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
SPacketTitle spackettitle = new SPacketTitle(spackettitle$type, (ITextComponent)null);
|
||||
entityplayermp.connection.sendPacket(spackettitle);
|
||||
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, SPacketTitle.Type.getNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
|
||||
public class CommandToggleDownfall extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "toggledownfall";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.downfall.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
this.toggleRainfall(server);
|
||||
notifyCommandListener(sender, this, "commands.downfall.success", new Object[0]);
|
||||
}
|
||||
|
||||
protected void toggleRainfall(MinecraftServer server)
|
||||
{
|
||||
WorldInfo worldinfo = server.worlds[0].getWorldInfo();
|
||||
worldinfo.setRaining(!worldinfo.isRaining());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.scoreboard.IScoreCriteria;
|
||||
import net.minecraft.scoreboard.Score;
|
||||
import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandTrigger extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "trigger";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.trigger.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.trigger.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp;
|
||||
|
||||
if (sender instanceof EntityPlayerMP)
|
||||
{
|
||||
entityplayermp = (EntityPlayerMP)sender;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = sender.getCommandSenderEntity();
|
||||
|
||||
if (!(entity instanceof EntityPlayerMP))
|
||||
{
|
||||
throw new CommandException("commands.trigger.invalidPlayer", new Object[0]);
|
||||
}
|
||||
|
||||
entityplayermp = (EntityPlayerMP)entity;
|
||||
}
|
||||
|
||||
Scoreboard scoreboard = server.getWorld(0).getScoreboard();
|
||||
ScoreObjective scoreobjective = scoreboard.getObjective(args[0]);
|
||||
|
||||
if (scoreobjective != null && scoreobjective.getCriteria() == IScoreCriteria.TRIGGER)
|
||||
{
|
||||
int i = parseInt(args[2]);
|
||||
|
||||
if (!scoreboard.entityHasObjective(entityplayermp.getName(), scoreobjective))
|
||||
{
|
||||
throw new CommandException("commands.trigger.invalidObjective", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
Score score = scoreboard.getOrCreateScore(entityplayermp.getName(), scoreobjective);
|
||||
|
||||
if (score.isLocked())
|
||||
{
|
||||
throw new CommandException("commands.trigger.disabled", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("set".equals(args[1]))
|
||||
{
|
||||
score.setScorePoints(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"add".equals(args[1]))
|
||||
{
|
||||
throw new CommandException("commands.trigger.invalidMode", new Object[] {args[1]});
|
||||
}
|
||||
|
||||
score.increaseScore(i);
|
||||
}
|
||||
|
||||
score.setLocked(true);
|
||||
|
||||
if (entityplayermp.interactionManager.isCreative())
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.trigger.success", new Object[] {args[0], args[1], args[2]});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.trigger.invalidObjective", new Object[] {args[0]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
Scoreboard scoreboard = server.getWorld(0).getScoreboard();
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
|
||||
for (ScoreObjective scoreobjective : scoreboard.getScoreObjectives())
|
||||
{
|
||||
if (scoreobjective.getCriteria() == IScoreCriteria.TRIGGER)
|
||||
{
|
||||
list.add(scoreobjective.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return getListOfStringsMatchingLastWord(args, (String[])list.toArray(new String[list.size()]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, new String[] {"add", "set"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
|
||||
public class CommandWeather extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "weather";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.weather.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length >= 1 && args.length <= 2)
|
||||
{
|
||||
int i = (300 + (new Random()).nextInt(600)) * 20;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
i = parseInt(args[1], 1, 1000000) * 20;
|
||||
}
|
||||
|
||||
World world = server.worlds[0];
|
||||
WorldInfo worldinfo = world.getWorldInfo();
|
||||
|
||||
if ("clear".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
worldinfo.setCleanWeatherTime(i);
|
||||
worldinfo.setRainTime(0);
|
||||
worldinfo.setThunderTime(0);
|
||||
worldinfo.setRaining(false);
|
||||
worldinfo.setThundering(false);
|
||||
notifyCommandListener(sender, this, "commands.weather.clear", new Object[0]);
|
||||
}
|
||||
else if ("rain".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
worldinfo.setCleanWeatherTime(0);
|
||||
worldinfo.setRainTime(i);
|
||||
worldinfo.setThunderTime(i);
|
||||
worldinfo.setRaining(true);
|
||||
worldinfo.setThundering(false);
|
||||
notifyCommandListener(sender, this, "commands.weather.rain", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"thunder".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.weather.usage", new Object[0]);
|
||||
}
|
||||
|
||||
worldinfo.setCleanWeatherTime(0);
|
||||
worldinfo.setRainTime(i);
|
||||
worldinfo.setThunderTime(i);
|
||||
worldinfo.setRaining(true);
|
||||
worldinfo.setThundering(true);
|
||||
notifyCommandListener(sender, this, "commands.weather.thunder", new Object[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.weather.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"clear", "rain", "thunder"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.border.WorldBorder;
|
||||
|
||||
public class CommandWorldBorder extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "worldborder";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.worldborder.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldBorder worldborder = this.getWorldBorder(server);
|
||||
|
||||
if ("set".equals(args[0]))
|
||||
{
|
||||
if (args.length != 2 && args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.set.usage", new Object[0]);
|
||||
}
|
||||
|
||||
double d0 = worldborder.getTargetSize();
|
||||
double d2 = parseDouble(args[1], 1.0D, 6.0E7D);
|
||||
long i = args.length > 2 ? parseLong(args[2], 0L, 9223372036854775L) * 1000L : 0L;
|
||||
|
||||
if (i > 0L)
|
||||
{
|
||||
worldborder.setTransition(d0, d2, i);
|
||||
|
||||
if (d0 > d2)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.worldborder.setSlowly.shrink.success", new Object[] {String.format("%.1f", d2), String.format("%.1f", d0), Long.toString(i / 1000L)});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.worldborder.setSlowly.grow.success", new Object[] {String.format("%.1f", d2), String.format("%.1f", d0), Long.toString(i / 1000L)});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
worldborder.setTransition(d2);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.set.success", new Object[] {String.format("%.1f", d2), String.format("%.1f", d0)});
|
||||
}
|
||||
}
|
||||
else if ("add".equals(args[0]))
|
||||
{
|
||||
if (args.length != 2 && args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.add.usage", new Object[0]);
|
||||
}
|
||||
|
||||
double d4 = worldborder.getDiameter();
|
||||
double d8 = d4 + parseDouble(args[1], -d4, 6.0E7D - d4);
|
||||
long j1 = worldborder.getTimeUntilTarget() + (args.length > 2 ? parseLong(args[2], 0L, 9223372036854775L) * 1000L : 0L);
|
||||
|
||||
if (j1 > 0L)
|
||||
{
|
||||
worldborder.setTransition(d4, d8, j1);
|
||||
|
||||
if (d4 > d8)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.worldborder.setSlowly.shrink.success", new Object[] {String.format("%.1f", d8), String.format("%.1f", d4), Long.toString(j1 / 1000L)});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.worldborder.setSlowly.grow.success", new Object[] {String.format("%.1f", d8), String.format("%.1f", d4), Long.toString(j1 / 1000L)});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
worldborder.setTransition(d8);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.set.success", new Object[] {String.format("%.1f", d8), String.format("%.1f", d4)});
|
||||
}
|
||||
}
|
||||
else if ("center".equals(args[0]))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.center.usage", new Object[0]);
|
||||
}
|
||||
|
||||
BlockPos blockpos = sender.getPosition();
|
||||
double d1 = parseDouble((double)blockpos.getX() + 0.5D, args[1], true);
|
||||
double d3 = parseDouble((double)blockpos.getZ() + 0.5D, args[2], true);
|
||||
worldborder.setCenter(d1, d3);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.center.success", new Object[] {d1, d3});
|
||||
}
|
||||
else if ("damage".equals(args[0]))
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.damage.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if ("buffer".equals(args[1]))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.damage.buffer.usage", new Object[0]);
|
||||
}
|
||||
|
||||
double d5 = parseDouble(args[2], 0.0D);
|
||||
double d9 = worldborder.getDamageBuffer();
|
||||
worldborder.setDamageBuffer(d5);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.damage.buffer.success", new Object[] {String.format("%.1f", d5), String.format("%.1f", d9)});
|
||||
}
|
||||
else if ("amount".equals(args[1]))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.damage.amount.usage", new Object[0]);
|
||||
}
|
||||
|
||||
double d6 = parseDouble(args[2], 0.0D);
|
||||
double d10 = worldborder.getDamageAmount();
|
||||
worldborder.setDamageAmount(d6);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.damage.amount.success", new Object[] {String.format("%.2f", d6), String.format("%.2f", d10)});
|
||||
}
|
||||
}
|
||||
else if ("warning".equals(args[0]))
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.warning.usage", new Object[0]);
|
||||
}
|
||||
|
||||
if ("time".equals(args[1]))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.warning.time.usage", new Object[0]);
|
||||
}
|
||||
|
||||
int j = parseInt(args[2], 0);
|
||||
int l = worldborder.getWarningTime();
|
||||
worldborder.setWarningTime(j);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.warning.time.success", new Object[] {j, l});
|
||||
}
|
||||
else if ("distance".equals(args[1]))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.warning.distance.usage", new Object[0]);
|
||||
}
|
||||
|
||||
int k = parseInt(args[2], 0);
|
||||
int i1 = worldborder.getWarningDistance();
|
||||
worldborder.setWarningDistance(k);
|
||||
notifyCommandListener(sender, this, "commands.worldborder.warning.distance.success", new Object[] {k, i1});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"get".equals(args[0]))
|
||||
{
|
||||
throw new WrongUsageException("commands.worldborder.usage", new Object[0]);
|
||||
}
|
||||
|
||||
double d7 = worldborder.getDiameter();
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, MathHelper.floor(d7 + 0.5D));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.worldborder.get.success", new Object[] {String.format("%.0f", d7)}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected WorldBorder getWorldBorder(MinecraftServer server)
|
||||
{
|
||||
return server.worlds[0].getWorldBorder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"set", "center", "damage", "warning", "add", "get"});
|
||||
}
|
||||
else if (args.length == 2 && "damage".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"buffer", "amount"});
|
||||
}
|
||||
else if (args.length >= 2 && args.length <= 3 && "center".equals(args[0]))
|
||||
{
|
||||
return getTabCompletionCoordinateXZ(args, 1, targetPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 2 && "warning".equals(args[0]) ? getListOfStringsMatchingLastWord(args, new String[] {"time", "distance"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandXP extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "xp";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.xp.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length <= 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.xp.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = args[0];
|
||||
boolean flag = s.endsWith("l") || s.endsWith("L");
|
||||
|
||||
if (flag && s.length() > 1)
|
||||
{
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
|
||||
int i = parseInt(s);
|
||||
boolean flag1 = i < 0;
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
i *= -1;
|
||||
}
|
||||
|
||||
EntityPlayer entityplayer = args.length > 1 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
entityplayer.addExperienceLevel(-i);
|
||||
notifyCommandListener(sender, this, "commands.xp.success.negative.levels", new Object[] {i, entityplayer.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entityplayer.addExperienceLevel(i);
|
||||
notifyCommandListener(sender, this, "commands.xp.success.levels", new Object[] {i, entityplayer.getName()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
|
||||
}
|
||||
|
||||
entityplayer.addExperience(i);
|
||||
notifyCommandListener(sender, this, "commands.xp.success", new Object[] {i, entityplayer.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 2 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class EntityNotFoundException extends CommandException
|
||||
{
|
||||
public EntityNotFoundException(String p_i47332_1_)
|
||||
{
|
||||
this("commands.generic.entity.notFound", p_i47332_1_);
|
||||
}
|
||||
|
||||
public EntityNotFoundException(String message, Object... args)
|
||||
{
|
||||
super(message, args);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,885 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.scoreboard.Score;
|
||||
import net.minecraft.scoreboard.ScoreObjective;
|
||||
import net.minecraft.scoreboard.Scoreboard;
|
||||
import net.minecraft.scoreboard.Team;
|
||||
import net.minecraft.util.EntitySelectors;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntitySelector
|
||||
{
|
||||
/** This matches the at-tokens introduced for command blocks, including their arguments, if any. */
|
||||
private static final Pattern TOKEN_PATTERN = Pattern.compile("^@([pares])(?:\\[([^ ]*)\\])?$");
|
||||
private static final Splitter COMMA_SPLITTER = Splitter.on(',').omitEmptyStrings();
|
||||
private static final Splitter EQUAL_SPLITTER = Splitter.on('=').limit(2);
|
||||
private static final Set<String> VALID_ARGUMENTS = Sets.<String>newHashSet();
|
||||
private static final String ARGUMENT_RANGE_MAX = addArgument("r");
|
||||
private static final String ARGUMENT_RANGE_MIN = addArgument("rm");
|
||||
private static final String ARGUMENT_LEVEL_MAX = addArgument("l");
|
||||
private static final String ARGUMENT_LEVEL_MIN = addArgument("lm");
|
||||
private static final String ARGUMENT_COORDINATE_X = addArgument("x");
|
||||
private static final String ARGUMENT_COORDINATE_Y = addArgument("y");
|
||||
private static final String ARGUMENT_COORDINATE_Z = addArgument("z");
|
||||
private static final String ARGUMENT_DELTA_X = addArgument("dx");
|
||||
private static final String ARGUMENT_DELTA_Y = addArgument("dy");
|
||||
private static final String ARGUMENT_DELTA_Z = addArgument("dz");
|
||||
private static final String ARGUMENT_ROTX_MAX = addArgument("rx");
|
||||
private static final String ARGUMENT_ROTX_MIN = addArgument("rxm");
|
||||
private static final String ARGUMENT_ROTY_MAX = addArgument("ry");
|
||||
private static final String ARGUMENT_ROTY_MIN = addArgument("rym");
|
||||
private static final String ARGUMENT_COUNT = addArgument("c");
|
||||
private static final String ARGUMENT_MODE = addArgument("m");
|
||||
private static final String ARGUMENT_TEAM_NAME = addArgument("team");
|
||||
private static final String ARGUMENT_PLAYER_NAME = addArgument("name");
|
||||
private static final String ARGUMENT_ENTITY_TYPE = addArgument("type");
|
||||
private static final String ARGUMENT_ENTITY_TAG = addArgument("tag");
|
||||
private static final Predicate<String> IS_VALID_ARGUMENT = new Predicate<String>()
|
||||
{
|
||||
public boolean apply(@Nullable String p_apply_1_)
|
||||
{
|
||||
return p_apply_1_ != null && (EntitySelector.VALID_ARGUMENTS.contains(p_apply_1_) || p_apply_1_.length() > "score_".length() && p_apply_1_.startsWith("score_"));
|
||||
}
|
||||
};
|
||||
/**
|
||||
* A set of arguments that will change the selector's world list to the sender's world instead of all the worlds
|
||||
* when present
|
||||
*/
|
||||
private static final Set<String> WORLD_BINDING_ARGS = Sets.newHashSet(ARGUMENT_COORDINATE_X, ARGUMENT_COORDINATE_Y, ARGUMENT_COORDINATE_Z, ARGUMENT_DELTA_X, ARGUMENT_DELTA_Y, ARGUMENT_DELTA_Z, ARGUMENT_RANGE_MIN, ARGUMENT_RANGE_MAX);
|
||||
|
||||
public static String addArgument(String argument)
|
||||
{
|
||||
VALID_ARGUMENTS.add(argument);
|
||||
return argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the one player that matches the given at-token. Returns null if more than one player matches.
|
||||
*/
|
||||
@Nullable
|
||||
public static EntityPlayerMP matchOnePlayer(ICommandSender sender, String token) throws CommandException
|
||||
{
|
||||
return (EntityPlayerMP)matchOneEntity(sender, token, EntityPlayerMP.class);
|
||||
}
|
||||
|
||||
public static List<EntityPlayerMP> getPlayers(ICommandSender sender, String token) throws CommandException
|
||||
{
|
||||
return matchEntities(sender, token, EntityPlayerMP.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns one entity of the given class that matches the given at-token. Returns null if more than one entity
|
||||
* matches.
|
||||
*/
|
||||
@Nullable
|
||||
public static <T extends Entity> T matchOneEntity(ICommandSender sender, String token, Class <? extends T > targetClass) throws CommandException
|
||||
{
|
||||
List<T> list = matchEntities(sender, token, targetClass);
|
||||
return (T)(list.size() == 1 ? (Entity)list.get(0) : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ITextComponent matchEntitiesToTextComponent(ICommandSender sender, String token) throws CommandException
|
||||
{
|
||||
List<Entity> list = matchEntities(sender, token, Entity.class);
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ITextComponent> list1 = Lists.<ITextComponent>newArrayList();
|
||||
|
||||
for (Entity entity : list)
|
||||
{
|
||||
list1.add(entity.getDisplayName());
|
||||
}
|
||||
|
||||
return CommandBase.join(list1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all entities of the given class that matches the given at-token in a list.
|
||||
*/
|
||||
public static <T extends Entity> List<T> matchEntities(ICommandSender sender, String token, Class <? extends T > targetClass) throws CommandException
|
||||
{
|
||||
return net.minecraftforge.common.command.SelectorHandlerManager.matchEntities(sender, token, targetClass);
|
||||
}
|
||||
|
||||
public static <T extends Entity> List<T> matchEntitiesDefault(ICommandSender sender, String token, Class <? extends T > targetClass) throws CommandException
|
||||
{
|
||||
Matcher matcher = TOKEN_PATTERN.matcher(token);
|
||||
|
||||
if (matcher.matches() && sender.canUseCommand(1, "@"))
|
||||
{
|
||||
Map<String, String> map = getArgumentMap(matcher.group(2));
|
||||
|
||||
if (!isEntityTypeValid(sender, map))
|
||||
{
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = matcher.group(1);
|
||||
BlockPos blockpos = getBlockPosFromArguments(map, sender.getPosition());
|
||||
Vec3d vec3d = getPosFromArguments(map, sender.getPositionVector());
|
||||
List<World> list = getWorlds(sender, map);
|
||||
List<T> list1 = Lists.<T>newArrayList();
|
||||
|
||||
for (World world : list)
|
||||
{
|
||||
if (world != null)
|
||||
{
|
||||
List<Predicate<Entity>> list2 = Lists.<Predicate<Entity>>newArrayList();
|
||||
list2.addAll(getTypePredicates(map, s));
|
||||
list2.addAll(getXpLevelPredicates(map));
|
||||
list2.addAll(getGamemodePredicates(map));
|
||||
list2.addAll(getTeamPredicates(map));
|
||||
list2.addAll(getScorePredicates(sender, map));
|
||||
list2.addAll(getNamePredicates(map));
|
||||
list2.addAll(getTagPredicates(map));
|
||||
list2.addAll(getRadiusPredicates(map, vec3d));
|
||||
list2.addAll(getRotationsPredicates(map));
|
||||
list2.addAll(net.minecraftforge.fml.common.registry.GameRegistry.createEntitySelectors(map, s, sender, vec3d));
|
||||
|
||||
if ("s".equalsIgnoreCase(s))
|
||||
{
|
||||
Entity entity = sender.getCommandSenderEntity();
|
||||
|
||||
if (entity != null && targetClass.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
if (map.containsKey(ARGUMENT_DELTA_X) || map.containsKey(ARGUMENT_DELTA_Y) || map.containsKey(ARGUMENT_DELTA_Z))
|
||||
{
|
||||
int i = getInt(map, ARGUMENT_DELTA_X, 0);
|
||||
int j = getInt(map, ARGUMENT_DELTA_Y, 0);
|
||||
int k = getInt(map, ARGUMENT_DELTA_Z, 0);
|
||||
AxisAlignedBB axisalignedbb = getAABB(blockpos, i, j, k);
|
||||
|
||||
if (!axisalignedbb.intersects(entity.getEntityBoundingBox()))
|
||||
{
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
for (Predicate<Entity> predicate : list2)
|
||||
{
|
||||
if (!predicate.apply(entity))
|
||||
{
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
return Lists.newArrayList((T)entity);
|
||||
}
|
||||
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
|
||||
list1.addAll(filterResults(map, targetClass, list2, s, world, blockpos));
|
||||
}
|
||||
}
|
||||
|
||||
return getEntitiesFromPredicates(list1, map, sender, targetClass, s, vec3d);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the worlds to match the entities in for the specified command sender and token. This returns the sender's
|
||||
* world if the selector specifies a location or all currently loaded worlds on the server if not.
|
||||
*/
|
||||
private static List<World> getWorlds(ICommandSender sender, Map<String, String> argumentMap)
|
||||
{
|
||||
List<World> list = Lists.<World>newArrayList();
|
||||
|
||||
if (hasArgument(argumentMap))
|
||||
{
|
||||
list.add(sender.getEntityWorld());
|
||||
}
|
||||
else
|
||||
{
|
||||
Collections.addAll(list, sender.getServer().worlds);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to make sure that the specified type is valid
|
||||
*/
|
||||
private static <T extends Entity> boolean isEntityTypeValid(ICommandSender commandSender, Map<String, String> params)
|
||||
{
|
||||
String s = getArgument(params, ARGUMENT_ENTITY_TYPE);
|
||||
|
||||
if (s == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceLocation resourcelocation = new ResourceLocation(s.startsWith("!") ? s.substring(1) : s);
|
||||
|
||||
if (EntityList.isRegistered(resourcelocation))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.generic.entity.invalidType", new Object[] {resourcelocation});
|
||||
textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
|
||||
commandSender.sendMessage(textcomponenttranslation);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getTypePredicates(Map<String, String> params, String type)
|
||||
{
|
||||
String s = getArgument(params, ARGUMENT_ENTITY_TYPE);
|
||||
|
||||
if (s == null || !type.equals("e") && !type.equals("r") && !type.equals("s"))
|
||||
{
|
||||
return !type.equals("e") && !type.equals("s") ? Collections.singletonList(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
return p_apply_1_ instanceof EntityPlayer;
|
||||
}
|
||||
}) : Collections.emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
final boolean flag = s.startsWith("!");
|
||||
final ResourceLocation resourcelocation = new ResourceLocation(flag ? s.substring(1) : s);
|
||||
return Collections.singletonList(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
return EntityList.isMatchingName(p_apply_1_, resourcelocation) != flag;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getXpLevelPredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
final int i = getInt(params, ARGUMENT_LEVEL_MIN, -1);
|
||||
final int j = getInt(params, ARGUMENT_LEVEL_MAX, -1);
|
||||
|
||||
if (i > -1 || j > -1)
|
||||
{
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (!(p_apply_1_ instanceof EntityPlayerMP))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp = (EntityPlayerMP)p_apply_1_;
|
||||
return (i <= -1 || entityplayermp.experienceLevel >= i) && (j <= -1 || entityplayermp.experienceLevel <= j);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getGamemodePredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
String s = getArgument(params, ARGUMENT_MODE);
|
||||
|
||||
if (s == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
final boolean flag = s.startsWith("!");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
GameType gametype;
|
||||
|
||||
try
|
||||
{
|
||||
int i = Integer.parseInt(s);
|
||||
gametype = GameType.parseGameTypeWithDefault(i, GameType.NOT_SET);
|
||||
}
|
||||
catch (Throwable var6)
|
||||
{
|
||||
gametype = GameType.parseGameTypeWithDefault(s, GameType.NOT_SET);
|
||||
}
|
||||
|
||||
final GameType type = gametype;
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (!(p_apply_1_ instanceof EntityPlayerMP))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp = (EntityPlayerMP)p_apply_1_;
|
||||
GameType gametype1 = entityplayermp.interactionManager.getGameType();
|
||||
return flag ? gametype1 != type : gametype1 == type;
|
||||
}
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getTeamPredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
String s = getArgument(params, ARGUMENT_TEAM_NAME);
|
||||
final boolean flag = s != null && s.startsWith("!");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
final String s_f_ = s;
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (!(p_apply_1_ instanceof EntityLivingBase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityLivingBase entitylivingbase = (EntityLivingBase)p_apply_1_;
|
||||
Team team = entitylivingbase.getTeam();
|
||||
String s1 = team == null ? "" : team.getName();
|
||||
return s1.equals(s_f_) != flag;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getScorePredicates(final ICommandSender sender, Map<String, String> params)
|
||||
{
|
||||
final Map<String, Integer> map = getScoreMap(params);
|
||||
return (List<Predicate<Entity>>)(map.isEmpty() ? Collections.emptyList() : Lists.newArrayList(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Scoreboard scoreboard = sender.getServer().getWorld(0).getScoreboard();
|
||||
|
||||
for (Entry<String, Integer> entry : map.entrySet())
|
||||
{
|
||||
String s = entry.getKey();
|
||||
boolean flag = false;
|
||||
|
||||
if (s.endsWith("_min") && s.length() > 4)
|
||||
{
|
||||
flag = true;
|
||||
s = s.substring(0, s.length() - 4);
|
||||
}
|
||||
|
||||
ScoreObjective scoreobjective = scoreboard.getObjective(s);
|
||||
|
||||
if (scoreobjective == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String s1 = p_apply_1_ instanceof EntityPlayerMP ? p_apply_1_.getName() : p_apply_1_.getCachedUniqueIdString();
|
||||
|
||||
if (!scoreboard.entityHasObjective(s1, scoreobjective))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Score score = scoreboard.getOrCreateScore(s1, scoreobjective);
|
||||
int i = score.getScorePoints();
|
||||
|
||||
if (i < ((Integer)entry.getValue()).intValue() && flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i > ((Integer)entry.getValue()).intValue() && !flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getNamePredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
String s = getArgument(params, ARGUMENT_PLAYER_NAME);
|
||||
final boolean flag = s != null && s.startsWith("!");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
final String s_f_ = s;
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
return p_apply_1_ != null && p_apply_1_.getName().equals(s_f_) != flag;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getTagPredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
String s = getArgument(params, ARGUMENT_ENTITY_TAG);
|
||||
final boolean flag = s != null && s.startsWith("!");
|
||||
|
||||
if (flag)
|
||||
{
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
final String s_f_ = s;
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ("".equals(s_f_))
|
||||
{
|
||||
return p_apply_1_.getTags().isEmpty() != flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
return p_apply_1_.getTags().contains(s_f_) != flag;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getRadiusPredicates(Map<String, String> params, final Vec3d pos)
|
||||
{
|
||||
double d0 = (double)getInt(params, ARGUMENT_RANGE_MIN, -1);
|
||||
double d1 = (double)getInt(params, ARGUMENT_RANGE_MAX, -1);
|
||||
final boolean flag = d0 < -0.5D;
|
||||
final boolean flag1 = d1 < -0.5D;
|
||||
|
||||
if (flag && flag1)
|
||||
{
|
||||
return Collections.<Predicate<Entity>>emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
double d2 = Math.max(d0, 1.0E-4D);
|
||||
final double d3 = d2 * d2;
|
||||
double d4 = Math.max(d1, 1.0E-4D);
|
||||
final double d5 = d4 * d4;
|
||||
return Lists.newArrayList(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d6 = pos.squareDistanceTo(p_apply_1_.posX, p_apply_1_.posY, p_apply_1_.posZ);
|
||||
return (flag || d6 >= d3) && (flag1 || d6 <= d5);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Predicate<Entity>> getRotationsPredicates(Map<String, String> params)
|
||||
{
|
||||
List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
|
||||
|
||||
if (params.containsKey(ARGUMENT_ROTY_MIN) || params.containsKey(ARGUMENT_ROTY_MAX))
|
||||
{
|
||||
final int i = MathHelper.wrapDegrees(getInt(params, ARGUMENT_ROTY_MIN, 0));
|
||||
final int j = MathHelper.wrapDegrees(getInt(params, ARGUMENT_ROTY_MAX, 359));
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i1 = MathHelper.wrapDegrees(MathHelper.floor(p_apply_1_.rotationYaw));
|
||||
|
||||
if (i > j)
|
||||
{
|
||||
return i1 >= i || i1 <= j;
|
||||
}
|
||||
else
|
||||
{
|
||||
return i1 >= i && i1 <= j;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (params.containsKey(ARGUMENT_ROTX_MIN) || params.containsKey(ARGUMENT_ROTX_MAX))
|
||||
{
|
||||
final int k = MathHelper.wrapDegrees(getInt(params, ARGUMENT_ROTX_MIN, 0));
|
||||
final int l = MathHelper.wrapDegrees(getInt(params, ARGUMENT_ROTX_MAX, 359));
|
||||
list.add(new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i1 = MathHelper.wrapDegrees(MathHelper.floor(p_apply_1_.rotationPitch));
|
||||
|
||||
if (k > l)
|
||||
{
|
||||
return i1 >= k || i1 <= l;
|
||||
}
|
||||
else
|
||||
{
|
||||
return i1 >= k && i1 <= l;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the results based on the paramaters of the selector
|
||||
*/
|
||||
private static <T extends Entity> List<T> filterResults(Map<String, String> params, Class <? extends T > entityClass, List<Predicate<Entity>> inputList, String type, World worldIn, BlockPos position)
|
||||
{
|
||||
List<T> list = Lists.<T>newArrayList();
|
||||
String s = getArgument(params, ARGUMENT_ENTITY_TYPE);
|
||||
s = s != null && s.startsWith("!") ? s.substring(1) : s;
|
||||
boolean flag = !type.equals("e");
|
||||
boolean flag1 = type.equals("r") && s != null;
|
||||
int i = getInt(params, ARGUMENT_DELTA_X, 0);
|
||||
int j = getInt(params, ARGUMENT_DELTA_Y, 0);
|
||||
int k = getInt(params, ARGUMENT_DELTA_Z, 0);
|
||||
int l = getInt(params, ARGUMENT_RANGE_MAX, -1);
|
||||
Predicate<Entity> predicate = Predicates.and(inputList);
|
||||
Predicate<Entity> predicate1 = Predicates.<Entity>and(EntitySelectors.IS_ALIVE, predicate);
|
||||
|
||||
if (!params.containsKey(ARGUMENT_DELTA_X) && !params.containsKey(ARGUMENT_DELTA_Y) && !params.containsKey(ARGUMENT_DELTA_Z))
|
||||
{
|
||||
if (l >= 0)
|
||||
{
|
||||
AxisAlignedBB axisalignedbb1 = new AxisAlignedBB((double)(position.getX() - l), (double)(position.getY() - l), (double)(position.getZ() - l), (double)(position.getX() + l + 1), (double)(position.getY() + l + 1), (double)(position.getZ() + l + 1));
|
||||
|
||||
if (flag && !flag1)
|
||||
{
|
||||
list.addAll(worldIn.getPlayers(entityClass, predicate1));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.addAll(worldIn.getEntitiesWithinAABB(entityClass, axisalignedbb1, predicate1));
|
||||
}
|
||||
}
|
||||
else if (type.equals("a"))
|
||||
{
|
||||
list.addAll(worldIn.getPlayers(entityClass, predicate));
|
||||
}
|
||||
else if (!type.equals("p") && (!type.equals("r") || flag1))
|
||||
{
|
||||
list.addAll(worldIn.getEntities(entityClass, predicate1));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.addAll(worldIn.getPlayers(entityClass, predicate1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final AxisAlignedBB axisalignedbb = getAABB(position, i, j, k);
|
||||
|
||||
if (flag && !flag1)
|
||||
{
|
||||
Predicate<Entity> predicate2 = new Predicate<Entity>()
|
||||
{
|
||||
public boolean apply(@Nullable Entity p_apply_1_)
|
||||
{
|
||||
return p_apply_1_ != null && axisalignedbb.intersects(p_apply_1_.getEntityBoundingBox());
|
||||
}
|
||||
};
|
||||
list.addAll(worldIn.getPlayers(entityClass, Predicates.and(predicate1, predicate2)));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.addAll(worldIn.getEntitiesWithinAABB(entityClass, axisalignedbb, predicate1));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static <T extends Entity> List<T> getEntitiesFromPredicates(List<T> matchingEntities, Map<String, String> params, ICommandSender sender, Class <? extends T > targetClass, String type, final Vec3d pos)
|
||||
{
|
||||
int i = getInt(params, ARGUMENT_COUNT, !type.equals("a") && !type.equals("e") ? 1 : 0);
|
||||
|
||||
if (!type.equals("p") && !type.equals("a") && !type.equals("e"))
|
||||
{
|
||||
if (type.equals("r"))
|
||||
{
|
||||
Collections.shuffle(matchingEntities);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Collections.sort(matchingEntities, new Comparator<Entity>()
|
||||
{
|
||||
public int compare(Entity p_compare_1_, Entity p_compare_2_)
|
||||
{
|
||||
return ComparisonChain.start().compare(p_compare_1_.getDistanceSq(pos.x, pos.y, pos.z), p_compare_2_.getDistanceSq(pos.x, pos.y, pos.z)).result();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Entity entity = sender.getCommandSenderEntity();
|
||||
|
||||
if (entity != null && targetClass.isAssignableFrom(entity.getClass()) && i == 1 && matchingEntities.contains(entity) && !"r".equals(type))
|
||||
{
|
||||
matchingEntities = Lists.newArrayList((T)entity);
|
||||
}
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
if (i < 0)
|
||||
{
|
||||
Collections.reverse(matchingEntities);
|
||||
}
|
||||
|
||||
matchingEntities = matchingEntities.subList(0, Math.min(Math.abs(i), matchingEntities.size()));
|
||||
}
|
||||
|
||||
return matchingEntities;
|
||||
}
|
||||
|
||||
private static AxisAlignedBB getAABB(BlockPos pos, int x, int y, int z)
|
||||
{
|
||||
boolean flag = x < 0;
|
||||
boolean flag1 = y < 0;
|
||||
boolean flag2 = z < 0;
|
||||
int i = pos.getX() + (flag ? x : 0);
|
||||
int j = pos.getY() + (flag1 ? y : 0);
|
||||
int k = pos.getZ() + (flag2 ? z : 0);
|
||||
int l = pos.getX() + (flag ? 0 : x) + 1;
|
||||
int i1 = pos.getY() + (flag1 ? 0 : y) + 1;
|
||||
int j1 = pos.getZ() + (flag2 ? 0 : z) + 1;
|
||||
return new AxisAlignedBB((double)i, (double)j, (double)k, (double)l, (double)i1, (double)j1);
|
||||
}
|
||||
|
||||
private static BlockPos getBlockPosFromArguments(Map<String, String> params, BlockPos pos)
|
||||
{
|
||||
return new BlockPos(getInt(params, ARGUMENT_COORDINATE_X, pos.getX()), getInt(params, ARGUMENT_COORDINATE_Y, pos.getY()), getInt(params, ARGUMENT_COORDINATE_Z, pos.getZ()));
|
||||
}
|
||||
|
||||
private static Vec3d getPosFromArguments(Map<String, String> params, Vec3d pos)
|
||||
{
|
||||
return new Vec3d(getCoordinate(params, ARGUMENT_COORDINATE_X, pos.x, true), getCoordinate(params, ARGUMENT_COORDINATE_Y, pos.y, false), getCoordinate(params, ARGUMENT_COORDINATE_Z, pos.z, true));
|
||||
}
|
||||
|
||||
private static double getCoordinate(Map<String, String> params, String key, double defaultD, boolean offset)
|
||||
{
|
||||
return params.containsKey(key) ? (double)MathHelper.getInt(params.get(key), MathHelper.floor(defaultD)) + (offset ? 0.5D : 0.0D) : defaultD;
|
||||
}
|
||||
|
||||
private static boolean hasArgument(Map<String, String> params)
|
||||
{
|
||||
for (String s : WORLD_BINDING_ARGS)
|
||||
{
|
||||
if (params.containsKey(s))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int getInt(Map<String, String> params, String key, int defaultI)
|
||||
{
|
||||
return params.containsKey(key) ? MathHelper.getInt(params.get(key), defaultI) : defaultI;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getArgument(Map<String, String> params, String key)
|
||||
{
|
||||
return params.get(key);
|
||||
}
|
||||
|
||||
public static Map<String, Integer> getScoreMap(Map<String, String> params)
|
||||
{
|
||||
Map<String, Integer> map = Maps.<String, Integer>newHashMap();
|
||||
|
||||
for (String s : params.keySet())
|
||||
{
|
||||
if (s.startsWith("score_") && s.length() > "score_".length())
|
||||
{
|
||||
map.put(s.substring("score_".length()), Integer.valueOf(MathHelper.getInt(params.get(s), 1)));
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given pattern can match more than one player.
|
||||
*/
|
||||
public static boolean matchesMultiplePlayers(String selectorStr) throws CommandException
|
||||
{
|
||||
return net.minecraftforge.common.command.SelectorHandlerManager.matchesMultiplePlayers(selectorStr);
|
||||
}
|
||||
|
||||
public static boolean matchesMultiplePlayersDefault(String selectorStr) throws CommandException
|
||||
{
|
||||
Matcher matcher = TOKEN_PATTERN.matcher(selectorStr);
|
||||
|
||||
if (!matcher.matches())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<String, String> map = getArgumentMap(matcher.group(2));
|
||||
String s = matcher.group(1);
|
||||
int i = !"a".equals(s) && !"e".equals(s) ? 1 : 0;
|
||||
return getInt(map, ARGUMENT_COUNT, i) != 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given string represents a selector.
|
||||
*/
|
||||
public static boolean isSelector(String selectorStr)
|
||||
{
|
||||
return net.minecraftforge.common.command.SelectorHandlerManager.isSelector(selectorStr);
|
||||
}
|
||||
|
||||
public static boolean isSelectorDefault(String selectorStr)
|
||||
{
|
||||
return TOKEN_PATTERN.matcher(selectorStr).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given argument string, turning it into a HashMap<String, String> of name->value.
|
||||
*/
|
||||
private static Map<String, String> getArgumentMap(@Nullable String argumentString) throws CommandException
|
||||
{
|
||||
Map<String, String> map = Maps.<String, String>newHashMap();
|
||||
|
||||
if (argumentString == null)
|
||||
{
|
||||
return map;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : COMMA_SPLITTER.split(argumentString))
|
||||
{
|
||||
Iterator<String> iterator = EQUAL_SPLITTER.split(s).iterator();
|
||||
String s1 = iterator.next();
|
||||
|
||||
if (!IS_VALID_ARGUMENT.apply(s1))
|
||||
{
|
||||
throw new CommandException("commands.generic.selector_argument", new Object[] {s});
|
||||
}
|
||||
|
||||
map.put(s1, iterator.hasNext() ? (String)iterator.next() : "");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.FunctionManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class FunctionObject
|
||||
{
|
||||
private final FunctionObject.Entry[] entries;
|
||||
|
||||
public FunctionObject(FunctionObject.Entry[] entriesIn)
|
||||
{
|
||||
this.entries = entriesIn;
|
||||
}
|
||||
|
||||
public FunctionObject.Entry[] getEntries()
|
||||
{
|
||||
return this.entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Function from the given function definition.
|
||||
*/
|
||||
public static FunctionObject create(FunctionManager functionManagerIn, List<String> commands)
|
||||
{
|
||||
List<FunctionObject.Entry> list = Lists.<FunctionObject.Entry>newArrayListWithCapacity(commands.size());
|
||||
|
||||
for (String s : commands)
|
||||
{
|
||||
s = s.trim();
|
||||
|
||||
if (!s.startsWith("#") && !s.isEmpty())
|
||||
{
|
||||
String[] astring = s.split(" ", 2);
|
||||
String s1 = astring[0];
|
||||
|
||||
if (!functionManagerIn.getCommandManager().getCommands().containsKey(s1))
|
||||
{
|
||||
if (s1.startsWith("//"))
|
||||
{
|
||||
throw new IllegalArgumentException("Unknown or invalid command '" + s1 + "' (if you intended to make a comment, use '#' not '//')");
|
||||
}
|
||||
|
||||
if (s1.startsWith("/") && s1.length() > 1)
|
||||
{
|
||||
throw new IllegalArgumentException("Unknown or invalid command '" + s1 + "' (did you mean '" + s1.substring(1) + "'? Do not use a preceding forwards slash.)");
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unknown or invalid command '" + s1 + "'");
|
||||
}
|
||||
|
||||
list.add(new FunctionObject.CommandEntry(s));
|
||||
}
|
||||
}
|
||||
|
||||
return new FunctionObject((FunctionObject.Entry[])list.toArray(new FunctionObject.Entry[list.size()]));
|
||||
}
|
||||
|
||||
public static class CacheableFunction
|
||||
{
|
||||
public static final FunctionObject.CacheableFunction EMPTY = new FunctionObject.CacheableFunction((ResourceLocation)null);
|
||||
@Nullable
|
||||
private final ResourceLocation id;
|
||||
private boolean isValid;
|
||||
private FunctionObject function;
|
||||
|
||||
public CacheableFunction(@Nullable ResourceLocation idIn)
|
||||
{
|
||||
this.id = idIn;
|
||||
}
|
||||
|
||||
public CacheableFunction(FunctionObject functionIn)
|
||||
{
|
||||
this.id = null;
|
||||
this.function = functionIn;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FunctionObject get(FunctionManager functionManagerIn)
|
||||
{
|
||||
if (!this.isValid)
|
||||
{
|
||||
if (this.id != null)
|
||||
{
|
||||
this.function = functionManagerIn.getFunction(this.id);
|
||||
}
|
||||
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
return this.function;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf((Object)this.id);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandEntry implements FunctionObject.Entry
|
||||
{
|
||||
private final String command;
|
||||
|
||||
public CommandEntry(String p_i47534_1_)
|
||||
{
|
||||
this.command = p_i47534_1_;
|
||||
}
|
||||
|
||||
public void execute(FunctionManager functionManagerIn, ICommandSender sender, ArrayDeque<FunctionManager.QueuedCommand> commandQueue, int maxCommandChainLength)
|
||||
{
|
||||
functionManagerIn.getCommandManager().executeCommand(sender, this.command);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "/" + this.command;
|
||||
}
|
||||
}
|
||||
|
||||
public interface Entry
|
||||
{
|
||||
void execute(FunctionManager functionManagerIn, ICommandSender sender, ArrayDeque<FunctionManager.QueuedCommand> commandQueue, int maxCommandChainLength);
|
||||
}
|
||||
|
||||
public static class FunctionEntry implements FunctionObject.Entry
|
||||
{
|
||||
private final FunctionObject.CacheableFunction function;
|
||||
|
||||
public FunctionEntry(FunctionObject functionIn)
|
||||
{
|
||||
this.function = new FunctionObject.CacheableFunction(functionIn);
|
||||
}
|
||||
|
||||
public void execute(FunctionManager functionManagerIn, ICommandSender sender, ArrayDeque<FunctionManager.QueuedCommand> commandQueue, int maxCommandChainLength)
|
||||
{
|
||||
FunctionObject functionobject = this.function.get(functionManagerIn);
|
||||
|
||||
if (functionobject != null)
|
||||
{
|
||||
FunctionObject.Entry[] afunctionobject$entry = functionobject.getEntries();
|
||||
int i = maxCommandChainLength - commandQueue.size();
|
||||
int j = Math.min(afunctionobject$entry.length, i);
|
||||
|
||||
for (int k = j - 1; k >= 0; --k)
|
||||
{
|
||||
commandQueue.addFirst(new FunctionManager.QueuedCommand(functionManagerIn, sender, afunctionobject$entry[k]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "/function " + this.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface ICommand extends Comparable<ICommand>
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
String getUsage(ICommandSender sender);
|
||||
|
||||
/**
|
||||
* Get a list of aliases for this command. <b>Never return null!</b>
|
||||
*/
|
||||
List<String> getAliases();
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException;
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
boolean checkPermission(MinecraftServer server, ICommandSender sender);
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos);
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
boolean isUsernameIndex(String[] args, int index);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public interface ICommandListener
|
||||
{
|
||||
/**
|
||||
* Send an informative message to the server operators
|
||||
*/
|
||||
void notifyListener(ICommandSender sender, ICommand command, int flags, String translationKey, Object... translationArgs);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface ICommandManager
|
||||
{
|
||||
/**
|
||||
* Attempt to execute a command. This method should return the number of times that the command was executed. If the
|
||||
* command does not exist or if the player does not have permission, 0 will be returned. A number greater than 1 can
|
||||
* be returned if a player selector is used.
|
||||
*/
|
||||
int executeCommand(ICommandSender sender, String rawCommand);
|
||||
|
||||
/**
|
||||
* Get a list of possible completion options for when the TAB key is pressed. This can be a list of commands if no
|
||||
* command is specified or a partial command is specified. It could also be a list of arguments for the command that
|
||||
* is specified.
|
||||
*/
|
||||
List<String> getTabCompletions(ICommandSender sender, String input, @Nullable BlockPos pos);
|
||||
|
||||
/**
|
||||
* Get a list of commands that the given command sender has access to execute.
|
||||
*/
|
||||
List<ICommand> getPossibleCommands(ICommandSender sender);
|
||||
|
||||
/**
|
||||
* Get a Map of all the name to command pairs stored in this command manager.
|
||||
*/
|
||||
Map<String, ICommand> getCommands();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ICommandSender
|
||||
{
|
||||
/**
|
||||
* Get the name of this object. For players this returns their username
|
||||
*/
|
||||
String getName();
|
||||
|
||||
default ITextComponent getDisplayName()
|
||||
{
|
||||
return new TextComponentString(this.getName());
|
||||
}
|
||||
|
||||
default void sendMessage(ITextComponent component)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
|
||||
*/
|
||||
boolean canUseCommand(int permLevel, String commandName);
|
||||
|
||||
default BlockPos getPosition()
|
||||
{
|
||||
return BlockPos.ORIGIN;
|
||||
}
|
||||
|
||||
default Vec3d getPositionVector()
|
||||
{
|
||||
return Vec3d.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world, if available. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
|
||||
* the overworld
|
||||
*/
|
||||
World getEntityWorld();
|
||||
|
||||
@Nullable
|
||||
default Entity getCommandSenderEntity()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean sendCommandFeedback()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
default void setCommandStat(CommandResultStats.Type type, int amount)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Minecraft server instance
|
||||
*/
|
||||
@Nullable
|
||||
MinecraftServer getServer();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class InvalidBlockStateException extends CommandException
|
||||
{
|
||||
public InvalidBlockStateException()
|
||||
{
|
||||
this("commands.generic.blockstate.invalid");
|
||||
}
|
||||
|
||||
public InvalidBlockStateException(String message, Object... objects)
|
||||
{
|
||||
super(message, objects);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class NumberInvalidException extends CommandException
|
||||
{
|
||||
public NumberInvalidException()
|
||||
{
|
||||
this("commands.generic.num.invalid");
|
||||
}
|
||||
|
||||
public NumberInvalidException(String message, Object... replacements)
|
||||
{
|
||||
super(message, replacements);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class PlayerNotFoundException extends CommandException
|
||||
{
|
||||
public PlayerNotFoundException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlayerNotFoundException(String message, Object... replacements)
|
||||
{
|
||||
super(message, replacements);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class RecipeCommand extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "recipe";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.recipe.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.recipe.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = "give".equalsIgnoreCase(args[0]);
|
||||
boolean flag1 = "take".equalsIgnoreCase(args[0]);
|
||||
|
||||
if (!flag && !flag1)
|
||||
{
|
||||
throw new WrongUsageException("commands.recipe.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (EntityPlayerMP entityplayermp : getPlayers(server, sender, args[1]))
|
||||
{
|
||||
if ("*".equals(args[2]))
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
entityplayermp.unlockRecipes(this.getRecipes());
|
||||
notifyCommandListener(sender, this, "commands.recipe.give.success.all", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entityplayermp.resetRecipes(this.getRecipes());
|
||||
notifyCommandListener(sender, this, "commands.recipe.take.success.all", new Object[] {entityplayermp.getName()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IRecipe irecipe = CraftingManager.getRecipe(new ResourceLocation(args[2]));
|
||||
|
||||
if (irecipe == null)
|
||||
{
|
||||
throw new CommandException("commands.recipe.unknownrecipe", new Object[] {args[2]});
|
||||
}
|
||||
|
||||
if (irecipe.isDynamic())
|
||||
{
|
||||
throw new CommandException("commands.recipe.unsupported", new Object[] {args[2]});
|
||||
}
|
||||
|
||||
List<IRecipe> list = Lists.newArrayList(irecipe);
|
||||
|
||||
if (flag == entityplayermp.getRecipeBook().isUnlocked(irecipe))
|
||||
{
|
||||
String s = flag ? "commands.recipe.alreadyHave" : "commands.recipe.dontHave";
|
||||
throw new CommandException(s, new Object[] {entityplayermp.getName(), irecipe.getRecipeOutput().getDisplayName()});
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
entityplayermp.unlockRecipes(list);
|
||||
notifyCommandListener(sender, this, "commands.recipe.give.success.one", new Object[] {entityplayermp.getName(), irecipe.getRecipeOutput().getDisplayName()});
|
||||
}
|
||||
else
|
||||
{
|
||||
entityplayermp.resetRecipes(list);
|
||||
notifyCommandListener(sender, this, "commands.recipe.take.success.one", new Object[] {irecipe.getRecipeOutput().getDisplayName(), entityplayermp.getName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<IRecipe> getRecipes()
|
||||
{
|
||||
return Lists.newArrayList(CraftingManager.REGISTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"give", "take"});
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 3 ? getListOfStringsMatchingLastWord(args, CraftingManager.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
import net.minecraft.command.server.CommandBanIp;
|
||||
import net.minecraft.command.server.CommandBanPlayer;
|
||||
import net.minecraft.command.server.CommandBroadcast;
|
||||
import net.minecraft.command.server.CommandDeOp;
|
||||
import net.minecraft.command.server.CommandEmote;
|
||||
import net.minecraft.command.server.CommandListBans;
|
||||
import net.minecraft.command.server.CommandListPlayers;
|
||||
import net.minecraft.command.server.CommandMessage;
|
||||
import net.minecraft.command.server.CommandMessageRaw;
|
||||
import net.minecraft.command.server.CommandOp;
|
||||
import net.minecraft.command.server.CommandPardonIp;
|
||||
import net.minecraft.command.server.CommandPardonPlayer;
|
||||
import net.minecraft.command.server.CommandPublishLocalServer;
|
||||
import net.minecraft.command.server.CommandSaveAll;
|
||||
import net.minecraft.command.server.CommandSaveOff;
|
||||
import net.minecraft.command.server.CommandSaveOn;
|
||||
import net.minecraft.command.server.CommandScoreboard;
|
||||
import net.minecraft.command.server.CommandSetBlock;
|
||||
import net.minecraft.command.server.CommandSetDefaultSpawnpoint;
|
||||
import net.minecraft.command.server.CommandStop;
|
||||
import net.minecraft.command.server.CommandSummon;
|
||||
import net.minecraft.command.server.CommandTeleport;
|
||||
import net.minecraft.command.server.CommandTestFor;
|
||||
import net.minecraft.command.server.CommandTestForBlock;
|
||||
import net.minecraft.command.server.CommandWhitelist;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.rcon.RConConsoleSource;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.CommandBlockBaseLogic;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
public class ServerCommandManager extends CommandHandler implements ICommandListener
|
||||
{
|
||||
private final MinecraftServer server;
|
||||
|
||||
public ServerCommandManager(MinecraftServer serverIn)
|
||||
{
|
||||
this.server = serverIn;
|
||||
this.registerCommand(new CommandTime());
|
||||
this.registerCommand(new CommandGameMode());
|
||||
this.registerCommand(new CommandDifficulty());
|
||||
this.registerCommand(new CommandDefaultGameMode());
|
||||
this.registerCommand(new CommandKill());
|
||||
this.registerCommand(new CommandToggleDownfall());
|
||||
this.registerCommand(new CommandWeather());
|
||||
this.registerCommand(new CommandXP());
|
||||
this.registerCommand(new CommandTP());
|
||||
this.registerCommand(new CommandTeleport());
|
||||
this.registerCommand(new CommandGive());
|
||||
this.registerCommand(new CommandReplaceItem());
|
||||
this.registerCommand(new CommandStats());
|
||||
this.registerCommand(new CommandEffect());
|
||||
this.registerCommand(new CommandEnchant());
|
||||
this.registerCommand(new CommandParticle());
|
||||
this.registerCommand(new CommandEmote());
|
||||
this.registerCommand(new CommandShowSeed());
|
||||
this.registerCommand(new CommandHelp());
|
||||
this.registerCommand(new CommandDebug());
|
||||
this.registerCommand(new CommandMessage());
|
||||
this.registerCommand(new CommandBroadcast());
|
||||
this.registerCommand(new CommandSetSpawnpoint());
|
||||
this.registerCommand(new CommandSetDefaultSpawnpoint());
|
||||
this.registerCommand(new CommandGameRule());
|
||||
this.registerCommand(new CommandClearInventory());
|
||||
this.registerCommand(new CommandTestFor());
|
||||
this.registerCommand(new CommandSpreadPlayers());
|
||||
this.registerCommand(new CommandPlaySound());
|
||||
this.registerCommand(new CommandScoreboard());
|
||||
this.registerCommand(new CommandExecuteAt());
|
||||
this.registerCommand(new CommandTrigger());
|
||||
this.registerCommand(new AdvancementCommand());
|
||||
this.registerCommand(new RecipeCommand());
|
||||
this.registerCommand(new CommandSummon());
|
||||
this.registerCommand(new CommandSetBlock());
|
||||
this.registerCommand(new CommandFill());
|
||||
this.registerCommand(new CommandClone());
|
||||
this.registerCommand(new CommandCompare());
|
||||
this.registerCommand(new CommandBlockData());
|
||||
this.registerCommand(new CommandTestForBlock());
|
||||
this.registerCommand(new CommandMessageRaw());
|
||||
this.registerCommand(new CommandWorldBorder());
|
||||
this.registerCommand(new CommandTitle());
|
||||
this.registerCommand(new CommandEntityData());
|
||||
this.registerCommand(new CommandStopSound());
|
||||
this.registerCommand(new CommandLocate());
|
||||
this.registerCommand(new CommandReload());
|
||||
this.registerCommand(new CommandFunction());
|
||||
|
||||
if (serverIn.isDedicatedServer())
|
||||
{
|
||||
this.registerCommand(new CommandOp());
|
||||
this.registerCommand(new CommandDeOp());
|
||||
this.registerCommand(new CommandStop());
|
||||
this.registerCommand(new CommandSaveAll());
|
||||
this.registerCommand(new CommandSaveOff());
|
||||
this.registerCommand(new CommandSaveOn());
|
||||
this.registerCommand(new CommandBanIp());
|
||||
this.registerCommand(new CommandPardonIp());
|
||||
this.registerCommand(new CommandBanPlayer());
|
||||
this.registerCommand(new CommandListBans());
|
||||
this.registerCommand(new CommandPardonPlayer());
|
||||
this.registerCommand(new CommandServerKick());
|
||||
this.registerCommand(new CommandListPlayers());
|
||||
this.registerCommand(new CommandWhitelist());
|
||||
this.registerCommand(new CommandSetPlayerTimeout());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.registerCommand(new CommandPublishLocalServer());
|
||||
}
|
||||
|
||||
CommandBase.setCommandListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an informative message to the server operators
|
||||
*/
|
||||
public void notifyListener(ICommandSender sender, ICommand command, int flags, String translationKey, Object... translationArgs)
|
||||
{
|
||||
boolean flag = true;
|
||||
MinecraftServer minecraftserver = this.server;
|
||||
|
||||
if (!sender.sendCommandFeedback())
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
|
||||
ITextComponent itextcomponent = new TextComponentTranslation("chat.type.admin", new Object[] {sender.getName(), new TextComponentTranslation(translationKey, translationArgs)});
|
||||
itextcomponent.getStyle().setColor(TextFormatting.GRAY);
|
||||
itextcomponent.getStyle().setItalic(Boolean.valueOf(true));
|
||||
|
||||
if (flag)
|
||||
{
|
||||
for (EntityPlayer entityplayer : minecraftserver.getPlayerList().getPlayers())
|
||||
{
|
||||
if (entityplayer != sender && minecraftserver.getPlayerList().canSendCommands(entityplayer.getGameProfile()) && command.checkPermission(this.server, sender))
|
||||
{
|
||||
boolean flag1 = sender instanceof MinecraftServer && this.server.shouldBroadcastConsoleToOps();
|
||||
boolean flag2 = sender instanceof RConConsoleSource && this.server.shouldBroadcastRconToOps();
|
||||
|
||||
if (flag1 || flag2 || !(sender instanceof RConConsoleSource) && !(sender instanceof MinecraftServer))
|
||||
{
|
||||
entityplayer.sendMessage(itextcomponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sender != minecraftserver && minecraftserver.worlds[0].getGameRules().getBoolean("logAdminCommands"))
|
||||
{
|
||||
minecraftserver.sendMessage(itextcomponent);
|
||||
}
|
||||
|
||||
boolean flag3 = minecraftserver.worlds[0].getGameRules().getBoolean("sendCommandFeedback");
|
||||
|
||||
if (sender instanceof CommandBlockBaseLogic)
|
||||
{
|
||||
flag3 = ((CommandBlockBaseLogic)sender).shouldTrackOutput();
|
||||
}
|
||||
|
||||
if ((flags & 1) != 1 && flag3 || sender instanceof MinecraftServer)
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation(translationKey, translationArgs));
|
||||
}
|
||||
}
|
||||
|
||||
protected MinecraftServer getServer()
|
||||
{
|
||||
return this.server;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class SyntaxErrorException extends CommandException
|
||||
{
|
||||
public SyntaxErrorException()
|
||||
{
|
||||
this("commands.generic.snytax");
|
||||
}
|
||||
|
||||
public SyntaxErrorException(String message, Object... replacements)
|
||||
{
|
||||
super(message, replacements);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.minecraft.command;
|
||||
|
||||
public class WrongUsageException extends SyntaxErrorException
|
||||
{
|
||||
public WrongUsageException(String message, Object... replacements)
|
||||
{
|
||||
super(message, replacements);
|
||||
}
|
||||
|
||||
public synchronized Throwable fillInStackTrace()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.command;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.PlayerNotFoundException;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.UserListIPBansEntry;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandBanIp extends CommandBase
|
||||
{
|
||||
/** A regex that matches ip addresses */
|
||||
public static final Pattern IP_PATTERN = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "ban-ip";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return server.getPlayerList().getBannedIPs().isLanServer() && super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.banip.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length >= 1 && args[0].length() > 1)
|
||||
{
|
||||
ITextComponent itextcomponent = args.length >= 2 ? getChatComponentFromNthArg(sender, args, 1) : null;
|
||||
Matcher matcher = IP_PATTERN.matcher(args[0]);
|
||||
|
||||
if (matcher.matches())
|
||||
{
|
||||
this.banIp(server, sender, args[0], itextcomponent == null ? null : itextcomponent.getUnformattedText());
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayerMP entityplayermp = server.getPlayerList().getPlayerByUsername(args[0]);
|
||||
|
||||
if (entityplayermp == null)
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.banip.invalid");
|
||||
}
|
||||
|
||||
this.banIp(server, sender, entityplayermp.getPlayerIP(), itextcomponent == null ? null : itextcomponent.getUnformattedText());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.banip.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
|
||||
protected void banIp(MinecraftServer server, ICommandSender sender, String ipAddress, @Nullable String banReason)
|
||||
{
|
||||
UserListIPBansEntry userlistipbansentry = new UserListIPBansEntry(ipAddress, (Date)null, sender.getName(), (Date)null, banReason);
|
||||
server.getPlayerList().getBannedIPs().addEntry(userlistipbansentry);
|
||||
List<EntityPlayerMP> list = server.getPlayerList().getPlayersMatchingAddress(ipAddress);
|
||||
String[] astring = new String[list.size()];
|
||||
int i = 0;
|
||||
|
||||
for (EntityPlayerMP entityplayermp : list)
|
||||
{
|
||||
entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.ip_banned", new Object[0]));
|
||||
astring[i++] = entityplayermp.getName();
|
||||
}
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.banip.success", new Object[] {ipAddress});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.banip.success.players", new Object[] {ipAddress, joinNiceString(astring)});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.UserListBansEntry;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandBanPlayer extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "ban";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.ban.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return server.getPlayerList().getBannedPlayers().isLanServer() && super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length >= 1 && args[0].length() > 0)
|
||||
{
|
||||
GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
|
||||
|
||||
if (gameprofile == null)
|
||||
{
|
||||
throw new CommandException("commands.ban.failed", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = null;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
s = getChatComponentFromNthArg(sender, args, 1).getUnformattedText();
|
||||
}
|
||||
|
||||
UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, sender.getName(), (Date)null, s);
|
||||
server.getPlayerList().getBannedPlayers().addEntry(userlistbansentry);
|
||||
EntityPlayerMP entityplayermp = server.getPlayerList().getPlayerByUsername(args[0]);
|
||||
|
||||
if (entityplayermp != null)
|
||||
{
|
||||
entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.banned", new Object[0]));
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.ban.success", new Object[] {args[0]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.ban.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length >= 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandBroadcast extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "say";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.say.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length > 0 && args[0].length() > 0)
|
||||
{
|
||||
ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 0, true);
|
||||
server.getPlayerList().sendMessage(new TextComponentTranslation("chat.type.announcement", new Object[] {sender.getDisplayName(), itextcomponent}));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.say.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length >= 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandDeOp extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "deop";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.deop.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length == 1 && args[0].length() > 0)
|
||||
{
|
||||
GameProfile gameprofile = server.getPlayerList().getOppedPlayers().getGameProfileFromName(args[0]);
|
||||
|
||||
if (gameprofile == null)
|
||||
{
|
||||
throw new CommandException("commands.deop.failed", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
server.getPlayerList().removeOp(gameprofile);
|
||||
notifyCommandListener(sender, this, "commands.deop.success", new Object[] {args[0]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.deop.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getPlayerList().getOppedPlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandEmote extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "me";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.me.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length <= 0)
|
||||
{
|
||||
throw new WrongUsageException("commands.me.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 0, !(sender instanceof EntityPlayer));
|
||||
server.getPlayerList().sendMessage(new TextComponentTranslation("chat.type.emote", new Object[] {sender.getDisplayName(), itextcomponent}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandListBans extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "banlist";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return (server.getPlayerList().getBannedIPs().isLanServer() || server.getPlayerList().getBannedPlayers().isLanServer()) && super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.banlist.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length >= 1 && "ips".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.banlist.ips", new Object[] {server.getPlayerList().getBannedIPs().getKeys().length}));
|
||||
sender.sendMessage(new TextComponentString(joinNiceString(server.getPlayerList().getBannedIPs().getKeys())));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.banlist.players", new Object[] {server.getPlayerList().getBannedPlayers().getKeys().length}));
|
||||
sender.sendMessage(new TextComponentString(joinNiceString(server.getPlayerList().getBannedPlayers().getKeys())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"players", "ips"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandResultStats;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandListPlayers extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "list";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.players.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
int i = server.getCurrentPlayerCount();
|
||||
sender.sendMessage(new TextComponentTranslation("commands.players.list", new Object[] {i, server.getMaxPlayers()}));
|
||||
sender.sendMessage(new TextComponentString(server.getPlayerList().getFormattedListOfPlayers(args.length > 0 && "uuids".equalsIgnoreCase(args[0]))));
|
||||
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.PlayerNotFoundException;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
public class CommandMessage extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Get a list of aliases for this command. <b>Never return null!</b>
|
||||
*/
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Arrays.<String>asList("w", "msg");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "tell";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.message.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.message.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
|
||||
|
||||
if (entityplayer == sender)
|
||||
{
|
||||
throw new PlayerNotFoundException("commands.message.sameTarget");
|
||||
}
|
||||
else
|
||||
{
|
||||
ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 1, !(sender instanceof EntityPlayer));
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.message.display.incoming", new Object[] {sender.getDisplayName(), itextcomponent.createCopy()});
|
||||
TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation("commands.message.display.outgoing", new Object[] {entityplayer.getDisplayName(), itextcomponent.createCopy()});
|
||||
textcomponenttranslation.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
|
||||
textcomponenttranslation1.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
|
||||
entityplayer.sendMessage(textcomponenttranslation);
|
||||
sender.sendMessage(textcomponenttranslation1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentUtils;
|
||||
|
||||
public class CommandMessageRaw extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "tellraw";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.tellraw.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
|
||||
String s = buildString(args, 1);
|
||||
|
||||
try
|
||||
{
|
||||
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
|
||||
entityplayer.sendMessage(TextComponentUtils.processComponent(sender, itextcomponent, entityplayer));
|
||||
}
|
||||
catch (JsonParseException jsonparseexception)
|
||||
{
|
||||
/**
|
||||
* Convert a JsonParseException into a user-friendly exception
|
||||
*/
|
||||
throw toSyntaxException(jsonparseexception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandOp extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "op";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.op.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length == 1 && args[0].length() > 0)
|
||||
{
|
||||
GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
|
||||
|
||||
if (gameprofile == null)
|
||||
{
|
||||
throw new CommandException("commands.op.failed", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
server.getPlayerList().addOp(gameprofile);
|
||||
notifyCommandListener(sender, this, "commands.op.success", new Object[] {args[0]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.op.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
String s = args[args.length - 1];
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
|
||||
for (GameProfile gameprofile : server.getOnlinePlayerProfiles())
|
||||
{
|
||||
if (!server.getPlayerList().canSendCommands(gameprofile) && doesStringStartWith(s, gameprofile.getName()))
|
||||
{
|
||||
list.add(gameprofile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.SyntaxErrorException;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandPardonIp extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "pardon-ip";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return server.getPlayerList().getBannedIPs().isLanServer() && super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.unbanip.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length == 1 && args[0].length() > 1)
|
||||
{
|
||||
Matcher matcher = CommandBanIp.IP_PATTERN.matcher(args[0]);
|
||||
|
||||
if (matcher.matches())
|
||||
{
|
||||
server.getPlayerList().getBannedIPs().removeEntry(args[0]);
|
||||
notifyCommandListener(sender, this, "commands.unbanip.success", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SyntaxErrorException("commands.unbanip.invalid", new Object[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.unbanip.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getPlayerList().getBannedIPs().getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandPardonPlayer extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "pardon";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.unban.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given ICommandSender has permission to execute this command
|
||||
*/
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return server.getPlayerList().getBannedPlayers().isLanServer() && super.checkPermission(server, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length == 1 && args[0].length() > 0)
|
||||
{
|
||||
GameProfile gameprofile = server.getPlayerList().getBannedPlayers().getBannedProfile(args[0]);
|
||||
|
||||
if (gameprofile == null)
|
||||
{
|
||||
throw new CommandException("commands.unban.failed", new Object[] {args[0]});
|
||||
}
|
||||
else
|
||||
{
|
||||
server.getPlayerList().getBannedPlayers().removeEntry(gameprofile);
|
||||
notifyCommandListener(sender, this, "commands.unban.success", new Object[] {args[0]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException("commands.unban.usage", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getPlayerList().getBannedPlayers().getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.GameType;
|
||||
|
||||
public class CommandPublishLocalServer extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "publish";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.publish.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
String s = server.shareToLAN(GameType.SURVIVAL, false);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.publish.started", new Object[] {s});
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.publish.failed", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.IProgressUpdate;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.MinecraftException;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class CommandSaveAll extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "save-all";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.save.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.save.start", new Object[0]));
|
||||
|
||||
if (server.getPlayerList() != null)
|
||||
{
|
||||
server.getPlayerList().saveAllPlayerData();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < server.worlds.length; ++i)
|
||||
{
|
||||
if (server.worlds[i] != null)
|
||||
{
|
||||
WorldServer worldserver = server.worlds[i];
|
||||
boolean flag = worldserver.disableLevelSaving;
|
||||
worldserver.disableLevelSaving = false;
|
||||
worldserver.saveAllChunks(true, (IProgressUpdate)null);
|
||||
worldserver.disableLevelSaving = flag;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length > 0 && "flush".equals(args[0]))
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.save.flushStart", new Object[0]));
|
||||
|
||||
for (int j = 0; j < server.worlds.length; ++j)
|
||||
{
|
||||
if (server.worlds[j] != null)
|
||||
{
|
||||
WorldServer worldserver1 = server.worlds[j];
|
||||
boolean flag1 = worldserver1.disableLevelSaving;
|
||||
worldserver1.disableLevelSaving = false;
|
||||
worldserver1.flushToDisk();
|
||||
worldserver1.disableLevelSaving = flag1;
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(new TextComponentTranslation("commands.save.flushEnd", new Object[0]));
|
||||
}
|
||||
}
|
||||
catch (MinecraftException minecraftexception)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.save.failed", new Object[] {minecraftexception.getMessage()});
|
||||
return;
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.save.success", new Object[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"flush"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class CommandSaveOff extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "save-off";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.save-off.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
for (int i = 0; i < server.worlds.length; ++i)
|
||||
{
|
||||
if (server.worlds[i] != null)
|
||||
{
|
||||
WorldServer worldserver = server.worlds[i];
|
||||
|
||||
if (!worldserver.disableLevelSaving)
|
||||
{
|
||||
worldserver.disableLevelSaving = true;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.save.disabled", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.save-off.alreadyOff", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class CommandSaveOn extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "save-on";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.save-on.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
for (int i = 0; i < server.worlds.length; ++i)
|
||||
{
|
||||
if (server.worlds[i] != null)
|
||||
{
|
||||
WorldServer worldserver = server.worlds[i];
|
||||
|
||||
if (worldserver.disableLevelSaving)
|
||||
{
|
||||
worldserver.disableLevelSaving = false;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.save.enabled", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.save-on.alreadyOn", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,170 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandResultStats;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandSetBlock extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "setblock";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.setblock.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.setblock.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
Block block = CommandBase.getBlockByText(sender, args[3]);
|
||||
IBlockState iblockstate;
|
||||
|
||||
if (args.length >= 5)
|
||||
{
|
||||
iblockstate = convertArgToBlockState(block, args[4]);
|
||||
}
|
||||
else
|
||||
{
|
||||
iblockstate = block.getDefaultState();
|
||||
}
|
||||
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (!world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.setblock.outOfWorld", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
boolean flag = false;
|
||||
|
||||
if (args.length >= 7 && block.hasTileEntity(iblockstate))
|
||||
{
|
||||
String s = buildString(args, 6);
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(s);
|
||||
flag = true;
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.setblock.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 6)
|
||||
{
|
||||
if ("destroy".equals(args[5]))
|
||||
{
|
||||
world.destroyBlock(blockpos, true);
|
||||
|
||||
if (block == Blocks.AIR)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.setblock.success", new Object[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ("keep".equals(args[5]) && !world.isAirBlock(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.setblock.noChange", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity tileentity1 = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity1 != null && tileentity1 instanceof IInventory)
|
||||
{
|
||||
((IInventory)tileentity1).clear();
|
||||
}
|
||||
|
||||
if (!world.setBlockState(blockpos, iblockstate, 2))
|
||||
{
|
||||
throw new CommandException("commands.setblock.noChange", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
nbttagcompound.setInteger("x", blockpos.getX());
|
||||
nbttagcompound.setInteger("y", blockpos.getY());
|
||||
nbttagcompound.setInteger("z", blockpos.getZ());
|
||||
tileentity.readFromNBT(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
world.notifyNeighborsRespectDebug(blockpos, iblockstate.getBlock(), false);
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
|
||||
notifyCommandListener(sender, this, "commands.setblock.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length > 0 && args.length <= 3)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 0, targetPos);
|
||||
}
|
||||
else if (args.length == 4)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 6 ? getListOfStringsMatchingLastWord(args, new String[] {"replace", "destroy", "keep"}) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.network.play.server.SPacketSpawnPosition;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandSetDefaultSpawnpoint extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "setworldspawn";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.setworldspawn.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
BlockPos blockpos;
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
blockpos = getCommandSenderAsPlayer(sender).getPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length != 3 || sender.getEntityWorld() == null)
|
||||
{
|
||||
throw new WrongUsageException("commands.setworldspawn.usage", new Object[0]);
|
||||
}
|
||||
|
||||
blockpos = parseBlockPos(sender, args, 0, true);
|
||||
}
|
||||
|
||||
sender.getEntityWorld().setSpawnPoint(blockpos);
|
||||
server.getPlayerList().sendPacketToAllPlayers(new SPacketSpawnPosition(blockpos));
|
||||
notifyCommandListener(sender, this, "commands.setworldspawn.success", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length > 0 && args.length <= 3 ? getTabCompletionCoordinate(args, 0, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class CommandStop extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "stop";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.stop.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (server.worlds != null)
|
||||
{
|
||||
notifyCommandListener(sender, this, "commands.stop.start", new Object[0]);
|
||||
}
|
||||
|
||||
server.initiateShutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.IEntityLivingData;
|
||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
||||
|
||||
public class CommandSummon extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "summon";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.summon.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.summon.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = args[0];
|
||||
BlockPos blockpos = sender.getPosition();
|
||||
Vec3d vec3d = sender.getPositionVector();
|
||||
double d0 = vec3d.x;
|
||||
double d1 = vec3d.y;
|
||||
double d2 = vec3d.z;
|
||||
|
||||
if (args.length >= 4)
|
||||
{
|
||||
d0 = parseDouble(d0, args[1], true);
|
||||
d1 = parseDouble(d1, args[2], false);
|
||||
d2 = parseDouble(d2, args[3], true);
|
||||
blockpos = new BlockPos(d0, d1, d2);
|
||||
}
|
||||
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (!world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.summon.outOfWorld", new Object[0]);
|
||||
}
|
||||
else if (EntityList.LIGHTNING_BOLT.equals(new ResourceLocation(s)))
|
||||
{
|
||||
world.addWeatherEffect(new EntityLightningBolt(world, d0, d1, d2, false));
|
||||
notifyCommandListener(sender, this, "commands.summon.success", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
boolean flag = false;
|
||||
|
||||
if (args.length >= 5)
|
||||
{
|
||||
String s1 = buildString(args, 4);
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(s1);
|
||||
flag = true;
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.summon.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
nbttagcompound.setString("id", s);
|
||||
Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, true);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new CommandException("commands.summon.failed", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.setLocationAndAngles(d0, d1, d2, entity.rotationYaw, entity.rotationPitch);
|
||||
|
||||
if (!flag && entity instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null);
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.summon.success", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, EntityList.getEntityNameList());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length > 1 && args.length <= 4 ? getTabCompletionCoordinate(args, 1, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class CommandTeleport extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "teleport";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.teleport.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.teleport.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[0]);
|
||||
|
||||
if (entity.world != null)
|
||||
{
|
||||
int i = 4096;
|
||||
Vec3d vec3d = sender.getPositionVector();
|
||||
int j = 1;
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(vec3d.x, args[j++], true);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(vec3d.y, args[j++], -4096, 4096, false);
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(vec3d.z, args[j++], true);
|
||||
Entity entity1 = sender.getCommandSenderEntity() == null ? entity : sender.getCommandSenderEntity();
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate(args.length > j ? (double)entity1.rotationYaw : (double)entity.rotationYaw, args.length > j ? args[j] : "~", false);
|
||||
++j;
|
||||
CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate(args.length > j ? (double)entity1.rotationPitch : (double)entity.rotationPitch, args.length > j ? args[j] : "~", false);
|
||||
doTeleport(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
|
||||
notifyCommandListener(sender, this, "commands.teleport.success.coordinates", new Object[] {entity.getName(), commandbase$coordinatearg.getResult(), commandbase$coordinatearg1.getResult(), commandbase$coordinatearg2.getResult()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual teleport
|
||||
*
|
||||
* @param teleportingEntity the entity being teleported
|
||||
*/
|
||||
private static void doTeleport(Entity teleportingEntity, CommandBase.CoordinateArg argX, CommandBase.CoordinateArg argY, CommandBase.CoordinateArg argZ, CommandBase.CoordinateArg argYaw, CommandBase.CoordinateArg argPitch)
|
||||
{
|
||||
if (teleportingEntity instanceof EntityPlayerMP)
|
||||
{
|
||||
Set<SPacketPlayerPosLook.EnumFlags> set = EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class);
|
||||
float f = (float)argYaw.getAmount();
|
||||
|
||||
if (argYaw.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.Y_ROT);
|
||||
}
|
||||
else
|
||||
{
|
||||
f = MathHelper.wrapDegrees(f);
|
||||
}
|
||||
|
||||
float f1 = (float)argPitch.getAmount();
|
||||
|
||||
if (argPitch.isRelative())
|
||||
{
|
||||
set.add(SPacketPlayerPosLook.EnumFlags.X_ROT);
|
||||
}
|
||||
else
|
||||
{
|
||||
f1 = MathHelper.wrapDegrees(f1);
|
||||
}
|
||||
|
||||
teleportingEntity.dismountRidingEntity();
|
||||
((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getResult(), argY.getResult(), argZ.getResult(), f, f1, set);
|
||||
teleportingEntity.setRotationYawHead(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float f2 = (float)MathHelper.wrapDegrees(argYaw.getResult());
|
||||
float f3 = (float)MathHelper.wrapDegrees(argPitch.getResult());
|
||||
f3 = MathHelper.clamp(f3, -90.0F, 90.0F);
|
||||
teleportingEntity.setLocationAndAngles(argX.getResult(), argY.getResult(), argZ.getResult(), f2, f3);
|
||||
teleportingEntity.setRotationYawHead(f2);
|
||||
}
|
||||
|
||||
if (!(teleportingEntity instanceof EntityLivingBase) || !((EntityLivingBase)teleportingEntity).isElytraFlying())
|
||||
{
|
||||
teleportingEntity.motionY = 0.0D;
|
||||
teleportingEntity.onGround = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length > 1 && args.length <= 4 ? getTabCompletionCoordinate(args, 1, targetPos) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class CommandTestFor extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "testfor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.testfor.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.testfor.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = getEntity(server, sender, args[0]);
|
||||
NBTTagCompound nbttagcompound = null;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = entityToNBT(entity);
|
||||
|
||||
if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
|
||||
{
|
||||
throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified command parameter index is a username parameter.
|
||||
*/
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
return index == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
return args.length == 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandResultStats;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.NumberInvalidException;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandTestForBlock extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "testforblock";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.testforblock.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
throw new WrongUsageException("commands.testforblock.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
||||
Block block = getBlockByText(sender, args[3]);
|
||||
|
||||
if (block == null)
|
||||
{
|
||||
throw new NumberInvalidException("commands.setblock.notFound", new Object[] {args[3]});
|
||||
}
|
||||
else
|
||||
{
|
||||
World world = sender.getEntityWorld();
|
||||
|
||||
if (!world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.testforblock.outOfWorld", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
boolean flag = false;
|
||||
|
||||
if (args.length >= 6 && block.hasTileEntity())
|
||||
{
|
||||
String s = buildString(args, 5);
|
||||
|
||||
try
|
||||
{
|
||||
nbttagcompound = JsonToNBT.getTagFromJson(s);
|
||||
flag = true;
|
||||
}
|
||||
catch (NBTException nbtexception)
|
||||
{
|
||||
throw new CommandException("commands.setblock.tagError", new Object[] {nbtexception.getMessage()});
|
||||
}
|
||||
}
|
||||
|
||||
IBlockState iblockstate = world.getBlockState(blockpos);
|
||||
Block block1 = iblockstate.getBlock();
|
||||
|
||||
if (block1 != block)
|
||||
{
|
||||
throw new CommandException("commands.testforblock.failed.tile", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ(), block1.getLocalizedName(), block.getLocalizedName()});
|
||||
}
|
||||
else if (args.length >= 5 && !CommandBase.convertArgToBlockStatePredicate(block, args[4]).apply(iblockstate))
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = iblockstate.getBlock().getMetaFromState(iblockstate);
|
||||
throw new CommandException("commands.testforblock.failed.data", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ(), i, Integer.parseInt(args[4])});
|
||||
}
|
||||
catch (NumberFormatException var13)
|
||||
{
|
||||
throw new CommandException("commands.testforblock.failed.data", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ(), iblockstate.toString(), args[4]});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity == null)
|
||||
{
|
||||
throw new CommandException("commands.testforblock.failed.tileEntity", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = tileentity.writeToNBT(new NBTTagCompound());
|
||||
|
||||
if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
|
||||
{
|
||||
throw new CommandException("commands.testforblock.failed.nbt", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
}
|
||||
|
||||
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
|
||||
notifyCommandListener(sender, this, "commands.testforblock.success", new Object[] {blockpos.getX(), blockpos.getY(), blockpos.getZ()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length > 0 && args.length <= 3)
|
||||
{
|
||||
return getTabCompletionCoordinate(args, 0, targetPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return args.length == 4 ? getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
public class CommandWhitelist extends CommandBase
|
||||
{
|
||||
/**
|
||||
* Gets the name of the command
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return "whitelist";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required permission level for this command.
|
||||
*/
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usage string for the command.
|
||||
*/
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.whitelist.usage";
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the command is executed
|
||||
*/
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new WrongUsageException("commands.whitelist.usage", new Object[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("on".equals(args[0]))
|
||||
{
|
||||
server.getPlayerList().setWhiteListEnabled(true);
|
||||
notifyCommandListener(sender, this, "commands.whitelist.enabled", new Object[0]);
|
||||
}
|
||||
else if ("off".equals(args[0]))
|
||||
{
|
||||
server.getPlayerList().setWhiteListEnabled(false);
|
||||
notifyCommandListener(sender, this, "commands.whitelist.disabled", new Object[0]);
|
||||
}
|
||||
else if ("list".equals(args[0]))
|
||||
{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.whitelist.list", new Object[] {server.getPlayerList().getWhitelistedPlayerNames().length, server.getPlayerList().getAvailablePlayerDat().length}));
|
||||
String[] astring = server.getPlayerList().getWhitelistedPlayerNames();
|
||||
sender.sendMessage(new TextComponentString(joinNiceString(astring)));
|
||||
}
|
||||
else if ("add".equals(args[0]))
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.whitelist.add.usage", new Object[0]);
|
||||
}
|
||||
|
||||
GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(args[1]);
|
||||
|
||||
if (gameprofile == null)
|
||||
{
|
||||
throw new CommandException("commands.whitelist.add.failed", new Object[] {args[1]});
|
||||
}
|
||||
|
||||
server.getPlayerList().addWhitelistedPlayer(gameprofile);
|
||||
notifyCommandListener(sender, this, "commands.whitelist.add.success", new Object[] {args[1]});
|
||||
}
|
||||
else if ("remove".equals(args[0]))
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException("commands.whitelist.remove.usage", new Object[0]);
|
||||
}
|
||||
|
||||
GameProfile gameprofile1 = server.getPlayerList().getWhitelistedPlayers().getByName(args[1]);
|
||||
|
||||
if (gameprofile1 == null)
|
||||
{
|
||||
throw new CommandException("commands.whitelist.remove.failed", new Object[] {args[1]});
|
||||
}
|
||||
|
||||
server.getPlayerList().removePlayerFromWhitelist(gameprofile1);
|
||||
notifyCommandListener(sender, this, "commands.whitelist.remove.success", new Object[] {args[1]});
|
||||
}
|
||||
else if ("reload".equals(args[0]))
|
||||
{
|
||||
server.getPlayerList().reloadWhitelist();
|
||||
notifyCommandListener(sender, this, "commands.whitelist.reloaded", new Object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of options for when the user presses the TAB key
|
||||
*/
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, new String[] {"on", "off", "list", "add", "remove", "reload"});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
if ("remove".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getPlayerList().getWhitelistedPlayerNames());
|
||||
}
|
||||
|
||||
if ("add".equals(args[0]))
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, server.getPlayerProfileCache().getUsernames());
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.command.server;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in New Issue
Block a user