Пример #1
0
 /** Gets the flags which the type of TileEntity is checked against. */
 public List<FlagType> getFlagsForTile(Class<? extends TileEntity> te) {
   List<FlagType> flags = new ArrayList<FlagType>();
   for (SegmentTileEntity segment : segmentsTiles) {
     if (segment.getCheckClass().isAssignableFrom(te)) flags.add(segment.getFlag());
   }
   return flags;
 }
Пример #2
0
    private SegmentTileEntity deserializeTileEntity(
        JsonObject json, JsonDeserializationContext context) {
      SegmentTileEntity segment = new SegmentTileEntity();

      segment.retainsOwner = json.getAsJsonObject().get("retainsOwner").getAsBoolean();
      json.remove("retainsOwner");

      return segment;
    }
Пример #3
0
  public static boolean isOwnable(Class<? extends TileEntity> clazz) {
    for (SegmentTileEntity segment : segmentsTile.get(clazz)) {
      if (segment.retainsOwner()) {
        return true;
      }
    }

    return false;
  }
Пример #4
0
 public static void check(TileEntity te) {
   for (SegmentTileEntity segment : segmentsTile.get(te.getClass())) {
     if (!segment.shouldExist(te)) {
       ItemStack itemStack = new ItemStack(te.getBlockType(), 1, te.getBlockMetadata());
       NBTTagCompound nbt = new NBTTagCompound();
       te.writeToNBT(nbt);
       itemStack.setTagCompound(nbt);
       WorldUtils.dropAsEntity(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, itemStack);
       te.getWorldObj().setBlock(te.xCoord, te.yCoord, te.zCoord, Blocks.air);
       te.invalidate();
       MyTown.instance.LOG.info("TileEntity {} was ATOMICALLY DISINTEGRATED!", te.toString());
       return;
     }
   }
 }
Пример #5
0
 public boolean checkTileEntity(TileEntity te) {
   for (Iterator<SegmentTileEntity> it = segmentsTiles.iterator(); it.hasNext(); ) {
     SegmentTileEntity segment = it.next();
     if (segment.getCheckClass().isAssignableFrom(te.getClass())) {
       try {
         if (segment.checkCondition(te)) {
           Volume teBox =
               new Volume(
                   segment.getX1(te),
                   segment.getY1(te),
                   segment.getZ1(te),
                   segment.getX2(te),
                   segment.getY2(te),
                   segment.getZ2(te));
           int dim = te.getWorldObj().provider.dimensionId;
           Resident owner =
               segment.hasOwner() ? Protections.instance.getOwnerForTileEntity(te) : null;
           if (!hasPermission(owner, segment, dim, teBox)) {
             return true;
           }
         }
       } catch (Exception ex) {
         MyTown.instance.LOG.error(
             "Failed to check tile entity: {} ({}, {}, {}, Dim: {})",
             te.getClass().getSimpleName(),
             te.xCoord,
             te.yCoord,
             te.zCoord,
             te.getWorldObj().provider.dimensionId);
         MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
         // Disabling protection if something errors.
         if (ex instanceof GetterException || ex instanceof ConditionException) {
           this.disableSegment(it, segment, ex.getMessage());
         } else {
           MyTown.instance.LOG.error("Skipping...");
         }
       }
       return false;
     }
   }
   return false;
 }
Пример #6
0
 public boolean isTileEntityOwnable(Class<? extends TileEntity> te) {
   for (SegmentTileEntity segment : segmentsTiles) {
     if (segment.getCheckClass().isAssignableFrom(te) && segment.hasOwner()) return true;
   }
   return false;
 }