use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class CommandGrist method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1 || (!args[0].equalsIgnoreCase("get") && args.length < 2))
throw new WrongUsageException(this.getUsage(sender));
String command = args[0];
PlayerIdentifier identifier;
int offset = 1;
if (!(command.equalsIgnoreCase("set") || command.equalsIgnoreCase("add") || command.equalsIgnoreCase("get"))) {
command = args[1];
identifier = IdentifierHandler.getForCommand(server, sender, args[0]);
offset = 2;
} else {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
identifier = IdentifierHandler.encode(player);
}
if ((args.length - offset) % 2 != 0)
throw new WrongUsageException(this.getUsage(sender));
String displayName = identifier.getUsername();
if (command.equalsIgnoreCase("set")) {
// Using a GristAmount array instead of a GristSet gives support for setting grist to 0
GristAmount[] grist = parseGrist(args, offset);
for (GristAmount amount : grist) GristHelper.setGrist(identifier, amount.getType(), amount.getAmount());
MinestuckPlayerTracker.updateGristCache(identifier);
notifyCommandListener(sender, this, "commands.grist.setSuccess", displayName);
} else if (command.equalsIgnoreCase("add")) {
GristSet grist = new GristSet(parseGrist(args, offset));
GristHelper.increase(identifier, grist);
MinestuckPlayerTracker.updateGristCache(identifier);
notifyCommandListener(sender, this, "commands.grist.addSuccess", displayName);
} else if (command.equalsIgnoreCase("get")) {
StringBuilder grist = new StringBuilder();
for (GristAmount amount : MinestuckPlayerData.getGristSet(identifier).getArray()) if (amount.getAmount() != 0)
// TODO properly translate display name for client side
grist.append("\n").append(amount.getAmount()).append(" ").append(amount.getType().getDisplayName());
sender.sendMessage(new TextComponentTranslation("commands.grist.get", displayName, grist.toString()));
} else
throw new WrongUsageException("commands.invalidSubCommand", command);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class CommandSburbServer method execute.
@Override
public void execute(MinecraftServer mcServer, ICommandSender sender, String[] args) throws CommandException {
if (args.length != 2)
throw new WrongUsageException("commands.sburbServer.usage");
PlayerIdentifier client = IdentifierHandler.getForCommand(mcServer, sender, args[0]);
PlayerIdentifier server = IdentifierHandler.getForCommand(mcServer, sender, args[1]);
SessionHandler.connectByCommand(sender, this, client, server);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class CommandSetRung method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2)
throw new WrongUsageException(this.getUsage(sender));
PlayerIdentifier target = IdentifierHandler.getForCommand(server, sender, args[0]);
int rung = parseInt(args[1], 0, Echeladder.RUNG_COUNT - 1);
double progress = 0;
if (args.length >= 3)
progress = parseDouble(args[2], 0, 1);
Echeladder echeladder = MinestuckPlayerData.getData(target).echeladder;
echeladder.setByCommand(rung, progress);
notifyCommandListener(sender, this, "commands.setRung.success", target.getUsername(), rung, progress * 100);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class MessageType method createMessage.
private static ITextComponent createMessage(EntityConsort consort, EntityPlayer player, String unlocalizedMessage, String[] args, boolean consortPrefix) {
String s = EntityList.getEntityString(consort);
if (s == null) {
s = "generic";
}
Object[] obj = new Object[args.length];
SburbConnection c = SburbHandler.getConnectionForDimension(consort.homeDimension);
Title title = c == null ? null : MinestuckPlayerData.getData(c.getClientIdentifier()).title;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("playerNameLand")) {
if (c != null)
obj[i] = c.getClientIdentifier().getUsername();
else
obj[i] = "Player name";
} else if (args[i].equals("playerName")) {
obj[i] = player.getName();
} else if (args[i].equals("landName")) {
World world = consort.getServer().getWorld(consort.homeDimension);
if (world != null && consort.world.provider instanceof WorldProviderLands) {
ChunkProviderLands chunkProvider = (ChunkProviderLands) world.provider.createChunkGenerator();
ITextComponent aspect1 = new TextComponentTranslation("land." + chunkProvider.aspect1.getNames()[chunkProvider.nameIndex1]);
ITextComponent aspect2 = new TextComponentTranslation("land." + chunkProvider.aspect2.getNames()[chunkProvider.nameIndex2]);
if (chunkProvider.nameOrder)
obj[i] = new TextComponentTranslation("land.format", aspect1, aspect2);
else
obj[i] = new TextComponentTranslation("land.format", aspect2, aspect1);
} else
obj[i] = "Land name";
} else if (args[i].equals("playerTitleLand")) {
if (title != null)
obj[i] = title.asTextComponent();
else
obj[i] = "Player title";
} else if (args[i].equals("playerClassLand")) {
if (title != null)
obj[i] = title.getHeroClass().asTextComponent();
else
obj[i] = "Player class";
} else if (args[i].equals("playerAspectLand")) {
if (title != null)
obj[i] = title.getHeroAspect().asTextComponent();
else
obj[i] = "Player aspect";
} else if (args[i].equals("consortSound")) {
obj[i] = new TextComponentTranslation("consort.sound." + s);
} else if (args[i].equals("consortType")) {
obj[i] = new TextComponentTranslation("entity." + s + ".name");
} else if (args[i].equals("consortTypes")) {
obj[i] = new TextComponentTranslation("entity." + s + ".plural.name");
} else if (args[i].equals("playerTitle")) {
PlayerIdentifier identifier = IdentifierHandler.encode(player);
if (MinestuckPlayerData.getTitle(identifier) != null)
obj[i] = MinestuckPlayerData.getTitle(identifier).asTextComponent();
else
obj[i] = player.getName();
} else if (args[i].equals("denizen")) {
if (title != null)
obj[i] = new TextComponentTranslation("denizen." + MinestuckPlayerData.getData(c.getClientIdentifier()).title.getHeroAspect().toString() + ".name");
else
obj[i] = "Denizen";
} else if (args[i].startsWith("nbtItem:")) {
NBTTagCompound nbt = consort.getMessageTagForPlayer(player);
ItemStack stack = new ItemStack(nbt.getCompoundTag(args[i].substring(8)));
if (!stack.isEmpty())
obj[i] = new TextComponentTranslation(stack.getUnlocalizedName() + ".name");
else
obj[i] = "Item";
}
}
TextComponentTranslation message = new TextComponentTranslation("consort." + unlocalizedMessage, obj);
if (consortPrefix) {
message.getStyle().setColor(consort.getConsortType().getColor());
TextComponentTranslation entity = new TextComponentTranslation("entity." + s + ".name");
return new TextComponentTranslation("chat.type.text", entity, message);
} else
return message;
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method predefineTitle.
public static void predefineTitle(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName, Title title) throws CommandException {
PlayerIdentifier identifier = predefineCheck(server, sender, playerName, sessionName);
Title playerTitle = MinestuckPlayerData.getTitle(identifier);
if (playerTitle != null)
throw new CommandException("You can't change your title after having entered the medium.");
Session session = sessionsByName.get(sessionName);
for (SburbConnection c : session.connections) if (c.isMain && c.enteredGame && title.equals(MinestuckPlayerData.getTitle(c.getClientIdentifier())))
throw new CommandException("This title is already used by %s.", c.getClientIdentifier().getUsername());
for (Map.Entry<PlayerIdentifier, PredefineData> entry : session.predefinedPlayers.entrySet()) if (entry.getValue().title != null && title.equals(entry.getValue().title))
throw new CommandException("This title is already assigned to %s.", entry.getKey().getUsername());
PredefineData data = session.predefinedPlayers.get(identifier);
data.title = title;
TitleLandAspect landAspect = LandAspectRegistry.getSingleLandAspect(title.getHeroAspect());
if (landAspect != null)
// This part could be made more robust for when landTerrain is already defined
data.landTitle = landAspect;
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.titleSuccess", playerName, title.asTextComponent());
}
Aggregations