mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Rewrote the commands
This commit is contained in:
parent
0fd12b7ac1
commit
259819c7dc
6 changed files with 145 additions and 97 deletions
|
@ -38,6 +38,10 @@ public enum Race {
|
||||||
return this == HUMAN;
|
return this == HUMAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOp() {
|
||||||
|
return this == ALICORN;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canFly() {
|
public boolean canFly() {
|
||||||
return flight;
|
return flight;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +62,7 @@ public enum Race {
|
||||||
return String.format("unicopia.race.%s", name().toLowerCase());
|
return String.format("unicopia.race.%s", name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSameAs(String s) {
|
public boolean equals(String s) {
|
||||||
return name().equalsIgnoreCase(s)
|
return name().equalsIgnoreCase(s)
|
||||||
|| getTranslationKey().equalsIgnoreCase(s);
|
|| getTranslationKey().equalsIgnoreCase(s);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +70,7 @@ public enum Race {
|
||||||
public static Race fromName(String s, Race def) {
|
public static Race fromName(String s, Race def) {
|
||||||
if (!Strings.isNullOrEmpty(s)) {
|
if (!Strings.isNullOrEmpty(s)) {
|
||||||
for (Race i : values()) {
|
for (Race i : values()) {
|
||||||
if (i.isSameAs(s)) return i;
|
if (i.equals(s)) return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,48 +1,51 @@
|
||||||
package com.minelittlepony.unicopia.command;
|
package com.minelittlepony.unicopia.command;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.player.IPlayer;
|
||||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||||
|
|
||||||
import net.minecraft.command.CommandException;
|
import net.minecraft.command.CommandException;
|
||||||
import net.minecraft.command.CommandGameMode;
|
import net.minecraft.command.CommandGameMode;
|
||||||
import net.minecraft.command.ICommandSender;
|
import net.minecraft.command.ICommandSender;
|
||||||
import net.minecraft.command.WrongUsageException;
|
import net.minecraft.command.WrongUsageException;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.GameType;
|
import net.minecraft.world.GameType;
|
||||||
|
|
||||||
class CommandOverrideGameMode extends CommandGameMode {
|
class CommandOverrideGameMode extends CommandGameMode {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException {
|
public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException {
|
||||||
|
|
||||||
if (params.length <= 0) {
|
if (params.length <= 0) {
|
||||||
throw new WrongUsageException("commands.gamemode.usage");
|
throw new WrongUsageException("commands.gamemode.usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
GameType gametype = getGameModeFromCommand(sender, params[0]);
|
GameType gametype = getGameModeFromCommand(sender, params[0]);
|
||||||
|
|
||||||
EntityPlayerMP entityplayermp = params.length >= 2 ? getPlayer(server, sender, params[1]) : getCommandSenderAsPlayer(sender);
|
EntityPlayer player = params.length >= 2 ? getPlayer(server, sender, params[1]) : getCommandSenderAsPlayer(sender);
|
||||||
|
|
||||||
updateGameMode(entityplayermp, gametype);
|
updateGameMode(player, gametype);
|
||||||
|
|
||||||
ITextComponent chatcomponenttranslation = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
|
ITextComponent mode = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
|
||||||
|
|
||||||
if (entityplayermp != sender) {
|
if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", entityplayermp.getName(), chatcomponenttranslation);
|
player.sendMessage(new TextComponentTranslation("gameMode.changed", mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player == sender) {
|
||||||
|
notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", mode);
|
||||||
} else {
|
} else {
|
||||||
notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", chatcomponenttranslation);
|
notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", player.getName(), mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGameMode(EntityPlayerMP player, GameType m) {
|
protected void updateGameMode(EntityPlayer player, GameType m) {
|
||||||
boolean flying = player.capabilities.isFlying;
|
|
||||||
|
|
||||||
player.setGameType(m);
|
player.setGameType(m);
|
||||||
player.capabilities.isFlying = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canFly();
|
|
||||||
|
|
||||||
if (flying != player.capabilities.isFlying) {
|
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);
|
||||||
player.sendPlayerAbilities();
|
|
||||||
}
|
|
||||||
|
|
||||||
player.fallDistance = 0;
|
iplayer.setPlayerSpecies(iplayer.getPlayerSpecies());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,105 +44,142 @@ class CommandSpecies extends CommandBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||||
if (args.length < 1) {
|
if (!processCommand(server, sender, args)) {
|
||||||
throw new WrongUsageException(getUsage(sender));
|
throw new WrongUsageException(getUsage(sender));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EntityPlayerMP player;
|
protected boolean processCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||||
int playerIndex = 1;
|
|
||||||
|
|
||||||
if (args[0].contentEquals("set") || args[0].contentEquals("describe")) {
|
if (args.length < 1) {
|
||||||
playerIndex++;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > playerIndex) {
|
int playerIndex = this.getPlayerIndex(args);
|
||||||
player = getPlayer(server, sender, args[playerIndex]);
|
|
||||||
} else {
|
EntityPlayerMP player = args.length > playerIndex ? getPlayer(server, sender, args[playerIndex]) : getCommandSenderAsPlayer(sender);
|
||||||
player = getCommandSenderAsPlayer(sender);
|
|
||||||
|
if (args.length >= 2) {
|
||||||
|
switch (args[0]) {
|
||||||
|
case "set": return updateSpecies(sender, player, args);
|
||||||
|
case "describe": return describeSpecies(player, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].contentEquals("set") && args.length >= 2) {
|
switch (args[0]) {
|
||||||
Race species = Race.fromName(args[1], Race.HUMAN);
|
case "get": return printSpecies(sender, player);
|
||||||
|
case "list": return list(player);
|
||||||
|
}
|
||||||
|
|
||||||
if (species.isDefault()) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getPlayerIndex(String[] args) {
|
||||||
|
switch (args[0]) {
|
||||||
|
case "set":
|
||||||
|
case "describe": return 2;
|
||||||
|
default: return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean updateSpecies(ICommandSender sender, EntityPlayer player, String[] args) {
|
||||||
|
Race species = Race.fromName(args[1], Race.HUMAN);
|
||||||
|
|
||||||
|
if (species.isDefault()) {
|
||||||
|
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
ITextComponent message = new TextComponentTranslation("commands.race.fail", args[1].toUpperCase());
|
ITextComponent message = new TextComponentTranslation("commands.race.fail", args[1].toUpperCase());
|
||||||
message.getStyle().setColor(TextFormatting.RED);
|
message.getStyle().setColor(TextFormatting.RED);
|
||||||
|
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
} else if (PlayerSpeciesList.instance().speciesPermitted(species, player)) {
|
||||||
|
PlayerSpeciesList.instance().getPlayer(player).setPlayerSpecies(species);
|
||||||
|
|
||||||
|
ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase());
|
||||||
|
|
||||||
|
if (player != sender) {
|
||||||
|
notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName);
|
||||||
} else {
|
} else {
|
||||||
if (PlayerSpeciesList.instance().speciesPermitted(species, player)) {
|
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
PlayerSpeciesList.instance().getPlayer(player).setPlayerSpecies(species);
|
player.sendMessage(new TextComponentTranslation("commands.race.success.self"));
|
||||||
|
|
||||||
ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase());
|
|
||||||
|
|
||||||
if (player != sender) {
|
|
||||||
notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName);
|
|
||||||
} else {
|
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.success.self"));
|
|
||||||
notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.permission"));
|
|
||||||
}
|
}
|
||||||
|
notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName);
|
||||||
}
|
}
|
||||||
} else if (args[0].contentEquals("get")) {
|
} else if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
Race spec = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies();
|
player.sendMessage(new TextComponentTranslation("commands.race.permission"));
|
||||||
|
}
|
||||||
|
|
||||||
String name = "commands.race.tell.";
|
return true;
|
||||||
name += player == sender ? "self" : "other";
|
}
|
||||||
|
|
||||||
ITextComponent race = new TextComponentTranslation(spec.getTranslationKey());
|
protected boolean printSpecies(ICommandSender sender, EntityPlayer player) {
|
||||||
ITextComponent message = new TextComponentTranslation(name);
|
Race spec = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies();
|
||||||
|
|
||||||
race.getStyle().setColor(TextFormatting.GOLD);
|
String name = "commands.race.tell.";
|
||||||
|
name += player == sender ? "self" : "other";
|
||||||
|
|
||||||
message.appendSibling(race);
|
ITextComponent race = new TextComponentTranslation(spec.getTranslationKey());
|
||||||
|
ITextComponent message = new TextComponentTranslation(name);
|
||||||
|
|
||||||
player.sendMessage(message);
|
race.getStyle().setColor(TextFormatting.GOLD);
|
||||||
} else if (args[0].contentEquals("list")) {
|
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.list"));
|
|
||||||
|
|
||||||
ITextComponent message = new TextComponentString(getRacesString());
|
message.appendSibling(race);
|
||||||
|
|
||||||
boolean first = true;
|
player.sendMessage(message);
|
||||||
for (Race i : Race.values()) {
|
|
||||||
if (!i.isDefault() && PlayerSpeciesList.instance().speciesPermitted(i, player)) {
|
return true;
|
||||||
message.appendSibling(new TextComponentString((!first ? "\n" : "") + " - " + i.name().toLowerCase()));
|
}
|
||||||
first = false;
|
|
||||||
}
|
protected boolean list(EntityPlayer player) {
|
||||||
|
player.sendMessage(new TextComponentTranslation("commands.race.list"));
|
||||||
|
|
||||||
|
ITextComponent message = new TextComponentString(getRacesString());
|
||||||
|
|
||||||
|
boolean first = true;
|
||||||
|
for (Race i : Race.values()) {
|
||||||
|
if (!i.isDefault() && PlayerSpeciesList.instance().speciesPermitted(i, player)) {
|
||||||
|
message.appendSibling(new TextComponentString((!first ? "\n" : "") + " - " + i.name().toLowerCase()));
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message.getStyle().setColor(TextFormatting.GOLD);
|
message.getStyle().setColor(TextFormatting.GOLD);
|
||||||
|
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
} else if (args[0].contentEquals("describe") && args.length >= 2) {
|
|
||||||
Race species = Race.fromName(args[1], null);
|
|
||||||
|
|
||||||
if (species == null) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean describeSpecies(EntityPlayer player, String[] args) {
|
||||||
|
Race species = Race.fromName(args[1], null);
|
||||||
|
|
||||||
|
if (species == null) {
|
||||||
|
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.fail", args[1].toUpperCase()));
|
player.sendMessage(new TextComponentTranslation("commands.race.fail", args[1].toUpperCase()));
|
||||||
} else {
|
|
||||||
String name = species.name().toLowerCase();
|
|
||||||
|
|
||||||
ITextComponent line1 = new TextComponentTranslation(String.format("commands.race.describe.%s.1", name));
|
|
||||||
line1.getStyle().setColor(TextFormatting.YELLOW);
|
|
||||||
|
|
||||||
player.sendMessage(line1);
|
|
||||||
|
|
||||||
player.sendMessage(new TextComponentTranslation(String.format("commands.race.describe.%s.2", name)));
|
|
||||||
|
|
||||||
ITextComponent line3 = new TextComponentTranslation(String.format("commands.race.describe.%s.3", name));
|
|
||||||
line3.getStyle().setColor(TextFormatting.RED);
|
|
||||||
|
|
||||||
player.sendMessage(line3);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new WrongUsageException(getUsage(sender));
|
String name = species.name().toLowerCase();
|
||||||
|
|
||||||
|
ITextComponent line1 = new TextComponentTranslation(String.format("commands.race.describe.%s.1", name));
|
||||||
|
line1.getStyle().setColor(TextFormatting.YELLOW);
|
||||||
|
|
||||||
|
player.sendMessage(line1);
|
||||||
|
|
||||||
|
player.sendMessage(new TextComponentTranslation(String.format("commands.race.describe.%s.2", name)));
|
||||||
|
|
||||||
|
ITextComponent line3 = new TextComponentTranslation(String.format("commands.race.describe.%s.3", name));
|
||||||
|
line3.getStyle().setColor(TextFormatting.RED);
|
||||||
|
|
||||||
|
player.sendMessage(line3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the strings available in this command to the given list of tab completion options.
|
* Adds the strings available in this command to the given list of tab completion options.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
|
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
|
@ -155,7 +192,7 @@ class CommandSpecies extends CommandBase {
|
||||||
EntityPlayer player = sender instanceof EntityPlayer ? (EntityPlayer)sender : null;
|
EntityPlayer player = sender instanceof EntityPlayer ? (EntityPlayer)sender : null;
|
||||||
|
|
||||||
for (Race i : Race.values()) {
|
for (Race i : Race.values()) {
|
||||||
if (args[0].contentEquals("describe") || !(i.isDefault() && PlayerSpeciesList.instance().speciesPermitted(i, player))) {
|
if (args[0].contentEquals("describe") || (!i.isDefault() && PlayerSpeciesList.instance().speciesPermitted(i, player))) {
|
||||||
names.add(i.name().toLowerCase());
|
names.add(i.name().toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,12 +207,8 @@ class CommandSpecies extends CommandBase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isUsernameIndex(String[] args, int index) {
|
public boolean isUsernameIndex(String[] args, int index) {
|
||||||
if (args[0].contentEquals("get")) {
|
return index == getPlayerIndex(args);
|
||||||
return index == 1;
|
|
||||||
} else if (args[0].contentEquals("set")) {
|
|
||||||
return index == 2;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,13 +93,7 @@ class PlayerCapabilities implements IPlayer {
|
||||||
public void setPlayerSpecies(Race race) {
|
public void setPlayerSpecies(Race race) {
|
||||||
EntityPlayer player = getOwner();
|
EntityPlayer player = getOwner();
|
||||||
|
|
||||||
if (!PlayerSpeciesList.instance().speciesPermitted(race, player)) {
|
race = PlayerSpeciesList.instance().validate(race, player);
|
||||||
race = Race.EARTH;
|
|
||||||
|
|
||||||
if (!PlayerSpeciesList.instance().speciesPermitted(race, player)) {
|
|
||||||
race = Race.HUMAN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.getDataManager().set(PLAYER_RACE, race.ordinal());
|
player.getDataManager().set(PLAYER_RACE, race.ordinal());
|
||||||
|
|
||||||
|
@ -132,7 +126,7 @@ class PlayerCapabilities implements IPlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInvisible() {
|
public boolean isInvisible() {
|
||||||
return invisible;
|
return invisible && hasEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,13 +35,25 @@ public class PlayerSpeciesList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean speciesPermitted(Race race, EntityPlayer sender) {
|
public boolean speciesPermitted(Race race, EntityPlayer sender) {
|
||||||
if (race == Race.ALICORN && (sender == null || !sender.capabilities.isCreativeMode)) {
|
if (race.isOp() && (sender == null || !sender.capabilities.isCreativeMode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return race.isDefault() || UConfig.getInstance().getSpeciesWhiteList().isEmpty() || UConfig.getInstance().getSpeciesWhiteList().contains(race);
|
return race.isDefault() || UConfig.getInstance().getSpeciesWhiteList().isEmpty() || UConfig.getInstance().getSpeciesWhiteList().contains(race);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Race validate(Race race, EntityPlayer sender) {
|
||||||
|
if (!speciesPermitted(race, sender)) {
|
||||||
|
race = Race.EARTH;
|
||||||
|
|
||||||
|
if (!speciesPermitted(race, sender)) {
|
||||||
|
race = Race.HUMAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return race;
|
||||||
|
}
|
||||||
|
|
||||||
public IRaceContainer<?> emptyContainer(Entity entity) {
|
public IRaceContainer<?> emptyContainer(Entity entity) {
|
||||||
if (entity instanceof EntityPlayer) {
|
if (entity instanceof EntityPlayer) {
|
||||||
return new PlayerCapabilities((EntityPlayer)entity);
|
return new PlayerCapabilities((EntityPlayer)entity);
|
||||||
|
|
|
@ -42,7 +42,6 @@ public interface IMagicEffect extends InbtSerialisable, IAligned {
|
||||||
*/
|
*/
|
||||||
boolean isCraftable();
|
boolean isCraftable();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the highest level this spell can be safely operated at.
|
* Gets the highest level this spell can be safely operated at.
|
||||||
* Gems may go higher, however chance of explosion/exhaustion increases with every level.
|
* Gems may go higher, however chance of explosion/exhaustion increases with every level.
|
||||||
|
@ -106,6 +105,9 @@ public interface IMagicEffect extends InbtSerialisable, IAligned {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new, deep-copied instance of this spell.
|
||||||
|
*/
|
||||||
default IMagicEffect copy() {
|
default IMagicEffect copy() {
|
||||||
return SpellRegistry.instance().copyInstance(this);
|
return SpellRegistry.instance().copyInstance(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue