use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class EventHandler method onPlayerInteract.
/**
* Event when a player right clicks a block, or right clicks with an item.
* Event gets cancelled when player has no permission. Event gets cancelled
* when the player has no permission to place a hut, and tried it.
*
* @param event {@link PlayerInteractEvent.RightClickBlock}
*/
@SubscribeEvent
public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
final EntityPlayer player = event.getEntityPlayer();
final World world = event.getWorld();
//Only execute for the main hand our colony events.
if (event.getHand() == EnumHand.MAIN_HAND && !(event.getWorld().isRemote)) {
// and uses that return value, but I didn't want to call it twice
if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
final IColony colony = ColonyManager.getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
}
return;
} else if (event.getEntityPlayer() != null && "pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && event.getItemStack() != null && Block.getBlockFromItem(event.getItemStack().getItem()) instanceof BlockSilverfish) {
LanguageHandler.sendPlayerMessage(event.getEntityPlayer(), "Stop that you twat!!!");
event.setCanceled(true);
}
if (player.getHeldItemMainhand() == null || player.getHeldItemMainhand().getItem() == null) {
return;
}
handleEventCancellation(event, player);
}
}
use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class EventHandler method onDebugOverlay.
/**
* Event when the debug screen is opened. Event gets called by displayed
* text on the screen, we only need it when f3 is clicked.
*
* @param event {@link net.minecraftforge.client.event.RenderGameOverlayEvent.Text}
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onDebugOverlay(final RenderGameOverlayEvent.Text event) {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.gameSettings.showDebugInfo) {
final WorldClient world = mc.world;
final EntityPlayerSP player = mc.player;
IColony colony = ColonyManager.getIColony(world, player.getPosition());
final double minDistance = ColonyManager.getMinimumDistanceBetweenTownHalls();
if (colony == null) {
colony = ColonyManager.getClosestIColony(world, player.getPosition());
if (colony == null || Math.sqrt(colony.getDistanceSquared(player.getPosition())) > 2 * minDistance) {
event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.noCloseColony"));
return;
}
event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.nextColony", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition())), minDistance));
return;
}
event.getLeft().add(colony.getName() + " : " + LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.blocksFromCenter", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition()))));
}
}
}
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) {
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);
}
use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class ShowColonyInfoCommand 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);
}
if (tempColony != null) {
colonyId = tempColony.getID();
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, SHOWCOLONYINFO, 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) {
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 BlockPos position = colony.getCenter();
sender.sendMessage(new TextComponentString(ID_TEXT + colony.getID() + NAME_TEXT + colony.getName()));
final String mayor = colony.getPermissions().getOwnerName();
sender.sendMessage(new TextComponentString(MAYOR_TEXT + mayor));
sender.sendMessage(new TextComponentString(CITIZENS + colony.getCitizens().size() + "/" + colony.getMaxCitizens()));
sender.sendMessage(new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
sender.sendMessage(new TextComponentString(String.format(LAST_CONTACT_TEXT, colony.getLastContactInHours())));
}
use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.
the class EventHandler method onTownHallPlaced.
static boolean onTownHallPlaced(@NotNull final World world, @NotNull final EntityPlayer player, final BlockPos pos) {
IColony colony = ColonyManager.getIColonyByOwner(world, player);
if (colony != null) {
return canOwnerPlaceTownHallHere(world, player, colony, pos);
}
colony = ColonyManager.getClosestIColony(world, pos);
if (colony == null) {
return true;
}
// Town Halls must be far enough apart
return canPlayerPlaceTownHallHere(world, player, pos, colony);
}
Aggregations