use of com.minecolonies.coremod.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));
if (sender instanceof EntityPlayer) {
if (colonyId == -1) {
IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
if (colony != null) {
colonyId = colony.getID();
}
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, LISTCITIZENS, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
return;
}
}
final Colony colony = ColonyManager.getColony(colonyId);
final List<CitizenData> citizens = new ArrayList<>(colony.getCitizens().values());
final int citizenCount = citizens.size();
// check to see if we have to add one page to show the half page
int page = getIthArgument(args, 1, 1);
final int halfPage = (citizenCount % CITIZENS_ON_PAGE == 0) ? 0 : 1;
final int pageCount = ((citizenCount) / CITIZENS_ON_PAGE) + halfPage;
if (page < 1 || page > pageCount) {
page = 1;
}
final int pageStartIndex = CITIZENS_ON_PAGE * (page - 1);
final int pageStopIndex = Math.min(CITIZENS_ON_PAGE * page, citizenCount);
final List<CitizenData> citizensPage;
if (pageStartIndex < 0 || pageStartIndex >= citizenCount) {
citizensPage = new ArrayList<>();
} else {
citizensPage = citizens.subList(pageStartIndex, pageStopIndex);
}
final ITextComponent headerLine = new TextComponentString(String.format(PAGE_TOP, page, pageCount));
sender.sendMessage(headerLine);
for (final CitizenData citizen : citizensPage) {
sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizen.getId(), citizen.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO, citizen.getColony().getID(), citizen.getId())))));
if (citizen.getCitizenEntity() != null) {
final BlockPos position = citizen.getCitizenEntity().getPosition();
sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
}
}
drawPageSwitcher(sender, page, citizenCount, halfPage, colonyId);
}
use of com.minecolonies.coremod.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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
int colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1 && sender instanceof EntityPlayer) {
final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
if (colony == null) {
sender.getCommandSenderEntity().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;
}
if (sender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, ADDOFFICER, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
String playerName = null;
if (args.length >= 2) {
playerName = args[1];
}
if (playerName == null || playerName.isEmpty()) {
playerName = sender.getName();
}
colony.getPermissions().addPlayer(playerName, Rank.OFFICER, colony.getWorld());
sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE, playerName, colonyId)));
}
use of com.minecolonies.coremod.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.getCommandSenderEntity().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) {
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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
if (sender instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
if (citizenId == -1 || colony.getCitizen(citizenId) == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
executeSpecializedCode(server, sender, colony, citizenId);
}
Aggregations