use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method managePredefinedSession.
public static void managePredefinedSession(MinecraftServer server, ICommandSender sender, ICommand command, String sessionName, String[] playerNames, boolean finish) throws CommandException {
Session session = sessionsByName.get(sessionName);
if (session == null) {
if (finish && playerNames.length == 0)
throw new CommandException("Couldn't find session with that name. Aborting the finalizing process.", sessionName);
if (singleSession)
throw new CommandException("Not allowed to create new sessions when global session is active. Use \"%s\" as session name for global session access.", GLOBAL_SESSION_NAME);
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Couldn't find session with that name, creating a new session..."));
session = new Session();
session.name = sessionName;
sessions.add(session);
sessionsByName.put(session.name, session);
}
if (session.locked)
throw new CommandException("That session may no longer be modified.");
int handled = 0;
boolean skipFinishing = false;
for (String playerName : playerNames) {
if (playerName.startsWith("!")) {
playerName = playerName.substring(1);
PlayerIdentifier identifier;
try {
identifier = IdentifierHandler.getForCommand(server, sender, playerName);
} catch (CommandException c) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString(String.format(c.getMessage(), c.getErrorObjects())));
continue;
}
if (!session.containsPlayer(identifier)) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Failed to remove player \"" + playerName + "\": Player isn't in session.").setStyle(new Style().setColor(TextFormatting.RED)));
continue;
}
if (session.predefinedPlayers.remove(identifier) == null) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Failed to remove player \"" + playerName + "\": Player isn't registered with the session.").setStyle(new Style().setColor(TextFormatting.RED)));
continue;
}
handled++;
if (session.containsPlayer(identifier)) {
split(session);
session = sessionsByName.get(sessionName);
if (session.containsPlayer(identifier)) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Removed player \"" + playerName + "\", but they are still part of a connection in the session and will therefore be part of the session unless the connection is discarded.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
skipFinishing = true;
continue;
}
}
} else {
PlayerIdentifier identifier;
try {
identifier = IdentifierHandler.getForCommand(server, sender, playerName);
} catch (CommandException c) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString(String.format(c.getMessage(), c.getErrorObjects())));
continue;
}
if (session.predefinedPlayers.containsKey(identifier)) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": Player is already registered with session.").setStyle(new Style().setColor(TextFormatting.RED)));
continue;
}
Session playerSession = getPlayerSession(identifier);
if (playerSession != null) {
if (merge(session, playerSession, null) != null) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": Can't merge with the session that the player is already in.").setStyle(new Style().setColor(TextFormatting.RED)));
continue;
}
} else if (MinestuckConfig.forceMaxSize && session.getPlayerList().size() + 1 > maxSize) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": The session can't accept more players with the current configurations.").setStyle(new Style().setColor(TextFormatting.RED)));
continue;
}
session.predefinedPlayers.put(identifier, new PredefineData());
handled++;
}
}
if (playerNames.length > 0)
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.addSuccess", handled, playerNames.length);
/*if(finish)
if(!skipFinishing && handled == playerNames.length)
{
SburbHandler.finishSession(sender, command, session);
} else throw new CommandException("Skipping to finalize the session due to one or more issues while adding players.");*/
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method sessionName.
public static void sessionName(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName) throws CommandException {
PlayerIdentifier identifier = IdentifierHandler.getForCommand(server, sender, playerName);
Session playerSession = getPlayerSession(identifier), session = sessionsByName.get(sessionName);
if (singleSession)
throw new CommandException("Not allowed to change session name when global session is active. Use \"%s\" as session name for global session access.", GLOBAL_SESSION_NAME);
if (playerSession == null)
throw new CommandException("Couldn't find session for player \"%s\"", playerName);
if (session != null)
throw new CommandException("That session name is already taken.");
if (playerSession.name != null)
sessionsByName.remove(playerSession.name);
String prevName = playerSession.name;
playerSession.name = sessionName;
sessionsByName.put(playerSession.name, playerSession);
if (prevName != null)
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.rename", prevName, sessionName, playerName);
else
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.name", sessionName, playerName);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method hasEntered.
public static boolean hasEntered(EntityPlayerMP player) {
PlayerIdentifier identifier = IdentifierHandler.encode(player);
SburbConnection c = SkaianetHandler.getMainConnection(identifier, true);
return c != null && c.enteredGame();
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method predefineTerrainLandAspect.
public static void predefineTerrainLandAspect(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName, TerrainLandAspect aspect) throws CommandException {
PlayerIdentifier identifier = predefineCheck(server, sender, playerName, sessionName);
Session session = sessionsByName.get(sessionName);
SburbConnection clientConnection = SkaianetHandler.getClientConnection(identifier);
PredefineData data = session.predefinedPlayers.get(identifier);
if (clientConnection != null && clientConnection.enteredGame())
throw new CommandException("You can't change your land aspects after having entered the medium.");
if (data.landTitle == null)
throw new CommandException("You should define the other land aspect before this one.");
if (!data.landTitle.isAspectCompatible(aspect))
throw new CommandException("That terrain land aspect isn't compatible with the other land aspect.");
data.landTerrain = aspect;
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.landTerrainSuccess", playerName, aspect.getPrimaryName());
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SessionHandler method createDataTag.
/**
* Creates data to be used for the data checker
*/
public static NBTTagCompound createDataTag(MinecraftServer server) {
NBTTagCompound nbt = new NBTTagCompound();
NBTTagList sessionList = new NBTTagList();
nbt.setTag("sessions", sessionList);
int nameIndex = 1;
for (int i = 0; i < sessions.size(); i++) {
Session session = sessions.get(i);
NBTTagList connectionList = new NBTTagList();
Set<PlayerIdentifier> playerSet = new HashSet<PlayerIdentifier>();
for (SburbConnection c : session.connections) {
if (c.isMain)
playerSet.add(c.getClientIdentifier());
NBTTagCompound connectionTag = new NBTTagCompound();
connectionTag.setString("client", c.getClientIdentifier().getUsername());
connectionTag.setString("clientId", c.getClientIdentifier().getString());
if (!c.getServerIdentifier().equals(IdentifierHandler.nullIdentifier))
connectionTag.setString("server", c.getServerIdentifier().getUsername());
connectionTag.setBoolean("isMain", c.isMain);
connectionTag.setBoolean("isActive", c.isActive);
if (c.isMain) {
connectionTag.setInteger("clientDim", c.enteredGame ? c.clientHomeLand : 0);
if (c.enteredGame && DimensionManager.isDimensionRegistered(c.clientHomeLand)) {
LandAspectRegistry.AspectCombination aspects = MinestuckDimensionHandler.getAspects(c.clientHomeLand);
IChunkGenerator chunkGen = server.getWorld(c.clientHomeLand).provider.createChunkGenerator();
if (chunkGen instanceof ChunkProviderLands) {
ChunkProviderLands landChunkGen = (ChunkProviderLands) chunkGen;
if (landChunkGen.nameOrder) {
connectionTag.setString("aspect1", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
connectionTag.setString("aspect2", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
} else {
connectionTag.setString("aspect1", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
connectionTag.setString("aspect2", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
}
}
Title title = MinestuckPlayerData.getTitle(c.getClientIdentifier());
connectionTag.setByte("class", title == null ? -1 : (byte) title.getHeroClass().ordinal());
connectionTag.setByte("aspect", title == null ? -1 : (byte) title.getHeroAspect().ordinal());
} else if (session.predefinedPlayers.containsKey(c.getClientIdentifier())) {
PredefineData data = session.predefinedPlayers.get(c.getClientIdentifier());
if (data.title != null) {
connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
}
if (data.landTerrain != null)
connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
if (data.landTitle != null)
connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
}
}
connectionList.appendTag(connectionTag);
}
for (Map.Entry<PlayerIdentifier, PredefineData> entry : session.predefinedPlayers.entrySet()) {
if (playerSet.contains(entry.getKey()))
continue;
NBTTagCompound connectionTag = new NBTTagCompound();
connectionTag.setString("client", entry.getKey().getUsername());
connectionTag.setString("clientId", entry.getKey().getString());
connectionTag.setBoolean("isMain", true);
connectionTag.setBoolean("isActive", false);
connectionTag.setInteger("clientDim", 0);
PredefineData data = entry.getValue();
if (data.title != null) {
connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
}
if (data.landTerrain != null)
connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
if (data.landTitle != null)
connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
connectionList.appendTag(connectionTag);
}
NBTTagCompound sessionTag = new NBTTagCompound();
if (session.name != null)
sessionTag.setString("name", session.name);
sessionTag.setTag("connections", connectionList);
sessionList.appendTag(sessionTag);
}
return nbt;
}
Aggregations