2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2013-09-30 20:08:57 +00:00
|
|
|
package net.minecraftforge.client;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiChat;
|
|
|
|
import net.minecraft.command.CommandException;
|
|
|
|
import net.minecraft.command.CommandHandler;
|
|
|
|
import net.minecraft.command.ICommand;
|
|
|
|
import net.minecraft.command.ICommandSender;
|
|
|
|
import net.minecraft.command.WrongUsageException;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2013-09-30 20:08:57 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.CommandEvent;
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2017-06-28 05:56:54 +00:00
|
|
|
import net.minecraftforge.fml.common.FMLLog;
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
import static net.minecraft.util.text.TextFormatting.*;
|
2013-09-30 20:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The class that handles client-side chat commands. You should register any
|
|
|
|
* commands that you want handled on the client with this command handler.
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
*
|
2013-09-30 20:08:57 +00:00
|
|
|
* If there is a command with the same name registered both on the server and
|
|
|
|
* client, the client takes precedence!
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
*
|
2013-09-30 20:08:57 +00:00
|
|
|
*/
|
2018-08-27 17:10:07 +00:00
|
|
|
public class ClientCommandHandler {} /*extends CommandHandler
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
public static final ClientCommandHandler instance = new ClientCommandHandler();
|
|
|
|
|
|
|
|
public String[] latestAutoComplete = null;
|
|
|
|
|
|
|
|
/**
|
2014-09-16 23:48:44 +00:00
|
|
|
* @return 1 if successfully executed, -1 if no permission or wrong usage,
|
|
|
|
* 0 if it doesn't exist or it was canceled (it's sent to the server)
|
2018-08-27 17:10:07 +00:00
|
|
|
* /
|
2013-09-30 20:08:57 +00:00
|
|
|
@Override
|
|
|
|
public int executeCommand(ICommandSender sender, String message)
|
|
|
|
{
|
|
|
|
message = message.trim();
|
|
|
|
|
2017-05-02 00:22:53 +00:00
|
|
|
boolean usedSlash = message.startsWith("/");
|
|
|
|
if (usedSlash)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
message = message.substring(1);
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:16:04 +00:00
|
|
|
String[] temp = message.split(" ");
|
|
|
|
String[] args = new String[temp.length - 1];
|
|
|
|
String commandName = temp[0];
|
|
|
|
System.arraycopy(temp, 1, args, 0, args.length);
|
2016-03-23 14:34:48 +00:00
|
|
|
ICommand icommand = getCommands().get(commandName);
|
2013-09-30 20:08:57 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-05-02 00:22:53 +00:00
|
|
|
if (icommand == null || (!usedSlash && icommand instanceof IClientCommand && !((IClientCommand)icommand).allowUsageWithoutPrefix(sender, message)))
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-13 01:40:03 +00:00
|
|
|
if (icommand.checkPermission(this.getServer(), sender))
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
CommandEvent event = new CommandEvent(icommand, sender, args);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
if (event.getException() != null)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
throw event.getException();
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
this.tryExecute(sender, args, icommand, message);
|
2013-09-30 20:08:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
sender.sendMessage(format(RED, "commands.generic.permission"));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (WrongUsageException wue)
|
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
sender.sendMessage(format(RED, "commands.generic.usage", format(RED, wue.getMessage(), wue.getErrorObjects())));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
catch (CommandException ce)
|
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
sender.sendMessage(format(RED, ce.getMessage(), ce.getErrorObjects()));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
sender.sendMessage(format(RED, "commands.generic.exception"));
|
2017-06-28 05:56:54 +00:00
|
|
|
FMLLog.log.error("Command '{}' threw an exception:", message, t);
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 23:48:44 +00:00
|
|
|
return -1;
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Couple of helpers because the mcp names are stupid and long...
|
2016-03-01 12:58:03 +00:00
|
|
|
private TextComponentTranslation format(TextFormatting color, String str, Object... args)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
2016-03-01 12:58:03 +00:00
|
|
|
TextComponentTranslation ret = new TextComponentTranslation(str, args);
|
2016-05-18 12:11:56 +00:00
|
|
|
ret.getStyle().setColor(color);
|
2013-12-10 05:59:12 +00:00
|
|
|
return ret;
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 07:34:40 +00:00
|
|
|
public void autoComplete(String leftOfCursor)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
latestAutoComplete = null;
|
|
|
|
|
|
|
|
if (leftOfCursor.charAt(0) == '/')
|
|
|
|
{
|
|
|
|
leftOfCursor = leftOfCursor.substring(1);
|
|
|
|
|
|
|
|
Minecraft mc = FMLClientHandler.instance().getClient();
|
|
|
|
if (mc.currentScreen instanceof GuiChat)
|
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
List<String> commands = getTabCompletions(mc.player, leftOfCursor, mc.player.getPosition());
|
2017-01-11 23:17:56 +00:00
|
|
|
if (!commands.isEmpty())
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
if (leftOfCursor.indexOf(' ') == -1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < commands.size(); i++)
|
|
|
|
{
|
|
|
|
commands.set(i, GRAY + "/" + commands.get(i) + RESET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < commands.size(); i++)
|
|
|
|
{
|
|
|
|
commands.set(i, GRAY + commands.get(i) + RESET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
latestAutoComplete = commands.toArray(new String[commands.size()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-13 01:40:03 +00:00
|
|
|
protected MinecraftServer getServer() {
|
2016-03-01 12:58:03 +00:00
|
|
|
return Minecraft.getMinecraft().getIntegratedServer();
|
|
|
|
}
|
2016-03-08 07:34:40 +00:00
|
|
|
}
|
2018-08-27 17:10:07 +00:00
|
|
|
*/
|