use of com.minecolonies.coremod.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.getIColonyByOwner(world, player);
if (colony != null && (!Configurations.limitToOneWareHousePerColony || !colony.hasWarehouse())) {
return true;
}
LanguageHandler.sendPlayerMessage(player, "tile.blockHut.warehouse.limit");
}
return false;
}
use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class TeleportToColony method colonyTeleport.
/**
* colonyTeleport is used with Home and Colony to teleport people to either
* there home. or to another colony, when you specified a colonyID.
*
* @param server the server instance.
* @param sender the player that is initiating the command.
* @param args this is the colony ID that the player wishes to TP to.
*/
@NotNull
public static void colonyTeleport(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) {
final EntityPlayer playerToTeleport;
final IColony colony;
final int colonyId;
//see if sent by a player and grab their name and Get the players Colony ID that sent the command
if (sender instanceof EntityPlayer) {
//if no args then this is a home colony TP and we get the players Colony ID
if (args.length == 0) {
playerToTeleport = (EntityPlayer) sender;
colony = ColonyManager.getIColonyByOwner(((EntityPlayer) sender).world, (EntityPlayer) sender);
colonyId = colony.getID();
} else {
//if there is args then this will be to a friends colony TP and we use the Colony ID they specify
//will need to see if they friendly to destination colony
playerToTeleport = (EntityPlayer) sender;
colonyId = Integer.valueOf(args[0]);
}
} else {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(CANT_FIND_PLAYER));
return;
}
if (MinecoloniesCommand.canExecuteCommand((EntityPlayer) sender)) {
teleportPlayer(playerToTeleport, colonyId, sender);
return;
}
sender.getCommandSenderEntity().sendMessage(new TextComponentString("Please wait at least " + Configurations.teleportBuffer + " seconds to teleport again"));
}
use of com.minecolonies.coremod.colony.IColony 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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
if (!isPlayerOpped(sender)) {
return;
}
int colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1) {
final String playerName = args[0];
if (playerName == null || playerName.isEmpty()) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player.getUniqueID());
colonyId = colony.getID();
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
return;
}
String playerName = null;
if (args.length >= 2) {
playerName = args[1];
}
if (playerName == null || playerName.isEmpty()) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
if (player == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
return;
}
if (ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player) != null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(String.format(HAS_A_COLONY, playerName)));
return;
}
colony.getPermissions().setOwner(player);
sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE, playerName, colonyId)));
}
use of com.minecolonies.coremod.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;
if (args.length == 0) {
IColony colony = null;
if (sender instanceof EntityPlayer) {
colony = ColonyManager.getIColonyByOwner(((EntityPlayer) sender).world, (EntityPlayer) sender);
}
if (colony == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
colonyId = colony.getID();
} else {
colonyId = getIthArgument(args, 0, -1);
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE_ID));
return;
}
if (sender instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, DELETECOLONY, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
server.addScheduledTask(() -> ColonyManager.deleteColony(colony.getID()));
}
use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class RefreshColonyCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int colonyId;
colonyId = getIthArgument(args, 0, -1);
IColony tempColony = ColonyManager.getColony(colonyId);
if (colonyId == -1 && args.length >= 1) {
final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
if (player != null) {
tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
}
}
if (sender instanceof EntityPlayer) {
final UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
if (tempColony == null) {
tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, Commands.REFRESH_COLONY, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
if (tempColony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE_ID, colonyId)));
}
return;
}
final Colony colony = ColonyManager.getColony(tempColony.getID());
if (colony == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE_ID));
return;
}
sender.getCommandSenderEntity().sendMessage(new TextComponentString(REFRESH));
colony.getPermissions().restoreOwnerIfNull();
}
Aggregations