mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-04-01 08:45:28 +02:00
86 lines
2.8 KiB
Java
86 lines
2.8 KiB
Java
package com.minelittlepony.unicopia.command;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
|
|
|
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.TextComponentTranslation;
|
|
|
|
class CommandGravity extends CommandBase {
|
|
|
|
public String getName() {
|
|
return "gravity";
|
|
}
|
|
|
|
public int getRequiredPermissionLevel() {
|
|
return 4;
|
|
}
|
|
|
|
public String getUsage(ICommandSender sender) {
|
|
return "commands.gravity.usage";
|
|
}
|
|
|
|
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
|
if (args.length < 2) {
|
|
throw new WrongUsageException(getUsage(sender));
|
|
}
|
|
|
|
EntityPlayer player = getCommandSenderAsPlayer(sender);
|
|
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);
|
|
|
|
|
|
|
|
if (args[0].contentEquals("get")) {
|
|
String translationKey = "commands.gravity.get";
|
|
|
|
float gravity = iplayer.getGravity().getGravitationConstant();
|
|
|
|
if (sender == player) {
|
|
player.sendMessage(new TextComponentTranslation(translationKey, gravity));
|
|
}
|
|
|
|
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity);
|
|
|
|
} else if (args[0].contentEquals("set") || args.length > 2) {
|
|
String translationKey = "commands.gravity.set";
|
|
|
|
float gravity = Float.valueOf(args[2]);
|
|
|
|
iplayer.getGravity().setGraviationConstant(gravity);
|
|
iplayer.sendCapabilities(true);
|
|
|
|
if (sender == player) {
|
|
player.sendMessage(new TextComponentTranslation(translationKey, gravity));
|
|
}
|
|
|
|
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity);
|
|
} else {
|
|
throw new WrongUsageException(getUsage(sender));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Adds the strings available in this command to the given list of tab completion options.
|
|
*/
|
|
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
|
|
if (args.length == 1) {
|
|
return getListOfStringsMatchingLastWord(args, "get", "set");
|
|
}
|
|
|
|
if (args.length == 2) {
|
|
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|