use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.
the class ServerEditHandler method onBlockPlaced.
@SubscribeEvent(priority = EventPriority.LOW)
public void onBlockPlaced(BlockEvent.PlaceEvent event) {
if (getData(event.getPlayer()) != null) {
EditData data = getData(event.getPlayer());
if (// If the event was cancelled server side and not client side, notify the client.
event.isCanceled()) {
MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, data.connection.givenItems());
MinestuckChannelHandler.sendToPlayer(packet, event.getPlayer());
return;
}
ItemStack stack = event.getItemInHand();
if (DeployList.containsItemStack(stack)) {
SburbConnection c = data.connection;
GristSet cost = c.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
c.givenItems()[DeployList.getOrdinal(stack)] = true;
if (!c.isMain())
SkaianetHandler.giveItems(c.getClientIdentifier());
if (!cost.isEmpty()) {
GristHelper.decrease(c.getClientIdentifier(), cost);
MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
}
event.getPlayer().inventory.mainInventory.set(event.getPlayer().inventory.currentItem, ItemStack.EMPTY);
} else {
GristHelper.decrease(data.connection.getClientIdentifier(), GristRegistry.getGristConversion(stack));
MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
}
}
}
use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.
the class ServerEditHandler method newServerEditor.
public static void newServerEditor(EntityPlayerMP player, PlayerIdentifier computerOwner, PlayerIdentifier computerTarget) {
if (player.isRiding())
// Don't want to bother making the decoy able to ride anything right now.
return;
SburbConnection c = SkaianetHandler.getClientConnection(computerTarget);
if (c != null && c.getServerIdentifier().equals(computerOwner) && getData(c) == null && getData(player) == null) {
Debug.info("Activating edit mode on player \"" + player.getName() + "\", target player: \"" + computerTarget + "\".");
EntityDecoy decoy = new EntityDecoy((WorldServer) player.world, player);
EditData data = new EditData(decoy, player, c);
if (!c.enteredGame()) {
c.centerX = c.getClientData().getX();
c.centerZ = c.getClientData().getZ();
}
if (!setPlayerStats(player, c)) {
player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to activate edit mode."));
return;
}
if (c.inventory != null)
player.inventory.readFromNBT(c.inventory);
decoy.world.spawnEntity(decoy);
list.add(data);
MinestuckPacket packet = MinestuckPacket.makePacket(Type.SERVER_EDIT, computerTarget, c.centerX, c.centerZ, c.givenItems());
MinestuckChannelHandler.sendToPlayer(packet, player);
MinestuckPlayerTracker.updateGristCache(c.getClientIdentifier());
}
}
use of com.mraof.minestuck.network.skaianet.SburbConnection 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.network.skaianet.SburbConnection in project Minestuck by mraof.
the class TileEntityComputer method getUpdateTag.
@Override
public NBTTagCompound getUpdateTag() {
NBTTagCompound tagCompound = new NBTTagCompound();
this.writeToNBT(tagCompound);
tagCompound.removeTag("owner");
tagCompound.removeTag("ownerMost");
tagCompound.removeTag("ownerLeast");
if (owner != null)
tagCompound.setInteger("ownerId", owner.getId());
if (hasProgram(1)) {
SburbConnection c = SkaianetHandler.getServerConnection(ComputerData.createData(this));
if (c != null)
tagCompound.getCompoundTag("programData").getCompoundTag("program_1").setInteger("connectedClient", c.getClientIdentifier().getId());
}
return tagCompound;
}
use of com.mraof.minestuck.network.skaianet.SburbConnection in project Minestuck by mraof.
the class ItemCruxiteArtifact method onArtifactActivated.
public void onArtifactActivated(World world, EntityPlayer player) {
try {
if (!world.isRemote && player.world.provider.getDimension() != -1) {
if (!SburbHandler.shouldEnterNow(player))
return;
SburbConnection c = SkaianetHandler.getMainConnection(IdentifierHandler.encode(player), true);
if (c == null || !c.enteredGame() || !MinestuckConfig.stopSecondEntry && !MinestuckDimensionHandler.isLandDimension(player.world.provider.getDimension())) {
if (c != null && c.enteredGame()) {
World newWorld = player.getServer().getWorld(c.getClientDimension());
if (newWorld == null) {
return;
}
BlockPos pos = newWorld.provider.getRandomizedSpawnPoint();
Teleport.teleportEntity(player, c.getClientDimension(), null, pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
return;
}
int destinationId = LandAspectRegistry.createLand(player);
if (// Something bad happened further down and the problem should be written in the server console
destinationId == -1) {
player.sendMessage(new TextComponentString("Something went wrong during entry. More details in the server console."));
return;
}
if (!Teleport.teleportEntity(player, destinationId, this)) {
Debug.warn("Was not able to teleport player " + player.getName() + " into the medium! Likely caused by mod collision.");
player.sendMessage(new TextComponentString("Was not able to teleport you into the medium! Likely caused by mod collision."));
} else
MinestuckPlayerTracker.sendLandEntryMessage(player);
}
}
} catch (Exception e) {
Debug.logger.error("Exception when " + player.getName() + " tried to enter their land.", e);
player.sendMessage(new TextComponentString("[Minestuck] Something went wrong during entry. " + (Minestuck.isServerRunning ? "Check the console for the error message." : "Notify the server owner about this.")).setStyle(new Style().setColor(TextFormatting.RED)));
}
}
Aggregations