use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by ldtteam.
the class AbstractBuildingGuards method getRallyLocation.
@Override
@Nullable
public ILocation getRallyLocation() {
if (rallyLocation == null) {
return null;
}
boolean outOfRange = false;
final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
outOfRange = true;
}
if (rallyLocation instanceof EntityLocation) {
final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
if (player == null) {
setRallyLocation(null);
return null;
}
if (outOfRange) {
LanguageHandler.sendPlayerMessage(player, "item.minecolonies.banner_rally_guards.outofrange");
setRallyLocation(null);
return null;
}
final int size = player.inventory.getContainerSize();
for (int i = 0; i < size; i++) {
final ItemStack stack = player.inventory.getItem(i);
if (stack.getItem() instanceof ItemBannerRallyGuards) {
if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
return rallyLocation;
}
}
}
// if the user moves the banner around in the inventory.
return null;
}
return rallyLocation;
}
use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by ldtteam.
the class EventHandler method onPlayerEnterWorld.
/**
* Event called when a player enters the world.
*
* @param event player enter world event
*/
@SubscribeEvent
public static void onPlayerEnterWorld(final PlayerEvent.PlayerLoggedInEvent event) {
if (event.getPlayer() instanceof ServerPlayerEntity) {
final ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
for (final IColony colony : IColonyManager.getInstance().getAllColonies()) {
if (colony.getPermissions().hasPermission(player, Action.CAN_KEEP_COLONY_ACTIVE_WHILE_AWAY) || colony.getPermissions().hasPermission(player, Action.RECEIVE_MESSAGES_FAR_AWAY)) {
colony.getPackageManager().addImportantColonyPlayer(player);
}
}
// Add visiting/subscriber to colony we're logging into
final Chunk chunk = (Chunk) player.level.getChunk(new BlockPos(player.position()));
final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (cap != null && cap.getOwningColony() != 0) {
IColony colony = IColonyManager.getInstance().getColonyByDimension(cap.getOwningColony(), player.level.dimension());
if (colony != null) {
colony.addVisitingPlayer(player);
colony.getPackageManager().addCloseSubscriber(player);
}
}
final int size = player.inventory.getContainerSize();
for (int i = 0; i < size; i++) {
final ItemStack stack = player.inventory.getItem(i);
if (stack.getItem() instanceof ItemBannerRallyGuards) {
ItemBannerRallyGuards.broadcastPlayerToRally(stack, player.getLevel(), player);
}
}
IGlobalResearchTree.getInstance().sendGlobalResearchTreePackets((ServerPlayerEntity) event.getPlayer());
CustomRecipeManager.getInstance().sendCustomRecipeManagerPackets((ServerPlayerEntity) event.getPlayer());
}
}
use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by Minecolonies.
the class AbstractBuildingGuards method getRallyLocation.
@Override
@Nullable
public ILocation getRallyLocation() {
if (rallyLocation == null) {
return null;
}
boolean outOfRange = false;
final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
outOfRange = true;
}
if (rallyLocation instanceof EntityLocation) {
final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
if (player == null) {
setRallyLocation(null);
return null;
}
if (outOfRange) {
MessageUtils.format(WARNING_RALLYING_POINT_OUT_OF_RANGE).sendTo(player);
setRallyLocation(null);
return null;
}
final int size = player.inventory.getContainerSize();
for (int i = 0; i < size; i++) {
final ItemStack stack = player.inventory.getItem(i);
if (stack.getItem() instanceof ItemBannerRallyGuards) {
if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
return rallyLocation;
}
}
}
// if the user moves the banner around in the inventory.
return null;
}
return rallyLocation;
}
use of com.minecolonies.coremod.items.ItemBannerRallyGuards in project minecolonies by Minecolonies.
the class EventHandler method onPlayerEnterWorld.
/**
* Event called when a player enters the world.
*
* @param event player enter world event
*/
@SubscribeEvent
public static void onPlayerEnterWorld(final PlayerEvent.PlayerLoggedInEvent event) {
if (event.getPlayer() instanceof ServerPlayerEntity) {
final ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
for (final IColony colony : IColonyManager.getInstance().getAllColonies()) {
if (colony.getPermissions().hasPermission(player, Action.CAN_KEEP_COLONY_ACTIVE_WHILE_AWAY) || colony.getPermissions().hasPermission(player, Action.RECEIVE_MESSAGES_FAR_AWAY)) {
colony.getPackageManager().addImportantColonyPlayer(player);
}
}
// Add visiting/subscriber to colony we're logging into
final Chunk chunk = (Chunk) player.level.getChunk(new BlockPos(player.position()));
final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (cap != null && cap.getOwningColony() != 0) {
IColony colony = IColonyManager.getInstance().getColonyByDimension(cap.getOwningColony(), player.level.dimension());
if (colony != null) {
colony.addVisitingPlayer(player);
colony.getPackageManager().addCloseSubscriber(player);
}
}
final int size = player.inventory.getContainerSize();
for (int i = 0; i < size; i++) {
final ItemStack stack = player.inventory.getItem(i);
if (stack.getItem() instanceof ItemBannerRallyGuards) {
ItemBannerRallyGuards.broadcastPlayerToRally(stack, player.getLevel(), player);
}
}
IGlobalResearchTree.getInstance().sendGlobalResearchTreePackets((ServerPlayerEntity) event.getPlayer());
CustomRecipeManager.getInstance().sendCustomRecipeManagerPackets((ServerPlayerEntity) event.getPlayer());
}
}
Aggregations