use of net.minecraft.util.text.Style in project minecolonies by Minecolonies.
the class ListCitizensCommand method drawPageSwitcher.
/**
* Draws the page switcher at the bottom.
*
* @param sender the sender.
* @param page the page number.
* @param count number of citizens.
* @param halfPage the halfPage.
* @param colonyId the colony id.
*/
private static void drawPageSwitcher(@NotNull final ICommandSender sender, final int page, final int count, final int halfPage, final int colonyId) {
final int prevPage = Math.max(0, page - 1);
final int nextPage = Math.min(page + 1, (count / CITIZENS_ON_PAGE) + halfPage);
final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, prevPage))));
final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, nextPage))));
final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
final ITextComponent endLine = new TextComponentString(PAGE_LINE);
sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
use of net.minecraft.util.text.Style 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 net.minecraft.util.text.Style in project Minestuck by mraof.
the class SessionHandler method connectByCommand.
public static void connectByCommand(ICommandSender sender, ICommand command, PlayerIdentifier client, PlayerIdentifier server) throws CommandException {
Session sc = getPlayerSession(client), ss = getPlayerSession(server);
if (singleSession) {
int i = (sc == null ? 1 : 0) + (ss == null ? 1 : 0);
sc = ss = sessions.get(0);
if (MinestuckConfig.forceMaxSize && sc.getPlayerList().size() + i > maxSize)
throw new CommandException("computer.singleSessionFull");
} else {
if (sc == null && ss == null) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Neither player is part of a session. Creating new session..."));
sc = ss = new Session();
sessions.add(sc);
} else if (sc == null) {
if (ss.locked)
throw new CommandException("The server session is locked, and can no longer be modified!");
if (MinestuckConfig.forceMaxSize && ss.getPlayerList().size() + 1 > maxSize)
throw new CommandException("computer.serverSessionFull");
sc = ss;
} else if (ss == null) {
if (sc.locked)
throw new CommandException("The client session is locked, and can no longer be modified!");
if (MinestuckConfig.forceMaxSize && sc.getPlayerList().size() + 1 > maxSize)
throw new CommandException("computer.clientSessionFull");
ss = sc;
}
}
SburbConnection cc = SkaianetHandler.getMainConnection(client, true), cs = SkaianetHandler.getMainConnection(server, false);
if (cc != null && cc == cs)
throw new CommandException("Those players are already connected!");
if (sc != ss) {
String merge = merge(sc, ss, null);
if (merge != null)
throw new CommandException(merge);
}
if (cs != null) {
if (cs.isActive)
SkaianetHandler.closeConnection(server, cs.getClientIdentifier(), false);
cs.serverIdentifier = IdentifierHandler.nullIdentifier;
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString(server.getUsername() + "'s old client player " + cs.getClientIdentifier().getUsername() + " is now without a server player.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
}
if (cc != null && cc.isActive)
SkaianetHandler.closeConnection(client, cc.getServerIdentifier(), true);
SburbConnection connection = SkaianetHandler.getConnection(client, server);
if (cc == null) {
if (connection != null)
cc = connection;
else {
cc = new SburbConnection();
SkaianetHandler.connections.add(cc);
cc.clientIdentifier = client;
cc.serverIdentifier = server;
sc.connections.add(cc);
SburbHandler.onConnectionCreated(cc);
}
cc.isMain = true;
} else {
if (connection != null && connection.isActive) {
SkaianetHandler.connections.remove(connection);
sc.connections.remove(connection);
cc.client = connection.client;
cc.server = connection.server;
cc.serverIdentifier = server;
} else
cc.serverIdentifier = server;
}
SkaianetHandler.updateAll();
CommandBase.notifyCommandListener(sender, command, "commands.sburbServer.success", client.getUsername(), server.getUsername());
}
use of net.minecraft.util.text.Style 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)));
}
}
use of net.minecraft.util.text.Style in project Random-Things by lumien231.
the class RTCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
return;
}
if (args[0].equals("setBiomeCrystal")) {
if (args.length == 2 && sender instanceof EntityPlayer) {
String biomeName = args[1];
EntityPlayer player = (EntityPlayer) sender;
ItemStack equipped = player.getHeldItemMainhand();
if (equipped != null && equipped.getItem() instanceof ItemBiomeCrystal) {
if (equipped.getTagCompound() == null) {
equipped.setTagCompound(new NBTTagCompound());
}
equipped.getTagCompound().setString("biomeName", args[1]);
}
}
} else if (args[0].equals("generateBiomeCrystalChests")) {
if (sender instanceof EntityPlayer) {
List<ResourceLocation> biomeIds = new ArrayList<>(Biome.REGISTRY.getKeys());
int modX = 0;
while (!biomeIds.isEmpty()) {
sender.getEntityWorld().setBlockState(sender.getPosition().add(modX, 0, 0), Blocks.CHEST.getDefaultState());
IInventory inventory = (IInventory) sender.getEntityWorld().getTileEntity(sender.getPosition().add(modX, 0, 0));
for (int i = 0; i < 27; i++) {
if (!biomeIds.isEmpty()) {
ResourceLocation next = biomeIds.remove(biomeIds.size() - 1);
ItemStack crystal = new ItemStack(ModItems.biomeCrystal);
crystal.setTagCompound(new NBTTagCompound());
crystal.getTagCompound().setString("biomeName", next.toString());
inventory.setInventorySlotContents(i, crystal);
}
}
modX += 2;
}
}
} else if (args[0].equals("tpFilter")) {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) sender;
ItemStack held;
if ((held = player.getHeldItemMainhand()) != null && held.getItem() == ModItems.positionFilter) {
BlockPos pos = ItemPositionFilter.getPosition(held);
player.connection.setPlayerLocation(pos.getX(), pos.getY() + 150, pos.getZ(), player.rotationYaw, player.rotationPitch);
}
}
} else if (args[0].equals("testSlimeSpawn")) {
BlockPos pos = sender.getPosition();
World world = sender.getEntityWorld();
if (pos != null && world != null) {
EntitySlime slime = new EntitySlime(world);
slime.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), 0F, 0F);
sender.sendMessage(new TextComponentString(slime.getCanSpawnHere() + ""));
}
} else if (args[0].equals("notify") && args.length == 5) {
String title = args[1];
String body = args[2];
String itemName = args[3];
String player = args[4];
EntityPlayerMP playerEntity = server.getPlayerList().getPlayerByUsername(player);
ItemStack itemStack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
MessageNotification message = new MessageNotification(title, body, itemStack);
PacketHandler.INSTANCE.sendTo(message, playerEntity);
} else if (args[0].equals("fireplaces")) {
FlooNetworkHandler handler = FlooNetworkHandler.get(sender.getEntityWorld());
List<FlooFireplace> firePlaces = handler.getFirePlaces();
sender.sendMessage(new TextComponentString("Floo Fireplaces in Dimension " + sender.getEntityWorld().provider.getDimension()).setStyle(new Style().setUnderlined(true)));
sender.sendMessage(new TextComponentString(""));
for (FlooFireplace firePlace : firePlaces) {
String name = firePlace.getName();
UUID creator = firePlace.getCreatorUUID();
String ownerName = null;
if (creator != null) {
GameProfile profile = server.getPlayerProfileCache().getProfileByUUID(creator);
if (profile != null) {
ownerName = profile.getName();
}
}
BlockPos pos = firePlace.getLastKnownPosition();
sender.sendMessage(new TextComponentString((name == null ? "<Unnamed>" : name) + " | " + String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()) + (ownerName != null ? " | " + ownerName : "")));
}
} else if (args[0].equals("festival")) {
FestivalHandler handler = FestivalHandler.get(sender.getEntityWorld());
List<EntityVillager> villagerList = sender.getEntityWorld().getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB(sender.getPosition()).grow(50));
if (!villagerList.isEmpty()) {
EntityVillager villager = villagerList.get(0);
int success = handler.addFestival(villager);
if (success == 2) {
sender.sendMessage(new TextComponentTranslation("command.festival.scheduled"));
} else {
sender.sendMessage(new TextComponentTranslation("command.festival.failed"));
}
} else {
sender.sendMessage(new TextComponentTranslation("command.festival.novillager"));
}
} else if (args[0].equals("ancientFurnace")) {
WorldGenAncientFurnace.pattern.place(sender.getEntityWorld(), sender.getPosition(), 3);
}
}
Aggregations