base mod created
This commit is contained in:
@@ -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