use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class MinestuckPlayerTracker method updateTitle.
public static void updateTitle(EntityPlayer player) {
PlayerIdentifier identifier = IdentifierHandler.encode(player);
Title newTitle = MinestuckPlayerData.getTitle(identifier);
if (newTitle == null)
return;
MinestuckPacket packet = MinestuckPacket.makePacket(Type.PLAYER_DATA, PlayerDataPacket.TITLE, newTitle.getHeroClass(), newTitle.getHeroAspect());
MinestuckChannelHandler.sendToPlayer(packet, player);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class MinestuckPlayerTracker method onPlayerLogin.
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
EntityPlayer player = event.player;
Debug.debug(player.getName() + " joined the game. Sending packets.");
MinecraftServer server = player.getServer();
if (!server.isDedicatedServer() && IdentifierHandler.host == null)
IdentifierHandler.host = event.player.getName();
IdentifierHandler.playerLoggedIn(player);
PlayerIdentifier identifier = IdentifierHandler.encode(player);
sendConfigPacket((EntityPlayerMP) player, true);
sendConfigPacket((EntityPlayerMP) player, false);
SkaianetHandler.playerConnected(player);
boolean firstTime = false;
if (MinestuckPlayerData.getGristSet(identifier) == null) {
Debug.debugf("Grist set is null for player %s. Handling it as first time in this world.", player.getName());
MinestuckPlayerData.setGrist(identifier, new GristSet(GristType.Build, 20));
firstTime = true;
}
MinestuckPlayerData.getData(identifier).echeladder.updateEcheladderBonuses(player);
if (CaptchaDeckHandler.getModus(player) == null && MinestuckConfig.defaultModusTypes.length > 0 && !MinestuckPlayerData.getData(player).givenModus) {
int index = player.world.rand.nextInt(MinestuckConfig.defaultModusTypes.length);
Modus modus = CaptchaDeckHandler.createInstance(new ResourceLocation(MinestuckConfig.defaultModusTypes[index]), Side.SERVER);
if (modus != null) {
modus.player = player;
modus.initModus(null, MinestuckConfig.initialModusSize);
CaptchaDeckHandler.setModus(player, modus);
} else
Debug.warnf("Couldn't create a modus by the name %s.", MinestuckConfig.defaultModusTypes[index]);
}
if (CaptchaDeckHandler.getModus(player) != null) {
Modus modus = CaptchaDeckHandler.getModus(player);
modus.player = player;
MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(Type.CAPTCHA, CaptchaDeckPacket.DATA, CaptchaDeckHandler.writeToNBT(modus)), player);
}
updateGristCache(identifier);
updateTitle(player);
updateEcheladder(player, true);
MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(Type.PLAYER_DATA, PlayerDataPacket.BOONDOLLAR, MinestuckPlayerData.getData(identifier).boondollars), player);
ServerEditHandler.onPlayerLoggedIn((EntityPlayerMP) player);
if (firstTime)
MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(Type.PLAYER_DATA, PlayerDataPacket.COLOR), player);
else {
MinestuckPacket packet = MinestuckPacket.makePacket(Type.PLAYER_DATA, PlayerDataPacket.COLOR, MinestuckPlayerData.getData(player).color);
MinestuckChannelHandler.sendToPlayer(packet, player);
}
if (UpdateChecker.outOfDate)
player.sendMessage(new TextComponentString("New version of Minestuck: " + UpdateChecker.latestVersion + "\nChanges: " + UpdateChecker.updateChanges));
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SkaianetHandler method requestInfo.
public static void requestInfo(EntityPlayer player, PlayerIdentifier p1) {
checkData();
PlayerIdentifier p0 = IdentifierHandler.encode(player);
PlayerIdentifier[] s = infoToSend.get(p0);
if (s == null) {
Debug.error("[SKAIANET] Something went wrong with player \"" + player.getName() + "\"'s skaianet data!");
return;
}
UserListOpsEntry opsEntry = player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
if (MinestuckConfig.privateComputers && !p0.equals(p1) && !(opsEntry != null && opsEntry.getPermissionLevel() >= 2)) {
player.sendMessage(new TextComponentString("[Minestuck] ").setStyle(new Style().setColor(TextFormatting.RED)).appendSibling(new TextComponentTranslation("message.privateComputerMessage")));
return;
}
int i = 0;
for (; i < s.length; i++) {
if (s[i] == null)
break;
if (s[i].equals(p1)) {
Debug.warnf("[Skaianet] Player %s already got the requested data.", player.getName());
// Update anyway, to fix whatever went wrong
updatePlayer(p0);
return;
}
}
if (// If the array is full, increase size with 5.
i == s.length) {
PlayerIdentifier[] newS = new PlayerIdentifier[s.length + 5];
System.arraycopy(s, 0, newS, 0, s.length);
s = newS;
infoToSend.put(p0, s);
}
s[i] = p1;
updatePlayer(p0);
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SkaianetHandler method requestConnection.
public static void requestConnection(ComputerData player, PlayerIdentifier otherPlayer, boolean isClient) {
if (player.dimension == -1)
return;
TileEntityComputer te = getComputer(player);
if (te == null)
return;
if (// Is server
!isClient) {
if (serversOpen.containsKey(player.owner) || resumingServers.containsKey(player.owner))
return;
if (// Wants to open
otherPlayer == null) {
if (resumingClients.containsKey(getAssociatedPartner(player.owner, false)))
connectTo(player, false, getAssociatedPartner(player.owner, false), resumingClients);
else {
te.getData(1).setBoolean("isOpen", true);
serversOpen.put(player.owner, player);
}
} else if (// Wants to resume
otherPlayer != null && getAssociatedPartner(player.owner, false).equals(otherPlayer)) {
if (// The client is already waiting
resumingClients.containsKey(otherPlayer))
connectTo(player, false, otherPlayer, resumingClients);
else // Client is not currently trying to resume
{
te.getData(1).setBoolean("isOpen", true);
resumingServers.put(player.owner, player);
}
} else
return;
} else // Is client
{
if (getClientConnection(player.owner) != null || resumingClients.containsKey(player.owner))
return;
PlayerIdentifier p = getAssociatedPartner(player.owner, true);
if (// If trying to connect to the associated partner
p != null && (otherPlayer == null || p.equals(otherPlayer))) {
if (// If server is "resuming".
resumingServers.containsKey(p))
connectTo(player, true, p, resumingServers);
else if (// If server is normally open.
serversOpen.containsKey(p))
connectTo(player, true, p, serversOpen);
else // If server isn't open
{
te.getData(0).setBoolean("isResuming", true);
resumingClients.put(player.owner, player);
}
} else if (// If the server is open.
serversOpen.containsKey(otherPlayer))
connectTo(player, true, otherPlayer, serversOpen);
}
te.markBlockForUpdate();
updateAll();
}
use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.
the class SburbHandler method predefineCheck.
private static PlayerIdentifier predefineCheck(MinecraftServer server, ICommandSender sender, String playerName, String sessionName) throws CommandException {
PlayerIdentifier identifier = IdentifierHandler.getForCommand(server, sender, playerName);
Session session = sessionsByName.get(sessionName), playerSession = getPlayerSession(identifier);
if (session == null) {
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 == null)
throw new CommandException("Couldn't find session with the name %s", sessionName);*/
if (playerSession != null && session != playerSession)
throw new CommandException("The player is already in another session!");
if (playerSession == null || !session.predefinedPlayers.containsKey(identifier)) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Couldn't find session for player or player isn't registered with this session yet. Adding player to session " + sessionName));
session.predefinedPlayers.put(identifier, new PredefineData());
}
return identifier;
}
Aggregations