@EventHandler(ignoreCancelled = true)
 public void onBlockPlace(BlockPlaceEvent event) {
   Player p = event.getPlayer();
   if (!p.getGameMode().equals(GameMode.CREATIVE)) {
     return;
   }
   Material mat = event.getBlock().getType();
   if (plugin.getConfig().getBoolean("creative_blacklist")
       && plugin.getBlackList().contains(mat)
       && !GameModeInventoriesBypass.canBypass(p, "blacklist", plugin)) {
     event.setCancelled(true);
     if (!plugin.getConfig().getBoolean("dont_spam_chat")) {
       p.sendMessage(
           plugin.MY_PLUGIN_NAME
               + String.format(
                   plugin.getM().getMessage().get("NO_CREATIVE_PLACE"), mat.toString()));
     }
     return;
   }
   if (plugin.getConfig().getBoolean("track_creative_place.enabled")) {
     Block block = event.getBlock();
     if (!plugin
         .getConfig()
         .getStringList("track_creative_place.worlds")
         .contains(block.getWorld().getName())) {
       return;
     }
     if (plugin.getNoTrackList().contains(mat)) {
       String gmiwc =
           block.getWorld().getName()
               + ","
               + block.getChunk().getX()
               + ","
               + block.getChunk().getZ();
       if (!plugin.getCreativeBlocks().containsKey(gmiwc)
           || !plugin.getCreativeBlocks().get(gmiwc).contains(block.getLocation().toString())) {
         plugin.getBlock().addBlock(gmiwc, block.getLocation().toString());
       }
     }
   }
 }
示例#2
0
 PerformResult perform() throws WorldEditorException {
   if (dontRollback.contains(replaced)) return PerformResult.BLACKLISTED;
   final Block block = loc.getBlock();
   if (replaced == 0 && block.getTypeId() == 0) return PerformResult.NO_ACTION;
   final BlockState state = block.getState();
   if (!world.isChunkLoaded(block.getChunk())) world.loadChunk(block.getChunk());
   if (type == replaced) {
     if (type == 0) {
       if (!block.setTypeId(0))
         throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
     } else if (ca != null && (type == 23 || type == 54 || type == 61 || type == 62)) {
       int leftover = 0;
       try {
         leftover =
             modifyContainer(
                 state, new ItemStack(ca.itemType, -ca.itemAmount, (short) 0, ca.itemData));
         if (leftover > 0)
           for (final BlockFace face :
               new BlockFace[] {
                 BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST
               })
             if (block.getRelative(face).getTypeId() == 54)
               leftover =
                   modifyContainer(
                       block.getRelative(face).getState(),
                       new ItemStack(
                           ca.itemType,
                           ca.itemAmount < 0 ? leftover : -leftover,
                           (short) 0,
                           ca.itemData));
       } catch (final Exception ex) {
         throw new WorldEditorException(ex.getMessage(), block.getLocation());
       }
       if (!state.update())
         throw new WorldEditorException(
             "Failed to update inventory of " + materialName(block.getTypeId()),
             block.getLocation());
       if (leftover > 0 && ca.itemAmount < 0)
         throw new WorldEditorException(
             "Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
     } else return PerformResult.NO_ACTION;
     return PerformResult.SUCCESS;
   }
   if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId())))
     return PerformResult.NO_ACTION;
   if (state instanceof InventoryHolder) {
     ((InventoryHolder) state).getInventory().clear();
     state.update();
   }
   if (block.getTypeId() == replaced) {
     if (block.getData() != (type == 0 ? data : (byte) 0))
       block.setData(type == 0 ? data : (byte) 0, true);
     else return PerformResult.NO_ACTION;
   } else if (!block.setTypeIdAndData(replaced, type == 0 ? data : (byte) 0, true))
     throw new WorldEditorException(block.getTypeId(), replaced, block.getLocation());
   final int curtype = block.getTypeId();
   if (signtext != null && (curtype == 63 || curtype == 68)) {
     final Sign sign = (Sign) block.getState();
     final String[] lines = signtext.split("\0", 4);
     if (lines.length < 4) return PerformResult.NO_ACTION;
     for (int i = 0; i < 4; i++) sign.setLine(i, lines[i]);
     if (!sign.update())
       throw new WorldEditorException(
           "Failed to update signtext of " + materialName(block.getTypeId()),
           block.getLocation());
   } else if (curtype == 26) {
     final Bed bed = (Bed) block.getState().getData();
     final Block secBlock =
         bed.isHeadOfBed()
             ? block.getRelative(bed.getFacing().getOppositeFace())
             : block.getRelative(bed.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(26, (byte) (bed.getData() | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), 26, secBlock.getLocation());
   } else if (curtype == 64 || curtype == 71) {
     final byte blockData = block.getData();
     final Block secBlock =
         (blockData & 8) == 8
             ? block.getRelative(BlockFace.DOWN)
             : block.getRelative(BlockFace.UP);
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(curtype, (byte) (blockData | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), curtype, secBlock.getLocation());
   } else if ((curtype == 29 || curtype == 33) && (block.getData() & 8) > 0) {
     final PistonBaseMaterial piston = (PistonBaseMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             34,
             curtype == 29 ? (byte) (block.getData() | 8) : (byte) (block.getData() & ~8),
             true))
       throw new WorldEditorException(secBlock.getTypeId(), 34, secBlock.getLocation());
   } else if (curtype == 34) {
     final PistonExtensionMaterial piston = (PistonExtensionMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing().getOppositeFace());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             piston.isSticky() ? 29 : 33, (byte) (block.getData() | 8), true))
       throw new WorldEditorException(
           secBlock.getTypeId(), piston.isSticky() ? 29 : 33, secBlock.getLocation());
   } else if (curtype == 18 && (block.getData() & 8) > 0)
     block.setData((byte) (block.getData() & 0xF7));
   return PerformResult.SUCCESS;
 }
  public void run() {
    while (!this.isInterrupted() && !kill.get()) {
      try {
        // Wait until necessary
        long timeWait =
            lastExecute + OrebfuscatorConfig.ProximityHiderRate - System.currentTimeMillis();
        lastExecute = System.currentTimeMillis();
        if (timeWait > 0) {
          Thread.sleep(timeWait);
        }

        if (!OrebfuscatorConfig.UseProximityHider) {
          running = false;
          return;
        }

        HashMap<Player, Location> checkPlayers = new HashMap<Player, Location>();

        synchronized (playersToCheck) {
          checkPlayers.putAll(playersToCheck);
          playersToCheck.clear();
        }

        int distance = OrebfuscatorConfig.ProximityHiderDistance;
        int distanceSquared = distance * distance;

        for (Player p : checkPlayers.keySet()) {

          if (p == null) {
            continue;
          }

          synchronized (proximityHiderTracker) {
            if (!proximityHiderTracker.containsKey(p)) {
              continue;
            }
          }

          Location loc1 = p.getLocation();
          Location loc2 = checkPlayers.get(p);

          // If player changed world
          if (!loc1.getWorld().equals(loc2.getWorld())) {
            synchronized (proximityHiderTracker) {
              proximityHiderTracker.remove(p);
              proximityHiderTrackerLocal.remove(p);
            }
            continue;
          }

          // Player didn't actually move
          if (loc1.getBlockX() == loc2.getBlockX()
              && loc1.getBlockY() == loc2.getBlockY()
              && loc1.getBlockZ() == loc2.getBlockZ()) {
            continue;
          }

          Set<Block> blocks = proximityHiderTrackerLocal.get(p);
          Set<Block> removedBlocks = new HashSet<Block>();
          if (blocks == null) {
            blocks = new HashSet<Block>();
            proximityHiderTrackerLocal.put(p, blocks);
          }

          int y = (int) Math.floor(p.getLocation().getY());

          boolean skip = OrebfuscatorConfig.skipProximityHiderCheck(y);

          synchronized (proximityHiderTracker) {
            Set<Block> synchronizedBlocks = proximityHiderTracker.get(p);
            if (synchronizedBlocks != null) {
              blocks.addAll(synchronizedBlocks);
              synchronizedBlocks.clear();
            }
          }

          if (!skip) {
            for (Block b : blocks) {
              if (b == null || b.getWorld() == null || p.getWorld() == null) {
                removedBlocks.add(b);
                continue;
              }

              if (!p.getWorld().equals(b.getWorld())) {
                removedBlocks.add(b);
                continue;
              }

              if (OrebfuscatorConfig.proximityHiderDeobfuscate(y, b)
                  || p.getLocation().distanceSquared(b.getLocation()) < distanceSquared) {
                removedBlocks.add(b);

                if (CalculationsUtil.isChunkLoaded(
                    b.getWorld(), b.getChunk().getX(), b.getChunk().getZ())) {
                  p.sendBlockChange(b.getLocation(), b.getTypeId(), b.getData());
                  final Block block = b;
                  final Player player = p;
                  Orebfuscator.instance.runTask(
                      new Runnable() {
                        @Override
                        public void run() {
                          OrebfuscatorConfig.blockAccess.updateBlockTileEntity(block, player);
                        }
                      });
                }
              }
            }

            for (Block b : removedBlocks) {
              blocks.remove(b);
            }
          }
        }
      } catch (Exception e) {
        Orebfuscator.log(e);
      }
    }

    running = false;
  }
示例#4
0
  @Override
  public int process(int maxBlocks) {
    int processedBlocks = 0;
    if (state == SimulationState.SCANNING_COMMAND) {
      // Process the casting command block first, and only if specially configured to do so.
      if (includeCommands && castCommandBlock != null) {
        // We are going to rely on the block toggling to kick this back to life when the chunk
        // reloads, so for now just bail and hope the timing works out.
        if (!castCommandBlock.getChunk().isLoaded()) {
          finish();
          // TODO: Maybe Scatter-shot and register all 6 surrounding power blocks for reload toggle.
          // Can't really do it without the chunk being loaded though, so hrm.
          return processedBlocks;
        }

        // Check for death since activation (e.g. during delay period)
        if (castCommandBlock.getType() != Material.COMMAND) {
          die();
          finish();
          return processedBlocks;
        }

        // Check for power blocks
        for (BlockFace powerFace : POWER_FACES) {
          Block checkForPower = castCommandBlock.getRelative(powerFace);
          if (checkForPower.getType() == POWER_MATERIAL) {
            if (commandReload) {
              controller.unregisterAutomata(checkForPower);
            }
            powerSimMaterial.modify(checkForPower);
            commandPowered = true;
          }
        }

        if (!commandPowered) {
          die();
          finish();
          return processedBlocks;
        }

        // Make this a normal block so the sim will process it
        // this also serves to reset the command block for the next tick, if it lives.
        birthMaterial.modify(castCommandBlock);
      }

      processedBlocks++;
      state = SimulationState.SCANNING;
    }

    while (state == SimulationState.SCANNING && processedBlocks <= maxBlocks) {
      if (!simulateBlocks(x, y, z)) {
        return processedBlocks;
      }

      y++;
      if (y > yRadius) {
        y = 0;
        if (x < radius) {
          x++;
        } else {
          z--;
          if (z < 0) {
            r++;
            z = r;
            x = 0;
          }
        }
      }

      if (r > radius) {
        state = SimulationState.UPDATING;
      }
    }

    while (state == SimulationState.UPDATING && processedBlocks <= maxBlocks) {
      int deadIndex = updatingIndex;
      if (deadIndex >= 0 && deadIndex < deadBlocks.size()) {
        Block killBlock = deadBlocks.get(deadIndex);
        if (!killBlock.getChunk().isLoaded()) {
          killBlock.getChunk().load();
          return processedBlocks;
        }

        if (birthMaterial.is(killBlock)) {
          registerForUndo(killBlock);
          killBlock.setType(deathMaterial);
        } else {
          // If this block was destroyed while we were processing,
          // avoid spawning a random birth block.
          // This tries to make it so automata don't "cheat" when
          // getting destroyed. A bit hacky though, I'm not about
          // to re-simulate...
          if (bornBlocks.size() > 0) {
            bornBlocks.remove(bornBlocks.size() - 1);
          }
        }
        processedBlocks++;
      }

      int bornIndex = updatingIndex - deadBlocks.size();
      if (bornIndex >= 0 && bornIndex < bornBlocks.size()) {
        Block birthBlock = bornBlocks.get(bornIndex);
        if (!birthBlock.getChunk().isLoaded()) {
          birthBlock.getChunk().load();
          return processedBlocks;
        }
        registerForUndo(birthBlock);
        birthMaterial.modify(birthBlock);
      }

      updatingIndex++;
      if (updatingIndex >= deadBlocks.size() + bornBlocks.size()) {
        state = SimulationState.COMMAND_SEARCH;

        // Wait at least a tick before re-populating the command block.
        return maxBlocks;
      }
    }

    // Each of the following states will end in this tick, to give the
    // MC sim time to register power updates.
    if (state == SimulationState.COMMAND_SEARCH) {
      if (includeCommands && potentialCommandBlocks.size() > 0) {
        switch (targetMode) {
          case HUNT:
            Collections.sort(potentialCommandBlocks);
            break;
          case FLEE:
            Collections.sort(potentialCommandBlocks);
            break;
          default:
            Collections.shuffle(potentialCommandBlocks);
            break;
        }

        // Find a valid block for the command
        powerTargetBlock = null;
        commandTargetBlock = null;
        Block backupBlock = null;
        while (commandTargetBlock == null && potentialCommandBlocks.size() > 0) {
          Block block = potentialCommandBlocks.remove(0).getBlock();
          if (block != null && birthMaterial.is(block)) {
            // If we're powering the block, look for one with a powerable neighbor.
            if (!commandPowered) {
              commandTargetBlock = block;
            } else {
              backupBlock = block;
              BlockFace powerFace = findPowerLocation(block, powerSimMaterial);
              if (powerFace != null) {
                commandTargetBlock = block;
              }
            }
          }
        }

        // If we didn't find any powerable blocks, but we did find at least one valid sim block
        // just use that one.
        if (commandTargetBlock == null) commandTargetBlock = backupBlock;

        // Search for a power block
        if (commandTargetBlock != null) {
          // First try and replace a live cell
          BlockFace powerDirection = findPowerLocation(commandTargetBlock, powerSimMaterial);
          // Next try to replace a dead cell, which will affect the simulation outcome
          // but this is perhaps better than it dying?
          if (powerDirection == null) {
            if (DEBUG) {
              controller
                  .getLogger()
                  .info("Had to fall back to backup location, pattern may diverge");
            }
            powerDirection = findPowerLocation(commandTargetBlock, powerSimMaterialBackup);
          }
          // If it's *still* not valid, search for something breakable.
          if (powerDirection == null) {
            for (BlockFace face : POWER_FACES) {
              if (blockSpell.isDestructible(commandTargetBlock.getRelative(face))) {
                if (DEBUG) {
                  controller
                      .getLogger()
                      .info(
                          "Had to fall back to destructible location, pattern may diverge and may destroy blocks");
                }
                powerDirection = face;
                break;
              }
            }
          }

          if (powerDirection != null) {
            powerTargetBlock = commandTargetBlock.getRelative(powerDirection);
          }
        }
      }
      if (DEBUG) {
        if (commandTargetBlock != null) {
          controller
              .getLogger()
              .info(
                  "MOVED: "
                      + commandTargetBlock.getLocation().toVector().subtract(center.toVector()));
        }
      }
      state = SimulationState.COMMON_RESET_REDSTONE;
      return processedBlocks;
    }

    if (state == SimulationState.COMMON_RESET_REDSTONE) {
      if (includeCommands && commandTargetBlock != null) {
        DeprecatedUtils.setData(commandTargetBlock, (byte) 0);
      }
      if (includeCommands && powerTargetBlock != null) {
        DeprecatedUtils.setData(powerTargetBlock, (byte) 0);
      }
      state = SimulationState.COMMAND_UPDATE;
      return processedBlocks;
    }

    if (state == SimulationState.COMMAND_UPDATE) {
      if (includeCommands) {
        if (commandTargetBlock != null) {
          if (!commandTargetBlock.getChunk().isLoaded()) {
            commandTargetBlock.getChunk().load();
            return processedBlocks;
          }

          commandTargetBlock.setType(Material.COMMAND);
          BlockState commandData = commandTargetBlock.getState();
          if (castCommand != null && commandData != null && commandData instanceof CommandBlock) {
            CommandBlock copyCommand = (CommandBlock) commandData;
            copyCommand.setCommand(castCommand);
            copyCommand.setName(commandName);
            copyCommand.update();

            // Also move the mage
            Location newLocation = commandTargetBlock.getLocation();
            newLocation.setPitch(center.getPitch());
            newLocation.setYaw(center.getYaw());
            mage.setLocation(newLocation);
          } else {
            commandTargetBlock = null;
          }
        } else {
          die();
        }
      }
      powerDelayTicks = POWER_DELAY_TICKS;
      state = SimulationState.COMMAND_POWER;
      return processedBlocks;
    }

    if (state == SimulationState.COMMAND_POWER) {
      // Continue to power the command block
      if (commandPowered && powerTargetBlock != null && includeCommands) {
        // Wait a bit before powering for redstone signals to reset
        if (powerDelayTicks > 0) {
          powerDelayTicks--;
          return processedBlocks;
        }

        if (powerTargetBlock != null) {
          powerTargetBlock.setType(POWER_MATERIAL);
          if (commandReload) {
            String automataName = commandName;
            if (automataName == null || automataName.length() <= 1) {
              automataName = controller.getMessages().get("automata.default_name");
            }
            controller.registerAutomata(powerTargetBlock, automataName, "automata.awaken");
          }
        }
      }
      state = SimulationState.FINISHED;
      return processedBlocks;
    }

    if (state == SimulationState.FINISHED) {
      finish();
    }

    return processedBlocks;
  }
示例#5
0
  protected boolean simulateBlock(int dx, int dy, int dz) {
    int x = center.getBlockX() + dx;
    int y = center.getBlockY() + dy;
    int z = center.getBlockZ() + dz;
    Block block = world.getBlockAt(x, y, z);
    if (!block.getChunk().isLoaded()) {
      block.getChunk().load();
      return false;
    }

    Material blockMaterial = block.getType();
    if (birthMaterial.is(block)) {
      int distanceSquared =
          liveRangeSquared > 0 || includeCommands
              ? (int) Math.ceil(block.getLocation().distanceSquared(castCommandBlock.getLocation()))
              : 0;

      if (liveRangeSquared <= 0 || distanceSquared <= liveRangeSquared) {
        if (diagonalLiveCounts.size() > 0) {
          int faceNeighborCount = getFaceNeighborCount(block, birthMaterial, includeCommands);
          int diagonalNeighborCount =
              getDiagonalNeighborCount(block, birthMaterial, includeCommands);
          if (faceNeighborCount >= liveCounts.size()
              || !liveCounts.get(faceNeighborCount)
              || diagonalNeighborCount >= diagonalLiveCounts.size()
              || !diagonalLiveCounts.get(diagonalNeighborCount)) {
            killBlock(block);
          } else {
            checkForPotentialCommand(block, distanceSquared);
          }
        } else {
          int neighborCount = getNeighborCount(block, birthMaterial, includeCommands);
          if (neighborCount >= liveCounts.size() || !liveCounts.get(neighborCount)) {
            killBlock(block);
          } else {
            checkForPotentialCommand(block, distanceSquared);
          }
        }
      } else {
        killBlock(block);
      }
    } else if (blockMaterial == deathMaterial) {
      int distanceSquared =
          birthRangeSquared > 0 || includeCommands
              ? (int) Math.ceil(block.getLocation().distanceSquared(castCommandBlock.getLocation()))
              : 0;

      if (birthRangeSquared <= 0 || distanceSquared <= birthRangeSquared) {
        if (diagonalBirthCounts.size() > 0) {
          int faceNeighborCount = getFaceNeighborCount(block, birthMaterial, includeCommands);
          int diagonalNeighborCount =
              getDiagonalNeighborCount(block, birthMaterial, includeCommands);
          if (faceNeighborCount < birthCounts.size()
              && birthCounts.get(faceNeighborCount)
              && diagonalNeighborCount < diagonalBirthCounts.size()
              && diagonalBirthCounts.get(diagonalNeighborCount)) {
            birthBlock(block);
            checkForPotentialCommand(block, distanceSquared);
          }
        } else {
          int neighborCount = getNeighborCount(block, birthMaterial, includeCommands);
          if (neighborCount < birthCounts.size() && birthCounts.get(neighborCount)) {
            birthBlock(block);
            checkForPotentialCommand(block, distanceSquared);
          }
        }
      }
    } else if (includeCommands
        && blockMaterial == Material.COMMAND
        && commandName != null
        && commandName.length() > 1) {
      // Absorb nearby commands of the same name.
      BlockState commandData = block.getState();
      if (commandData != null && commandData instanceof CommandBlock) {
        CommandBlock commandBlock = ((CommandBlock) commandData);
        if (commandBlock.getName().equals(commandName)) {
          block.setType(deathMaterial);
          if (DEBUG) {
            controller.getLogger().info("CONSUMED clone at " + block.getLocation().toVector());
          }
        }
      }
    }

    return true;
  }
示例#6
0
 public static Plot at(Block block) {
   return at(block.getChunk());
 }
示例#7
0
 public void flickSwitch(UUID uuid, boolean on) {
   HashMap<String, Object> whereb = new HashMap<String, Object>();
   whereb.put("uuid", uuid.toString());
   ResultSetTardis rs = new ResultSetTardis(plugin, whereb, "", false);
   if (rs.resultSet()) {
     SCHEMATIC schm = rs.getSchematic();
     if (no_beacon.contains(schm)) {
       // doesn't have a beacon!
       return;
     }
     // toggle beacon
     String beacon = rs.getBeacon();
     String[] beaconData;
     int plusy = 0;
     if (beacon.isEmpty()) {
       // get the location from the TARDIS size and the creeper location
       switch (schm) {
         case REDSTONE:
           plusy = 14;
           break;
         case ELEVENTH:
           plusy = 22;
           break;
         case DELUXE:
           plusy = 23;
           break;
         case BIGGER:
         case ARS:
           plusy = 12;
           break;
         default: // BUDGET, STEAMPUNK, WAR, CUSTOM?
           plusy = 11;
           break;
       }
       String creeper = rs.getCreeper();
       beaconData = creeper.split(":");
     } else {
       beaconData = beacon.split(":");
     }
     World w = plugin.getServer().getWorld(beaconData[0]);
     boolean stuffed = (beaconData[1].contains(".5"));
     int bx, bz;
     // get rid of decimal places due to incorrectly copied values from creeper field...
     if (stuffed) {
       bx = (int) plugin.getUtils().parseFloat(beaconData[1]) * 1;
       bz = (int) plugin.getUtils().parseFloat(beaconData[3]) * 1;
     } else {
       bx = plugin.getUtils().parseInt(beaconData[1]);
       bz = plugin.getUtils().parseInt(beaconData[3]);
     }
     int by = (int) plugin.getUtils().parseFloat(beaconData[2]) * 1 + plusy;
     if (beacon.isEmpty() || stuffed) {
       // update the tardis table so we don't have to do this again
       String beacon_loc = beaconData[0] + ":" + bx + ":" + by + ":" + bz;
       HashMap<String, Object> set = new HashMap<String, Object>();
       set.put("beacon", beacon_loc);
       HashMap<String, Object> where = new HashMap<String, Object>();
       where.put("tardis_id", rs.getTardis_id());
       new QueryFactory(plugin).doUpdate("tardis", set, where);
     }
     Location bl = new Location(w, bx, by, bz);
     Block b = bl.getBlock();
     while (!b.getChunk().isLoaded()) {
       b.getChunk().load();
     }
     b.setType((on) ? Material.GLASS : Material.BEDROCK);
   }
 }
 @SuppressWarnings("deprecation")
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBlockBreak(BlockBreakEvent event) {
   if (!plugin.getConfig().getBoolean("track_creative_place.enabled")) {
     return;
   }
   Player p = event.getPlayer();
   Block block = event.getBlock();
   if (block.getType().equals(Material.AIR)) {
     return;
   }
   if (!plugin
       .getConfig()
       .getStringList("track_creative_place.worlds")
       .contains(block.getWorld().getName())) {
     return;
   }
   if (plugin.getNoTrackList().contains(block.getType())) {
     String gmiwc =
         block.getWorld().getName()
             + ","
             + block.getChunk().getX()
             + ","
             + block.getChunk().getZ();
     if (!plugin.getCreativeBlocks().containsKey(gmiwc)) {
       return;
     }
     if (plugin.getCreativeBlocks().get(gmiwc).contains(block.getLocation().toString())) {
       if (p.getGameMode().equals(GameMode.CREATIVE)) {
         plugin.getBlock().removeBlock(gmiwc, block.getLocation().toString());
       } else {
         String message;
         if (plugin.getConfig().getBoolean("track_creative_place.break_no_drop")) {
           // remove the location from the creative blocks list because we're removing the block!
           plugin.getBlock().removeBlock(gmiwc, block.getLocation().toString());
           if (plugin.getBlockLogger().isLogging()) {
             Location loc = block.getLocation();
             String pname = p.getName();
             switch (plugin.getBlockLogger().getWhichLogger()) {
               case CORE_PROTECT: // log the block removal
                 int type = block.getTypeId();
                 byte data = block.getData();
                 plugin.getBlockLogger().getCoreProtectAPI().logRemoval(pname, loc, type, data);
                 break;
               case LOG_BLOCK:
                 plugin
                     .getBlockLogger()
                     .getLogBlockConsumer()
                     .queueBlockBreak(pname, block.getState());
                 break;
               case PRISM:
                 if (plugin.getBlockLogger().getPrism() != null) {
                   GameModeInventoriesPrismHandler.log(loc, block, pname);
                 }
                 break;
               default:
                 break;
             }
           }
           block.setType(Material.AIR);
           block.getDrops().clear();
           message = plugin.getM().getMessage().get("NO_CREATIVE_DROPS");
         } else {
           event.setCancelled(true);
           message = plugin.getM().getMessage().get("NO_CREATIVE_BREAK");
         }
         if (!plugin.getConfig().getBoolean("dont_spam_chat")) {
           p.sendMessage(plugin.MY_PLUGIN_NAME + message);
         }
       }
     }
   }
 }
示例#9
0
  @Override
  public void run() {
    for (Location l : Storage.blackholes.keySet()) {
      for (Entity e : Utilities.getNearbyEntities(l, 10, 10, 10)) {
        if (e instanceof Player) {
          if (((Player) e).getGameMode().equals(CREATIVE)) {
            continue;
          }
        }
        if (Storage.blackholes.get(l)) {
          Vector v = l.clone().subtract(e.getLocation()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setY(v.getY() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 10);
          e.setVelocity(v.multiply(.35f));
          e.setFallDistance(0);
        } else {
          Vector v = e.getLocation().subtract(l.clone()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 2);
          v.setY(v.getY() + Storage.rnd.nextFloat());
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 2);
          e.setVelocity(v.multiply(.35f));
        }
      }
    }
    // Arrows
    toRemove.clear();
    for (Set<CustomArrow> pro : Storage.advancedProjectiles.values()) {
      for (CustomArrow a : pro) {
        a.onFlight();
        a.tick++;
        if (a.entity.isDead() || a.tick > 600) {
          toRemove.add(a);
        }
      }
    }
    for (CustomArrow pro : toRemove) {
      Storage.advancedProjectiles.remove(pro.entity);
      pro.entity.remove();
    }
    for (Block block : Storage.webs) {
      if (Storage.rnd.nextInt(175) == 0 && block.getChunk().isLoaded()) {
        block.setType(AIR);
        websToRemove.add(block);
      }
    }
    for (Block block : websToRemove) {
      Storage.webs.remove(block);
    }
    websToRemove.clear();
    for (LivingEntity ent : Storage.derpingEntities) {
      Location loc = ent.getLocation();
      loc.setYaw(Storage.rnd.nextFloat() * 360F);
      loc.setPitch(Storage.rnd.nextFloat() * 180F - 90F);
      ent.teleport(loc);
    }
    tick++;
    // Other stuff
    for (FallingBlock b : Storage.anthMobs2) {
      if (!Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        for (Entity e : b.getNearbyEntities(7, 7, 7)) {
          if (e instanceof LivingEntity) {
            LivingEntity lE = (LivingEntity) e;
            if (!(lE instanceof Player) && lE instanceof Monster) {
              b.setVelocity(e.getLocation().subtract(b.getLocation()).toVector().multiply(.25));
              if (lE.getLocation().getWorld().equals(b.getLocation().getWorld())) {
                if (lE.getLocation().distance(b.getLocation()) < 1.2) {
                  EntityDamageEvent evt =
                      new EntityDamageEvent(lE, EntityDamageEvent.DamageCause.SUFFOCATION, 100);
                  Bukkit.getPluginManager().callEvent(evt);
                  lE.setLastDamageCause(evt);
                  if (!evt.isCancelled()) {
                    lE.damage(8f);
                  }
                }
              }
            }
          }
        }
      }
    }
    boolean r = Storage.fallBool;
    Storage.fallBool = !Storage.fallBool;
    for (FallingBlock b : Storage.anthMobs.keySet()) {
      if (Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        Location loc = Storage.anthMobs.get(b).getLocation();
        Vector v;
        if (b.getLocation().getWorld().equals(Storage.anthMobs.get(b).getLocation().getWorld())) {
          if (r && b.getLocation().distance(Storage.anthMobs.get(b).getLocation()) < 10) {
            v = b.getLocation().subtract(loc).toVector();
          } else {
            int x = Storage.rnd.nextInt(12) - 6;
            int z = Storage.rnd.nextInt(12) - 6;
            Location tLoc = loc.clone();
            tLoc.setX(tLoc.getX() + x);
            tLoc.setZ(tLoc.getZ() + z);
            v = tLoc.subtract(b.getLocation()).toVector();
          }
          v.multiply(.05);
          boolean close = false;
          for (int x = -3; x < 0; x++) {
            if (b.getLocation().getBlock().getRelative(0, x, 0).getType() != AIR) {
              close = true;
            }
          }
          if (close) {
            v.setY(5);
          } else {
            v.setY(-.1);
          }
          b.setVelocity(v);
        }
      }
    }

    for (Arrow e : Storage.tracer.keySet()) {
      Entity close = null;
      double distance = 100;
      int level = Storage.tracer.get(e);
      level = level + 2;
      for (Entity e1 : e.getNearbyEntities(level, level, level)) {
        if (e1.getLocation().getWorld().equals(e.getLocation().getWorld())) {
          double d = e1.getLocation().distance(e.getLocation());
          if (e.getLocation()
              .getWorld()
              .equals(((Entity) e.getShooter()).getLocation().getWorld())) {
            if (d < distance
                && e1 instanceof LivingEntity
                && !e1.equals(e.getShooter())
                && e.getLocation().distance(((Entity) e.getShooter()).getLocation()) > 15) {
              distance = d;
              close = e1;
            }
          }
        }
      }
      if (close != null) {
        Location location = close.getLocation();
        org.bukkit.util.Vector v = new org.bukkit.util.Vector(0D, 0D, 0D);
        Location pos = e.getLocation();
        double its =
            Math.sqrt(
                (location.getBlockX() - pos.getBlockX()) * (location.getBlockX() - pos.getBlockX())
                    + (location.getBlockY() - pos.getBlockY())
                        * (location.getBlockY() - pos.getBlockY())
                    + (location.getBlockZ() - pos.getBlockZ())
                        * (location.getBlockZ() - pos.getBlockZ()));
        if (its == 0) {
          its = (double) 1;
        }
        v.setX((location.getBlockX() - pos.getBlockX()) / its);
        v.setY((location.getBlockY() - pos.getBlockY()) / its);
        v.setZ((location.getBlockZ() - pos.getBlockZ()) / its);
        e.setVelocity(v.multiply(2));
      }
    }

    for (Guardian g : Storage.guardianMove.keySet()) {
      if (g.getLocation().distance(Storage.guardianMove.get(g).getLocation()) > 2
          && g.getTicksLived() < 160) {
        g.setVelocity(
            Storage.guardianMove
                .get(g)
                .getLocation()
                .toVector()
                .subtract(g.getLocation().toVector()));
      } else {
        Storage.guardianMove.remove(g);
      }
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
      Config config = Config.get(player.getWorld());
      for (ItemStack stk : player.getInventory().getArmorContents()) {
        HashMap<CustomEnchantment, Integer> map = config.getEnchants(stk);
        for (CustomEnchantment ench : map.keySet()) {
          ench.onFastScan(player, map.get(ench));
        }
      }
      HashMap<CustomEnchantment, Integer> map = config.getEnchants(player.getItemInHand());
      for (CustomEnchantment ench : map.keySet()) {
        ench.onFastScanHand(player, map.get(ench));
      }
    }
    HashSet<Player> toDelete = new HashSet<>();
    for (Player player : Storage.hungerPlayers.keySet()) {
      if (Storage.hungerPlayers.get(player) < 1) {
        toDelete.add(player);
      } else {
        Storage.hungerPlayers.put(player, Storage.hungerPlayers.get(player) - 1);
      }
    }
    for (Player p : toDelete) {
      Storage.hungerPlayers.remove(p);
    }
    toDelete.clear();
    for (Player player : Storage.moverBlockDecay.keySet()) {
      Storage.moverBlockDecay.put(player, Storage.moverBlockDecay.get(player) + 1);
      if (Storage.moverBlockDecay.get(player) > 5) {
        Storage.moverBlocks.remove(player);
        toDelete.add(player);
      }
    }
    for (Player p : toDelete) {
      Storage.moverBlockDecay.remove(p);
    }
  }