use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class AddOfficerCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
if (args.length == 0) {
sender.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
return;
}
final Entity senderEntity = sender.getCommandSenderEntity();
int colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1 && senderEntity instanceof EntityPlayer) {
final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
if (colony == null) {
senderEntity.sendMessage(new TextComponentString(COLONY_X_NULL));
return;
}
colonyId = colony.getID();
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_X_NULL, colonyId)));
return;
}
String playerName = null;
if (args.length >= 2) {
playerName = args[1];
}
if (playerName == null || playerName.isEmpty()) {
playerName = sender.getName();
}
executeShared(server, sender, colony, playerName);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ChangeColonyOwnerCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
if (args.length < 2) {
sender.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
return;
}
int colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1) {
final String playerName = args[0];
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
final Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity == null) {
server.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
return;
} else {
if (playerName == null || playerName.isEmpty() || player == null) {
senderEntity.sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player.getUniqueID());
if (colony == null) {
return;
}
colonyId = colony.getID();
}
}
String playerName = null;
if (args.length >= 2) {
playerName = args[1];
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_X_NULL, colonyId)));
return;
}
if (playerName == null || playerName.isEmpty()) {
sender.sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
executeShared(server, sender, colony, player);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ChangeColonyOwnerCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
final Colony colony = actionMenu.getColonyForArgument("colony");
final EntityPlayer player = actionMenu.getPlayerForArgument("player");
executeShared(server, sender, colony, player);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* ExplosionEvent.Detonate handler.
*
* @param event ExplosionEvent.Detonate
*/
@SubscribeEvent
public void on(final ExplosionEvent.Detonate event) {
if (!Configurations.gameplay.enableColonyProtection || !Configurations.gameplay.turnOffExplosionsInColonies) {
return;
}
final World eventWorld = event.getWorld();
final Predicate<BlockPos> getBlocksInColony = pos -> colony.isCoordInColony(eventWorld, pos);
final Predicate<Entity> getEntitiesInColony = entity -> colony.isCoordInColony(entity.getEntityWorld(), entity.getPosition());
// if block is in colony -> remove from list
final List<BlockPos> blocksToRemove = event.getAffectedBlocks().stream().filter(getBlocksInColony).collect(Collectors.toList());
// if entity is in colony -> remove from list
final List<Entity> entitiesToRemove = event.getAffectedEntities().stream().filter(getEntitiesInColony).collect(Collectors.toList());
event.getAffectedBlocks().removeAll(blocksToRemove);
event.getAffectedEntities().removeAll(entitiesToRemove);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class StructureWrapper method handleBlockPlacement.
private void handleBlockPlacement(final BlockPos pos, final IBlockState localState, final boolean complete) {
for (final IPlacementHandler handlers : PlacementHandlers.handlers) {
final Object result = handlers.handle(world, pos, localState, null, true, complete);
if (result instanceof IBlockState) {
final IBlockState blockState = (IBlockState) result;
final Colony colony = ColonyManager.getColony(world, pos);
if (colony != null) {
final AbstractBuilding building = colony.getBuildingManager().getBuilding(position);
if (building != null) {
building.registerBlockPosition(blockState, pos, world);
}
}
return;
} else if (!(result instanceof IPlacementHandler.ActionProcessingResult) || result != IGNORE) {
return;
}
}
}
Aggregations