use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.
the class CommandSanity method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
boolean sane = true;
if (RecurrentComplex.isLite()) {
commandSender.sendMessage(new TextComponentString("Recurrent Complex is in lightweight mode!"));
}
if (StructureRegistry.INSTANCE.ids().isEmpty()) {
commandSender.sendMessage(new TextComponentString("No registered structures!"));
sane = false;
}
if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
sane = false;
}
for (ModContainer mod : Loader.instance().getModList()) {
String domain = mod.getModId();
Path path = null;
try {
path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
if (path != null && !Files.isReadable(path)) {
commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
sane = false;
}
} catch (RCFiles.ResourceLocationLoadException e) {
RecurrentComplex.logger.error(e);
commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
sane = false;
} finally {
if (path != null)
RCFiles.closeQuietly(path.getFileSystem());
}
}
if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
sane = false;
}
if (!parameters.has("short")) {
sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
sane &= addGenericStructureLog(commandSender, (s, structure) -> !structure.metadata.authors.isEmpty(), "No author");
sane &= addGenericStructureLog(commandSender, (s, structure) -> structure.transformer.getTransformers().stream().allMatch(t -> t.id().length() > 0), "Transformer has empty ID");
sane &= addGenerationLog(commandSender, GenerationType.class, (structure, gen) -> gen.id().length() > 0, "Generation type has empty ID");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
}
if (sane && !parameters.has("silent"))
commandSender.sendMessage(new TextComponentString("No problems identified!"));
}
use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.
the class SpawnCommandLogic method trigger.
public void trigger(World worldIn) {
if (!worldIn.isRemote) {
MinecraftServer minecraftserver = this.getServer();
if (minecraftserver != null && minecraftserver.isAnvilFileSet() && minecraftserver.isCommandBlockEnabled()) {
ICommandManager icommandmanager = minecraftserver.getCommandManager();
ICommandListener cachedAdmin = null;
if (!RCConfig.notifyAdminOnBlockCommands) {
cachedAdmin = RCAccessorCommandBase.getCommandAdmin();
CommandBase.setCommandListener(null);
}
try {
icommandmanager.executeCommand(this, this.commandStored);
} catch (Exception ex) {
CrashReport crashreport = CrashReport.makeCrashReport(ex, "Executing command block");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Command to be executed");
crashreportcategory.addDetail("Command", this::getCommand);
crashreportcategory.addDetail("Name", this::getName);
throw new ReportedException(crashreport);
}
if (!RCConfig.notifyAdminOnBlockCommands)
CommandBase.setCommandListener(cachedAdmin);
}
}
}
use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.
the class MalmoMod method safeSendToAll.
public static void safeSendToAll(MalmoMessageType malmoMessage, Map<String, String> data) {
// network.sendToAll() is buggy - race conditions result in the message getting trashed if there is more than one client.
if (data == null) {
safeSendToAll(malmoMessage);
return;
}
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
for (Object player : server.getPlayerList().getPlayers()) {
if (player != null && player instanceof EntityPlayerMP) {
// Must construct a new message for each client:
Map<String, String> dataCopy = new HashMap<String, String>();
dataCopy.putAll(data);
network.sendTo(new MalmoMod.MalmoMessage(malmoMessage, 0, dataCopy), (EntityPlayerMP) player);
}
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundClaimGuiAbandonRequestPacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundClaimGuiAbandonRequestPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
final Claim claim = serverClaimManager.claimLookup(player, message.x, message.y, message.z, message.worldName);
if (claim != null) {
final boolean isOwner = (claim.getOwnerUniqueId().equals(player.getUniqueId()));
final boolean isAdmin = player.hasPermission(ServerClaimManager.adminPermission);
if (isOwner || isAdmin) {
this.serverClaimManager.abandonClaim(claim);
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Claim Abandoned!"), 5);
} else {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Insufficient Permissions!"), 5);
}
}
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundClaimGuiForSaleRequestPacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundClaimGuiForSaleRequestPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
final Claim claim = serverClaimManager.claimLookup(player, message.x, message.y, message.z, message.worldName);
if (claim != null) {
final boolean isOwner = (claim.getOwnerUniqueId().equals(player.getUniqueId()));
final boolean isAdmin = player.hasPermission(ServerClaimManager.adminPermission);
if (isOwner || isAdmin) {
this.serverClaimManager.setForSale(claim, message.setForSale, message.salePrice);
this.serverClaimManager.sendUpdateTo(player, claim, claim.getPlayers(), true, "requestClaimForSalePacket");
if (message.setForSale) {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Claim Listed For Sale!"), 5);
} else {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Claim Delisted!"), 5);
}
} else {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Insufficient Permissions!"), 5);
}
}
}
}
Aggregations