use of com.minecolonies.api.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 ActionMenu actionMenu) throws CommandException {
Colony colony = actionMenu.getColonyForArgument("colony");
if (null == colony) {
final EntityPlayer player = actionMenu.getPlayerForArgument("player");
if (null != player) {
IColony iColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
if (null == iColony) {
if (sender instanceof EntityPlayer) {
final Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity != null) {
final UUID mayorID = senderEntity.getUniqueID();
iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
}
}
if (null != iColony) {
colony = ColonyManager.getColony(iColony.getID());
}
}
}
if (colony == null) {
sender.sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE));
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.api.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 {
final 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 Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity == null) {
return;
}
final UUID mayorID = senderEntity.getUniqueID();
if (tempColony == null) {
tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
}
if (tempColony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_PLAYER_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
}
return;
}
final Colony colony = ColonyManager.getColony(tempColony.getID());
if (colony == null) {
sender.sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE));
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class AbstractCitizensCommands method execute.
@NotNull
@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;
}
boolean firstArgumentColonyId = true;
int colonyId = -1;
if (args.length >= 2) {
colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1) {
final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
if (player != null) {
final IColony tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
if (tempColony != null) {
colonyId = tempColony.getID();
}
}
firstArgumentColonyId = false;
}
}
final Colony colony;
if (sender instanceof EntityPlayer && colonyId == -1) {
final IColony tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
if (tempColony != null) {
colonyId = tempColony.getID();
firstArgumentColonyId = false;
}
}
colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
if (sender instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
player.sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
if (citizenId == -1 || colony.getCitizenManager().getCitizen(citizenId) == null) {
sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
executeSpecializedCode(server, sender, colony, citizenId);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class ListCitizensCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int colonyId = getIthArgument(args, 0, getColonyId(sender));
final Integer page = getIthArgument(args, 1, 1);
Colony colony = null;
if (sender instanceof EntityPlayer) {
if (colonyId == -1) {
final IColony icolony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
if (icolony != null) {
colonyId = icolony.getID();
}
}
}
colony = ColonyManager.getColony(colonyId);
executeShared(server, sender, colony, page);
}
use of com.minecolonies.api.colony.IColony 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);
}
Aggregations