// TODO: Add condition check public boolean checkEntity(Entity entity) { for (SegmentEntity segment : segmentsEntities) { if (segment.getCheckClass().isAssignableFrom(entity.getClass())) { if (segment.getType() == EntityType.TRACKED) { if (segment.checkCondition(entity)) { int range = segment.getRange(entity); Resident owner = segment.getOwner(entity); int dim = entity.dimension; int x = (int) Math.floor(entity.posX); int y = (int) Math.floor(entity.posY); int z = (int) Math.floor(entity.posZ); if (range == 0) { if (!hasPermission(owner, segment, dim, x, y, z)) { return true; } } else { Volume rangeBox = new Volume(x - range, y - range, z - range, x + range, y + range, z + range); if (!hasPermission(owner, segment, dim, rangeBox)) { return true; } } } } } } return false; }
/** Checking item usage for right click on air */ public boolean checkItem(ItemStack item, Resident res) { for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) { SegmentItem segment = it.next(); if (segment.getType() == ItemType.RIGHT_CLICK_AIR && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) { EntityPlayer entity = res.getPlayer(); try { if (segment.checkCondition(item)) { int range = segment.getRange(item); int dim = entity.dimension; int x = (int) Math.floor(entity.posX); int y = (int) Math.floor(entity.posY); int z = (int) Math.floor(entity.posZ); if (range == 0) { if (!hasPermission(res, segment, dim, x, y, z)) { return true; } } else { Volume rangeBox = new Volume(x - range, y - range, z - range, x + range, y + range, z + range); if (!hasPermission(res, segment, dim, rangeBox)) { return true; } } } } catch (Exception ex) { MyTown.instance.LOG.error( "Failed to check item use on {} at the player {} ({}, {}, {} | Dim: {})", item.getDisplayName(), res.getPlayerName(), entity.posX, entity.posY, entity.posZ, entity.dimension); if (ex instanceof GetterException || ex instanceof ConditionException) { this.disableSegment(it, segment, ex.getMessage()); } } } } return false; }
public static boolean check(Entity entity) { if (entity instanceof EntityLiving) { if (!getFlagValueAtLocation( FlagType.ENTITIES, entity.dimension, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY), (int) Math.floor(entity.posZ))) { entity.setDead(); return true; } } for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) { if (!segment.shouldExist(entity)) { entity.setDead(); return true; } } return false; }
public static void check(EntityPlayerMP player) { Town town = MyTownUtils.getTownAtPosition( player.dimension, (int) Math.floor(player.posX) >> 4, (int) Math.floor(player.posZ) >> 4); Resident res = MyTownUniverse.instance.getOrMakeResident(player); EntityPos lastTickPos = lastTickPlayerPos.get(player); if (res == null) { return; } if (!ProtectionManager.hasPermission( res, FlagType.ENTER, player.dimension, (int) Math.floor(player.posX), (int) Math.floor(player.posY), (int) Math.floor(player.posZ))) { if (lastTickPos == null) { res.knockbackPlayerToBorder(town); } else if (lastTickPos.getX() != player.posX || lastTickPos.getY() != player.posY || lastTickPos.getZ() != player.posZ || lastTickPos.getDim() != player.dimension) { PlayerUtils.teleport( player, lastTickPos.getDim(), lastTickPos.getX(), lastTickPos.getY(), lastTickPos.getZ()); } } else { // TODO: Refactor so that it's understandable if (lastTickPos != null && (((int) Math.floor(lastTickPos.getX())) >> 4 != (int) (Math.floor(player.posX)) >> 4 || ((int) Math.floor(lastTickPos.getZ())) >> 4 != (int) (Math.floor(player.posZ)) >> 4)) { if (lastTickPos.getDim() == player.dimension) { res.checkLocation( ((int) Math.floor(lastTickPos.getX())) >> 4, ((int) Math.floor(lastTickPos.getZ())) >> 4, ((int) Math.floor(player.posX)) >> 4, ((int) (Math.floor(player.posZ))) >> 4, player.dimension); } else { res.checkLocationOnDimensionChanged( (int) (Math.floor(player.posX)), (int) (Math.floor(player.posZ)), player.dimension); } } if (lastTickPos != null && town != null) { Plot currentPlot = town.plotsContainer.get( player.dimension, (int) Math.floor(player.posX), (int) Math.floor(player.posY), (int) Math.floor(player.posZ)); Plot lastTickPlot = town.plotsContainer.get( lastTickPos.getDim(), (int) Math.floor(lastTickPos.getX()), (int) Math.floor(lastTickPos.getY()), (int) Math.floor(lastTickPos.getZ())); if (currentPlot != null && (lastTickPlot == null || currentPlot != lastTickPlot)) { res.sendMessage( MyTown.instance.LOCAL.getLocalization( "mytown.notification.plot.enter", currentPlot.getName())); } else if (currentPlot == null && lastTickPlot != null) { res.sendMessage( MyTown.instance.LOCAL.getLocalization( "mytown.notification.plot.enter", EnumChatFormatting.RED + "Unassigned")); } } lastTickPlayerPos.put( player, new EntityPos(player.posX, player.posY, player.posZ, player.dimension)); } }