use of com.minecolonies.coremod.colony.permissions.Permissions in project minecolonies by Minecolonies.
the class Colony method sendPermissionsPackets.
/**
* Sends packages to update the permissions.
*
* @param oldSubscribers the existing subscribers.
* @param hasNewSubscribers the new subscribers.
*/
private void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
if (permissions.isDirty() || hasNewSubscribers) {
subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
final Rank rank = getPermissions().getRank(player);
MineColonies.getNetwork().sendTo(new PermissionsMessage.View(this, rank), player);
});
}
}
use of com.minecolonies.coremod.colony.permissions.Permissions in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* AttackEntityEvent handler.
* <p>
* Check, if a player tries to attack an entity..
* Deny if:
* - If the attacking happens in the colony
* - Player is less than officer to the colony.
*
* @param event EntityItemPickupEvent
*/
@SubscribeEvent
public void on(final AttackEntityEvent event) {
if (event.getTarget() instanceof EntityMob) {
return;
}
@NotNull final EntityPlayer player = EntityUtils.getPlayerOfFakePlayer(event.getEntityPlayer(), event.getEntityPlayer().getEntityWorld());
if (Configurations.gameplay.enableColonyProtection && colony.isCoordInColony(player.getEntityWorld(), player.getPosition())) {
final Permissions perms = colony.getPermissions();
if (event.getTarget() instanceof EntityCitizen) {
final EntityCitizen citizen = (EntityCitizen) event.getTarget();
if (citizen.getColonyJob() instanceof JobGuard && perms.hasPermission(event.getEntityPlayer(), Action.GUARDS_ATTACK)) {
return;
}
if (perms.hasPermission(event.getEntityPlayer(), Action.ATTACK_CITIZEN)) {
return;
}
cancelEvent(event, event.getEntityPlayer(), colony, Action.ATTACK_CITIZEN, event.getTarget().getPosition());
return;
}
if (!(event.getTarget() instanceof EntityMob) && !perms.hasPermission(event.getEntityPlayer(), Action.ATTACK_ENTITY)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.ATTACK_ENTITY, event.getTarget().getPosition());
}
}
}
use of com.minecolonies.coremod.colony.permissions.Permissions in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block.
* Deny if:
* - If the block is in colony
* - block is AbstractBlockHut
* - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (Configurations.gameplay.enableColonyProtection) {
if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && block != null && block != Blocks.AIR) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.RIGHTCLICK_BLOCK, event.getPos());
return;
}
if (block instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.RIGHTCLICK_ENTITY, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem() instanceof ItemFood) {
return;
}
if (stack.getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.THROW_POTION, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getEntityPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
return;
}
}
}
}
use of com.minecolonies.coremod.colony.permissions.Permissions in project minecolonies by Minecolonies.
the class PermissionUtils method getPlayersWithAtLeastRank.
/**
* Creates a list of players that have the given rank or higher.
* <p>
* This is using the enums ordinal method for comparison.
*
* @param colony The colony to get the players
* @param rank The rank to check
* @return The list with online players that has the rank or higher
*/
@NotNull
public static List<Player> getPlayersWithAtLeastRank(@NotNull final Colony colony, @NotNull final Rank rank) {
@NotNull final List<Player> playersWithAtLeastRank = new ArrayList<>();
@NotNull final Permissions permissions = colony.getPermissions();
@NotNull final Map<UUID, Player> players = permissions.getPlayers();
for (@NotNull final Player player : players.values()) {
if (player.getRank().ordinal() <= rank.ordinal()) {
playersWithAtLeastRank.add(player);
}
}
return playersWithAtLeastRank;
}
use of com.minecolonies.coremod.colony.permissions.Permissions in project minecolonies by Minecolonies.
the class ColonyPackageManager method sendPermissionsPackets.
@Override
public void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
final Permissions permissions = colony.getPermissions();
if (permissions.isDirty() || hasNewSubscribers || colony.getWorld().rand.nextInt(CHANCE_TO_UPDATE) <= 1) {
subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
final Rank rank = permissions.getRank(player);
MineColonies.getNetwork().sendTo(new PermissionsMessage.View(colony, rank), player);
});
}
}
Aggregations