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,33 +44,55 @@ 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;
|
|
||||||
int playerIndex = 1;
|
|
||||||
|
|
||||||
if (args[0].contentEquals("set") || args[0].contentEquals("describe")) {
|
|
||||||
playerIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > playerIndex) {
|
protected boolean processCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||||
player = getPlayer(server, sender, args[playerIndex]);
|
|
||||||
} else {
|
if (args.length < 1) {
|
||||||
player = getCommandSenderAsPlayer(sender);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].contentEquals("set") && args.length >= 2) {
|
int playerIndex = this.getPlayerIndex(args);
|
||||||
|
|
||||||
|
EntityPlayerMP player = args.length > playerIndex ? getPlayer(server, sender, args[playerIndex]) : getCommandSenderAsPlayer(sender);
|
||||||
|
|
||||||
|
if (args.length >= 2) {
|
||||||
|
switch (args[0]) {
|
||||||
|
case "set": return updateSpecies(sender, player, args);
|
||||||
|
case "describe": return describeSpecies(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[0]) {
|
||||||
|
case "get": return printSpecies(sender, player);
|
||||||
|
case "list": return list(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
Race species = Race.fromName(args[1], Race.HUMAN);
|
||||||
|
|
||||||
if (species.isDefault()) {
|
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)) {
|
} else if (PlayerSpeciesList.instance().speciesPermitted(species, player)) {
|
||||||
PlayerSpeciesList.instance().getPlayer(player).setPlayerSpecies(species);
|
PlayerSpeciesList.instance().getPlayer(player).setPlayerSpecies(species);
|
||||||
|
|
||||||
ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase());
|
ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase());
|
||||||
|
@ -78,14 +100,19 @@ class CommandSpecies extends CommandBase {
|
||||||
if (player != sender) {
|
if (player != sender) {
|
||||||
notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName);
|
notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName);
|
||||||
} else {
|
} else {
|
||||||
|
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.success.self"));
|
player.sendMessage(new TextComponentTranslation("commands.race.success.self"));
|
||||||
|
}
|
||||||
notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName);
|
notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.permission"));
|
player.sendMessage(new TextComponentTranslation("commands.race.permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else if (args[0].contentEquals("get")) {
|
|
||||||
|
protected boolean printSpecies(ICommandSender sender, EntityPlayer player) {
|
||||||
Race spec = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies();
|
Race spec = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies();
|
||||||
|
|
||||||
String name = "commands.race.tell.";
|
String name = "commands.race.tell.";
|
||||||
|
@ -99,7 +126,11 @@ class CommandSpecies extends CommandBase {
|
||||||
message.appendSibling(race);
|
message.appendSibling(race);
|
||||||
|
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
} else if (args[0].contentEquals("list")) {
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean list(EntityPlayer player) {
|
||||||
player.sendMessage(new TextComponentTranslation("commands.race.list"));
|
player.sendMessage(new TextComponentTranslation("commands.race.list"));
|
||||||
|
|
||||||
ITextComponent message = new TextComponentString(getRacesString());
|
ITextComponent message = new TextComponentString(getRacesString());
|
||||||
|
@ -115,11 +146,17 @@ class CommandSpecies extends CommandBase {
|
||||||
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) {
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean describeSpecies(EntityPlayer player, String[] args) {
|
||||||
Race species = Race.fromName(args[1], null);
|
Race species = Race.fromName(args[1], null);
|
||||||
|
|
||||||
if (species == 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 {
|
} else {
|
||||||
String name = species.name().toLowerCase();
|
String name = species.name().toLowerCase();
|
||||||
|
|
||||||
|
@ -135,14 +172,14 @@ class CommandSpecies extends CommandBase {
|
||||||
|
|
||||||
player.sendMessage(line3);
|
player.sendMessage(line3);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new WrongUsageException(getUsage(sender));
|
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