use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class EventHandler method onWareHousePlaced.
private static boolean onWareHousePlaced(final World world, final EntityPlayer player, final BlockPos pos) {
if (onBlockHutPlaced(world, player, pos)) {
final IColony colony = ColonyManager.getClosestIColony(world, pos);
if (colony != null && (!Configurations.gameplay.limitToOneWareHousePerColony || !colony.hasWarehouse())) {
return true;
}
LanguageHandler.sendPlayerMessage(player, "tile.blockHut.warehouse.limit");
}
return false;
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class ShowColonyInfoCommand method execute.
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
// See if we have a valid colony,
Colony colony = actionMenu.getColonyForArgument("colony");
EntityPlayer player = null;
if (null == colony) {
// see if we have a valid player
player = actionMenu.getPlayerForArgument("player");
if (null != player) {
final IColony iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player);
if (iColony != null) {
if (!canPlayerUseCommand(player, SHOWCOLONYINFO, iColony.getID())) {
sender.sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
colony = ColonyManager.getColony(iColony.getID());
}
}
}
if (null == colony) {
// see if we have a sender that is a valid player
if (sender instanceof EntityPlayer) {
player = (EntityPlayer) sender;
final UUID mayorID = player.getUniqueID();
final IColony iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
if (iColony != null) {
if (!canPlayerUseCommand(player, SHOWCOLONYINFO, iColony.getID())) {
sender.sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
colony = ColonyManager.getColony(iColony.getID());
}
}
}
if (colony == null) {
if (null != player) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, player.getName())));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE)));
}
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class RSResetCommand 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_ARGUMENTS));
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_NULL));
return;
}
colonyId = colony.getID();
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class WhereAmICommand method executeShared.
private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender) throws CommandException {
if (!(sender instanceof EntityPlayer)) {
Log.getLogger().info("In the console...");
return;
}
final BlockPos playerPos = sender.getPosition();
final IColony colony = ColonyManager.getClosestColony(server.getEntityWorld(), playerPos);
if (colony == null) {
sender.sendMessage(new TextComponentString(NONE));
return;
}
final BlockPos center = colony.getCenter();
final double distance = BlockPosUtil.getDistanceSquared(center, new BlockPos(playerPos.getX(), center.getY(), playerPos.getZ()));
if (!ColonyManager.isTooCloseToColony(sender.getEntityWorld(), playerPos)) {
sender.sendMessage(new TextComponentString(String.format(NONE_CLOSE, Math.sqrt(distance))));
return;
}
final String colonyName = colony.getName();
final String id = Integer.toString(colony.getID());
sender.sendMessage(new TextComponentString(String.format(INSIDE, colonyName, id, Math.sqrt(distance))));
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class DeleteColonyCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
final int colonyId;
boolean canDestroy = true;
boolean confirmDelete = false;
if (args.length == 0) {
IColony colony = null;
if (sender instanceof EntityPlayer) {
colony = ColonyManager.getIColonyByOwner(CompatibilityUtils.getWorld((EntityPlayer) sender), (EntityPlayer) sender);
}
if (colony == null) {
sender.sendMessage(new TextComponentString(NO_COLONY_MESSAGE));
return;
}
colonyId = colony.getID();
} else {
colonyId = getIthArgument(args, 0, -1);
if (args.length > 1) {
canDestroy = Boolean.parseBoolean(args[1]);
}
if (args.length > 2) {
confirmDelete = Boolean.parseBoolean(args[2]);
}
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
final String noColonyFoundMessage = String.format(COLONY_X_NULL, colonyId);
sender.sendMessage(new TextComponentString(noColonyFoundMessage));
return;
}
executeShared(server, sender, colony, canDestroy, confirmDelete);
}
Aggregations