use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandPlanetTeleport method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
if (args.length < 2) {
try {
if (args.length == 1) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
} else {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
}
if (playerBase != null) {
WorldServer worldserver = server.getWorld(GCCoreUtil.getDimensionID(server.worlds[0]));
BlockPos spawnPoint = worldserver.getSpawnPoint();
GCPlayerStats stats = GCPlayerStats.get(playerBase);
stats.setRocketStacks(NonNullList.withSize(2, ItemStack.EMPTY));
stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
stats.setRocketItem(GCItems.rocketTier1);
stats.setFuelLevel(1000);
stats.setCoordsTeleportedFromX(spawnPoint.getX());
stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
try {
WorldUtil.toCelestialSelection(playerBase, stats, Integer.MAX_VALUE);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CommandBase.notifyCommandListener(sender, this, "commands.dimensionteleport", new Object[] { String.valueOf(EnumColor.GREY + "[" + playerBase.getName()), "]" });
} else {
throw new Exception("Could not find player with name: " + args[0]);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandGCHouston method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
boolean isOp = this.isOp(server, sender);
if (args.length < 2) {
try {
if (args.length == 0) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (!playerBase.capabilities.isCreativeMode) {
if (ConfigManagerCore.challengeMode || !(playerBase.world.provider instanceof IGalacticraftWorldProvider)) {
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.fail");
return;
}
}
if (timerList.contains(playerBase)) {
timerList.remove(playerBase);
} else {
timerList.add(playerBase);
TickHandlerServer.timerHoustonCommand = 250;
String msg = EnumColor.YELLOW + GCCoreUtil.translate("commands.gchouston.confirm.1") + " " + EnumColor.WHITE + GCCoreUtil.translate("commands.gchouston.confirm.2");
CommandBase.notifyCommandListener(sender, this, msg);
return;
}
} else {
if (!isOp) {
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.noop");
return;
}
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
}
if (playerBase != null) {
int dimID = ConfigManagerCore.idDimensionOverworld;
WorldServer worldserver = server.getWorld(dimID);
if (worldserver == null) {
worldserver = server.getWorld(0);
if (worldserver == null) {
throw new Exception("/gchouston could not find Overworld.");
}
dimID = 0;
}
BlockPos spawnPoint = null;
BlockPos bedPos = playerBase.getBedLocation(dimID);
if (bedPos != null) {
spawnPoint = EntityPlayer.getBedSpawnLocation(worldserver, bedPos, false);
}
if (spawnPoint == null) {
spawnPoint = worldserver.getTopSolidOrLiquidBlock(worldserver.getSpawnPoint());
}
GCPlayerStats stats = GCPlayerStats.get(playerBase);
stats.setRocketStacks(NonNullList.withSize(0, ItemStack.EMPTY));
stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
stats.setRocketItem(null);
stats.setFuelLevel(0);
stats.setCoordsTeleportedFromX(spawnPoint.getX());
stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
stats.setUsingPlanetSelectionGui(false);
playerBase.closeScreen();
Vector3 spawnPos = new Vector3(spawnPoint.getX() + 0.5D, spawnPoint.getY() + 0.25D, spawnPoint.getZ() + 0.5D);
try {
WorldUtil.teleportEntitySimple(worldserver, dimID, playerBase, spawnPos);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
CommandBase.notifyCommandListener(sender, this, "commands.gchouston.success", new Object[] { String.valueOf(EnumColor.GREY + "" + playerBase.getName()) });
} else {
throw new Exception("Could not find player with name: " + args[0]);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandGCKit method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
if (args.length < 2) {
try {
if (args.length == 1) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
} else {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
}
if (playerBase != null) {
ItemHandlerHelper.giveItemToPlayer(playerBase, new ItemStack(GCItems.emergencyKit), 0);
CommandBase.notifyCommandListener(sender, this, "commands.emergencykit", new Object[] { String.valueOf(EnumColor.GREY + "[" + playerBase.getName()), "]" });
} else {
throw new Exception("Could not find player with name: " + args[0]);
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getUsage(sender)), new Object[0]);
}
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandSpaceStationAddOwner method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
String var3 = null;
EntityPlayerMP playerBase = null;
if (args.length > 0) {
var3 = args[0];
try {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (playerBase != null) {
GCPlayerStats stats = GCPlayerStats.get(playerBase);
if (stats.getSpaceStationDimensionData().isEmpty()) {
throw new WrongUsageException(GCCoreUtil.translate("commands.ssinvite.not_found"), new Object[0]);
} else {
for (Map.Entry<Integer, Integer> ownedStations : stats.getSpaceStationDimensionData().entrySet()) {
final SpaceStationWorldData data = SpaceStationWorldData.getStationData(playerBase.world, ownedStations.getValue(), playerBase);
if (var3.equalsIgnoreCase("+all")) {
data.setAllowedAll(true);
playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_true")));
return;
}
if (var3.equalsIgnoreCase("-all")) {
data.setAllowedAll(false);
playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.allow_all_false", var3)));
return;
}
if (!data.getAllowedPlayers().contains(var3)) {
data.getAllowedPlayers().add(var3);
data.markDirty();
}
}
}
final EntityPlayerMP playerToAdd = PlayerUtil.getPlayerBaseServerFromPlayerUsername(var3, true);
if (playerToAdd != null) {
playerToAdd.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.added", PlayerUtil.getName(playerBase))));
}
}
} catch (final Exception var6) {
throw new CommandException(var6.getMessage(), new Object[0]);
}
} else {
throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.ssinvite.wrong_usage", this.getUsage(sender)), new Object[0]);
}
if (playerBase != null) {
playerBase.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.spacestation.addsuccess", var3)));
}
}
use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.
the class QuestCommandEdit method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
boolean flag = !QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
if (args.length == 2) {
try {
if (args[1].equalsIgnoreCase("on")) {
flag = true;
} else if (args[1].equalsIgnoreCase("off")) {
flag = false;
} else {
flag = Boolean.parseBoolean(args[1]);
}
} catch (Exception e) {
throw this.getException(command);
}
}
QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, flag);
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.edit", new TextComponentTranslation(QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) ? "options.on" : "options.off")));
SaveLoadHandler.INSTANCE.markDirty();
NetSettingSync.sendSync(null);
}
Aggregations