use of net.minecraft.util.text.TextComponentString in project Waystones by blay09.
the class BlockWaystone method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
if (!world.isRemote) {
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone == null) {
return true;
}
if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(player)) {
player.sendStatusMessage(new TextComponentTranslation("waystones:notTheOwner"), true);
return true;
}
if (tileWaystone.isGlobal() && !player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
player.sendStatusMessage(new TextComponentTranslation("waystones:creativeRequired"), true);
return true;
}
player.openGui(Waystones.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone == null) {
return true;
}
WaystoneEntry knownWaystone = world.isRemote ? ClientWaystones.getKnownWaystone(tileWaystone.getWaystoneName()) : null;
if (knownWaystone != null) {
Waystones.proxy.openWaystoneSelection(WarpMode.WAYSTONE, EnumHand.MAIN_HAND, knownWaystone);
} else if (!world.isRemote) {
WaystoneEntry waystone = new WaystoneEntry(tileWaystone);
if (!WaystoneManager.checkAndUpdateWaystone(player, waystone)) {
TextComponentString nameComponent = new TextComponentString(tileWaystone.getWaystoneName());
nameComponent.getStyle().setColor(TextFormatting.WHITE);
TextComponentTranslation chatComponent = new TextComponentTranslation("waystones:activatedWaystone", nameComponent);
chatComponent.getStyle().setColor(TextFormatting.YELLOW);
player.sendMessage(chatComponent);
player.addStat(WAYSTONE_ACTIVATED);
WaystoneManager.addPlayerWaystone(player, waystone);
WaystoneManager.sendPlayerWaystones(player);
}
if (WaystoneConfig.general.setSpawnPoint) {
EnumFacing blockFacing = state.getValue(FACING);
player.setSpawnPoint(new BlockPos(tileWaystone.getPos().offset(blockFacing)), true);
}
} else {
Waystones.proxy.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, pos, 1f);
for (int i = 0; i < 32; i++) {
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 3, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 4, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
}
}
return true;
}
use of net.minecraft.util.text.TextComponentString in project OreSpawn by MinecraftModDevelopmentMods.
the class ClearChunkCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!(sender instanceof EntityPlayer)) {
throw new CommandException("Only players can use this command");
}
EntityPlayer player = (EntityPlayer) sender;
Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(player.getPosition());
ChunkPos chunkPos = chunk.getPos();
List<IBlockState> blocks;
boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false;
List<String> blockNames = new LinkedList<>();
getBlocks(args, blockNames);
blocks = blockNames.stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList());
blocks.addAll(OreSpawn.API.getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList()));
List<IBlockState> overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(bl -> bl.getDefaultState()).collect(Collectors.toList());
clearBlocks(chunkPos, blocks, overburden, flagClassic, player);
player.sendStatusMessage(new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true);
}
use of net.minecraft.util.text.TextComponentString in project YABBA by LatvianModder.
the class TileItemBarrel method createConfig.
@Override
public void createConfig(YabbaConfigEvent event) {
super.createConfig(event);
String group = Yabba.MOD_ID;
event.getConfig().setGroupName(group, new TextComponentString(Yabba.MOD_NAME));
if (!tier.creative()) {
event.getConfig().add(group, "locked", isLocked);
}
}
use of net.minecraft.util.text.TextComponentString in project Cavern2 by kegare.
the class RegenerationMessage method process.
@Override
public IMessage process() {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
File rootDir = DimensionManager.getCurrentSaveRootDirectory();
if (rootDir == null || !rootDir.exists()) {
return new RegenerationGuiMessage(EnumType.FAILED);
}
server.getPlayerList().saveAllPlayerData();
for (DimensionType type : dimensions) {
WorldServer world = DimensionManager.getWorld(type.getId());
if (world != null) {
for (EntityPlayer player : world.playerEntities) {
if (player != null && player instanceof EntityPlayerMP) {
EntityPlayerMP playerMP = (EntityPlayerMP) player;
if (playerMP.connection != null) {
playerMP.connection.disconnect(new TextComponentTranslation("cavern.message.disconnect.unload"));
}
}
}
try {
world.saveAllChunks(true, null);
} catch (MinecraftException e) {
return new RegenerationGuiMessage(EnumType.FAILED);
}
world.flush();
MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(world));
DimensionManager.setWorld(world.provider.getDimension(), null, server);
world.getWorldInfo().setDimensionData(world.provider.getDimension(), null);
}
for (EntityPlayerMP player : server.getPlayerList().getPlayers()) {
if (player != null) {
PortalCache.get(player).clearLastPos(null, type);
}
}
File dimDir = new File(rootDir, "DIM" + type.getId());
if (!dimDir.exists()) {
return new RegenerationGuiMessage(EnumType.FAILED);
}
ITextComponent name = new TextComponentString(CaveDimensions.getLocalizedName(type));
name.getStyle().setBold(true);
sendProgress(EnumType.START);
ITextComponent message = new TextComponentTranslation("cavern.regeneration.regenerating", name);
message.getStyle().setColor(TextFormatting.GRAY);
server.getPlayerList().sendMessage(message);
if (backup) {
message = new TextComponentTranslation("cavern.regeneration.backup", name);
message.getStyle().setColor(TextFormatting.GRAY);
server.getPlayerList().sendMessage(message);
sendProgress(EnumType.BACKUP);
Calendar calendar = Calendar.getInstance();
String year = Integer.toString(calendar.get(Calendar.YEAR));
String month = String.format("%02d", calendar.get(Calendar.MONTH) + 1);
String day = String.format("%02d", calendar.get(Calendar.DATE));
String hour = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY));
String minute = String.format("%02d", calendar.get(Calendar.MINUTE));
String second = String.format("%02d", calendar.get(Calendar.SECOND));
File bak = new File(rootDir, type.getName() + "_bak-" + String.join("", year, month, day) + "-" + String.join("", hour, minute, second) + ".zip");
if (CaveUtils.archiveDirectory(dimDir, bak)) {
message = new TextComponentTranslation("cavern.regeneration.backup.success", name);
message.getStyle().setColor(TextFormatting.GRAY);
server.getPlayerList().sendMessage(message);
} else {
message = new TextComponentTranslation("cavern.regeneration.backup.failed", name);
message.getStyle().setColor(TextFormatting.RED);
server.getPlayerList().sendMessage(message);
return new RegenerationGuiMessage(EnumType.FAILED);
}
}
try {
FileUtils.deleteDirectory(dimDir);
} catch (IOException e) {
return new RegenerationGuiMessage(EnumType.FAILED);
}
message = new TextComponentTranslation("cavern.regeneration.regenerated", name);
message.getStyle().setColor(TextFormatting.GRAY);
server.getPlayerList().sendMessage(message);
if (type.shouldLoadSpawn()) {
world = server.getWorld(type.getId());
try {
world.saveAllChunks(true, null);
} catch (MinecraftException e) {
}
world.flush();
}
}
return new RegenerationGuiMessage(EnumType.REGENERATED);
}
use of net.minecraft.util.text.TextComponentString in project BetterQuesting by Funwayguy.
the class PktHandlerLineEdit method handleServer.
@Override
public void handleServer(NBTTagCompound data, EntityPlayerMP sender) {
if (sender == null) {
return;
}
boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
if (!isOP) {
BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to edit quest lines without OP permissions!");
sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
// Player is not operator. Do nothing
return;
}
int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
int lID = !data.hasKey("lineID") ? -1 : data.getInteger("lineID");
int idx = !data.hasKey("order") ? -1 : data.getInteger("order");
IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(lID);
if (aID < 0 || aID >= EnumPacketAction.values().length) {
return;
}
EnumPacketAction action = EnumPacketAction.values()[aID];
if (action == EnumPacketAction.ADD) {
IQuestLine nq = new QuestLine();
int nID = QuestLineDatabase.INSTANCE.nextKey();
if (data.hasKey("data") && lID >= 0) {
nID = lID;
NBTTagCompound base = data.getCompoundTag("data");
nq.readFromNBT(base.getCompoundTag("line"), EnumSaveType.CONFIG);
}
QuestLineDatabase.INSTANCE.add(nq, nID);
PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
return;
} else if (// Edit quest lines
action == EnumPacketAction.EDIT && questLine != null) {
questLine.readPacket(data);
if (idx >= 0 && QuestLineDatabase.INSTANCE.getOrderIndex(lID) != idx) {
QuestLineDatabase.INSTANCE.setOrderIndex(lID, idx);
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
} else {
PacketSender.INSTANCE.sendToAll(questLine.getSyncPacket());
}
return;
} else if (action == EnumPacketAction.REMOVE && questLine != null) {
QuestLineDatabase.INSTANCE.removeKey(lID);
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
return;
}
}
Aggregations