예제 #1
0
 public synchronized void start() throws Exception {
   final long start = System.currentTimeMillis();
   taskID = logblock.getServer().getScheduler().scheduleSyncRepeatingTask(logblock, this, 0, 1);
   if (taskID == -1) throw new Exception("Failed to schedule task");
   try {
     wait();
   } catch (final InterruptedException ex) {
     throw new Exception("Interrupted");
   }
   elapsedTime = System.currentTimeMillis() - start;
 }
예제 #2
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
예제 #3
0
  public void setExtraData(net.minecraft.nbt.NBTTagCompound nbttagcompound) {
    if (!nbttagcompound.func_74764_b("bukkit")) {
      nbttagcompound.func_74766_a("bukkit", new net.minecraft.nbt.NBTTagCompound());
    }

    net.minecraft.nbt.NBTTagCompound data = nbttagcompound.func_74775_l("bukkit");
    net.minecraft.entity.player.EntityPlayerMP handle = getHandle();
    data.func_74768_a("newExp", handle.newExp);
    data.func_74768_a("newTotalExp", handle.newTotalExp);
    data.func_74768_a("newLevel", handle.newLevel);
    data.func_74768_a("expToDrop", handle.expToDrop);
    data.func_74757_a("keepLevel", handle.keepLevel);
    data.func_74772_a("firstPlayed", getFirstPlayed());
    data.func_74772_a("lastPlayed", System.currentTimeMillis());
  }
예제 #4
0
  public boolean handleCommand(Player player, String[] split) {

    try {

      split[0] = split[0].substring(1);

      // Quick script shortcut
      if (split[0].matches("^[^/].*\\.js$")) {
        String[] newSplit = new String[split.length + 1];
        System.arraycopy(split, 0, newSplit, 1, split.length);
        newSplit[0] = "cs";
        newSplit[1] = newSplit[1];
        split = newSplit;
      }

      // No command found!
      if (!commandMap.hasCommand(split[0])) {
        return false;
      }

      try {
        commandMap.execute(split, player, this, player);
      } catch (CommandPermissionsException e) {
        player.sendMessage("You don't have permission to do this.");
      } catch (MissingNestedCommandException e) {
        player.sendMessage(e.getUsage());
      } catch (CommandUsageException e) {
        player.sendMessage(e.getMessage());
        player.sendMessage(e.getUsage());
      } catch (WrappedCommandException e) {
        throw e.getCause();
      } catch (UnhandledCommandException e) {
        return false;
      } finally {

      }

    } catch (Throwable excp) {

      player.sendMessage("Please report this error:");
      player.sendMessage(excp.getMessage());
    }

    return true;
  }
예제 #5
0
  public ArrayList<Integer> formatTime(BanData banData) {
    ArrayList<Integer> ret = new ArrayList<Integer>();

    long set = banData.getUnixTime();

    int time = (int) (System.currentTimeMillis() / 1000L);
    int diff = (int) ((set - time) + 604800);

    int d = diff / 86400 % 7;
    int h = diff / 3600 % 24;
    int m = diff / 60 % 60;
    int s = diff % 60;

    ret.add(d);
    ret.add(h);
    ret.add(m);
    ret.add(s);

    return ret;
  }
예제 #6
0
 @SuppressWarnings("incomplete-switch")
 @Override
 public synchronized void run() {
   final List<WorldEditorException> errorList = new ArrayList<WorldEditorException>();
   int counter = 0;
   while (!edits.isEmpty() && counter < 100) {
     try {
       switch (edits.poll().perform()) {
         case SUCCESS:
           successes++;
           break;
         case BLACKLISTED:
           blacklistCollisions++;
           break;
       }
     } catch (final WorldEditorException ex) {
       errorList.add(ex);
     } catch (final Exception ex) {
       getLogger().log(Level.WARNING, "[LogBlock WorldEditor] Exeption: ", ex);
     }
     counter++;
   }
   if (edits.isEmpty()) {
     logblock.getServer().getScheduler().cancelTask(taskID);
     if (errorList.size() > 0)
       try {
         final File file =
             new File(
                 "plugins/LogBlock/error/WorldEditor-"
                     + new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis())
                     + ".log");
         file.getParentFile().mkdirs();
         final PrintWriter writer = new PrintWriter(file);
         for (final LookupCacheElement err : errorList) writer.println(err.getMessage());
         writer.close();
       } catch (final Exception ex) {
       }
     errors = errorList.toArray(new WorldEditorException[errorList.size()]);
     notify();
   }
 }
예제 #7
0
  /**
   * Creates a new server on TCP port 25565 and starts listening for connections.
   *
   * @param args The command-line arguments.
   */
  public static void main(String[] args) {
    try {
      ConfigurationSerialization.registerClass(GlowOfflinePlayer.class);
      GlowPotionEffect.register();

      // parse arguments and read config
      final ServerConfig config = parseArguments(args);
      if (config == null) {
        return;
      }

      // start server
      final GlowServer server = new GlowServer(config);
      server.start();
      server.bind();
      server.bindQuery();
      server.bindRcon();
      logger.info("Ready for connections.");
    } catch (Throwable t) {
      logger.log(Level.SEVERE, "Error during server startup.", t);
      System.exit(1);
    }
  }
예제 #8
0
  public CraftPlayer(CraftServer server, net.minecraft.entity.player.EntityPlayerMP entity) {
    super(server, entity);

    firstPlayed = System.currentTimeMillis();
  }
예제 #9
0
 public static boolean isTagged(final Player player) {
   return SpawnTagHandler.spawnTags.containsKey(player.getName())
       && SpawnTagHandler.spawnTags.get(player.getName()) > System.currentTimeMillis();
 }
예제 #10
0
 public static long getTag(final Player player) {
   return SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis();
 }
예제 #11
0
  public synchronized void load() {
    if (pendingDiskWrites.get() != 0) {
      LOGGER.log(
          Level.INFO, "File {0} not read, because it''s not yet written to disk.", configFile);
      return;
    }
    if (!configFile.getParentFile().exists()) {
      if (!configFile.getParentFile().mkdirs()) {
        LOGGER.log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString()));
      }
    }
    // This will delete files where the first character is 0. In most cases they are broken.
    if (configFile.exists() && configFile.length() != 0) {
      try {
        final InputStream input = new FileInputStream(configFile);
        try {
          if (input.read() == 0) {
            input.close();
            configFile.delete();
          }
        } catch (IOException ex) {
          LOGGER.log(Level.SEVERE, null, ex);
        } finally {
          try {
            input.close();
          } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
          }
        }
      } catch (FileNotFoundException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
      }
    }

    if (!configFile.exists()) {
      if (legacyFileExists()) {
        convertLegacyFile();
      } else if (altFileExists()) {
        convertAltFile();
      } else if (templateName != null) {
        LOGGER.log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString()));
        createFromTemplate();
      } else {
        return;
      }
    }

    try {
      final FileInputStream inputStream = new FileInputStream(configFile);
      try {
        long startSize = configFile.length();
        if (startSize > Integer.MAX_VALUE) {
          throw new InvalidConfigurationException("File too big");
        }
        ByteBuffer buffer = ByteBuffer.allocate((int) startSize);
        int length;
        while ((length = inputStream.read(bytebuffer)) != -1) {
          if (length > buffer.remaining()) {
            ByteBuffer resize =
                ByteBuffer.allocate(buffer.capacity() + length - buffer.remaining());
            int resizePosition = buffer.position();
            buffer.rewind();
            resize.put(buffer);
            resize.position(resizePosition);
            buffer = resize;
          }
          buffer.put(bytebuffer, 0, length);
        }
        buffer.rewind();
        final CharBuffer data = CharBuffer.allocate(buffer.capacity());
        CharsetDecoder decoder = UTF8.newDecoder();
        CoderResult result = decoder.decode(buffer, data, true);
        if (result.isError()) {
          buffer.rewind();
          data.clear();
          LOGGER.log(
              Level.INFO,
              "File "
                  + configFile.getAbsolutePath().toString()
                  + " is not utf-8 encoded, trying "
                  + Charset.defaultCharset().displayName());
          decoder = Charset.defaultCharset().newDecoder();
          result = decoder.decode(buffer, data, true);
          if (result.isError()) {
            throw new InvalidConfigurationException(
                "Invalid Characters in file " + configFile.getAbsolutePath().toString());
          } else {
            decoder.flush(data);
          }
        } else {
          decoder.flush(data);
        }
        final int end = data.position();
        data.rewind();
        super.loadFromString(data.subSequence(0, end).toString());
      } finally {
        inputStream.close();
      }
    } catch (IOException ex) {
      LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    } catch (InvalidConfigurationException ex) {
      File broken =
          new File(configFile.getAbsolutePath() + ".broken." + System.currentTimeMillis());
      configFile.renameTo(broken);
      LOGGER.log(
          Level.SEVERE,
          "The file "
              + configFile.toString()
              + " is broken, it has been renamed to "
              + broken.toString(),
          ex.getCause());
    }
  }
예제 #12
0
  @SuppressWarnings("deprecation")
  @Override
  public void rightClick(final Player player) {
    long cooldown;
    if (item.getHasPermission() == true && player.hasPermission(item.getPermission()) == false) {
    } else {
      RPGValue value = RPGValue.get(player, item, "ice.cooldown");
      if (value == null) {
        cooldown = System.currentTimeMillis() / 50;
        value = new RPGValue(player, item, "ice.cooldown", cooldown);
      } else {
        cooldown = value.asLong();
      }
      if (cooldown <= System.currentTimeMillis() / 50) {
        value.set(System.currentTimeMillis() / 50 + cooldownTime);
        player.playSound(player.getLocation(), Sound.FIZZ, 1.0f, 0.1f);
        final FallingBlock block =
            player
                .getWorld()
                .spawnFallingBlock(player.getLocation().add(0, 1.8, 0), Material.ICE, (byte) 0);
        block.setVelocity(player.getLocation().getDirection().multiply(2d));
        block.setDropItem(false);
        BukkitRunnable run =
            new BukkitRunnable() {

              public void run() {
                boolean hit = false;
                World world = block.getWorld();
                Location bLoc = block.getLocation();
                loop:
                for (int x = -1; x < 2; x++) {
                  for (int y = -1; y < 2; y++) {
                    for (int z = -1; z < 2; z++) {
                      Location loc = block.getLocation().add(x, y, z);
                      if (world.getBlockAt(loc).getType() != Material.AIR) {
                        Block b = world.getBlockAt(loc);
                        if (b.getType().isSolid()) {
                          if (checkBlock(
                              loc.getBlockX(),
                              loc.getBlockY(),
                              loc.getBlockZ(),
                              1,
                              1,
                              1,
                              bLoc.getX() - 0.5d,
                              bLoc.getY() - 0.5d,
                              bLoc.getZ() - 0.5d,
                              1,
                              1,
                              1)) {
                            hit = true;
                            break loop;
                          }
                        }
                      }
                    }
                  }
                }
                if (!hit) {
                  List<Entity> entities = block.getNearbyEntities(1, 1, 1);
                  for (Entity e : entities) {
                    if (e != player) {
                      hit = true;
                      break;
                    }
                  }
                }
                if (block.isDead() || hit) {
                  block.remove();
                  if (!block.getLocation().getBlock().getType().isSolid()
                      && !block.getLocation().getBlock().getType().toString().contains("SIGN"))
                    block.getLocation().getBlock().setType(Material.AIR);
                  cancel();
                  final TObjectLongHashMap<Location> changedBlocks =
                      new gnu.trove.map.hash.TObjectLongHashMap<Location>();
                  for (int x = -1; x < 2; x++) {
                    for (int y = -1; y < 3; y++) {
                      for (int z = -1; z < 2; z++) {
                        Location loc = block.getLocation().add(x, y, z);
                        Block b = world.getBlockAt(loc);
                        if (!b.getType().isSolid() && !b.getType().toString().contains("SIGN")) {
                          changedBlocks.put(b.getLocation(), b.getTypeId() | (b.getData() << 16));
                          b.setType(Material.ICE);
                        }
                      }
                    }
                  }
                  (new BukkitRunnable() {
                        Random random = new Random();

                        @Override
                        public void run() {
                          for (int i = 0; i < 4; i++) {
                            if (changedBlocks.isEmpty()) {
                              cancel();
                              return;
                            }
                            int index = random.nextInt(changedBlocks.size());
                            long data = changedBlocks.values()[index];
                            Location position = (Location) changedBlocks.keys()[index];
                            changedBlocks.remove(position);
                            Block c = position.getBlock();
                            position
                                .getWorld()
                                .playEffect(position, Effect.STEP_SOUND, c.getTypeId());
                            c.setTypeId((int) (data & 0xFFFF));
                            c.setData((byte) (data >> 16));
                          }
                        }
                      })
                      .runTaskTimer(Plugin.plugin, 4 * 20 + new Random().nextInt(40), 3);
                }
              }
            };
        run.runTaskTimer(Plugin.plugin, 0, 1);

      } else {
        player.sendMessage(
            ChatColor.AQUA
                + String.format(
                    Locale.get("message.cooldown"),
                    ((double) (cooldown - System.currentTimeMillis() / 50)) / 20d));
      }
    }
  }
예제 #13
0
  public static int distanceBetweenRegions2(NovaRegion region1, Location l1, Location l2) {
    float millis = System.nanoTime();
    double distance = -1;

    int[] x1 = new int[2];
    int[] x2 = new int[2];

    int[] z1 = new int[2];
    int[] z2 = new int[2];

    Location[] c1 = new Location[2];
    Location[] c2 = new Location[2];

    c1[0] = region1.getCorner(0);
    c1[1] = region1.getCorner(1);

    //		c2[0] = region2.getCorner(0);
    //		c2[1] = region2.getCorner(1);

    c2[0] = l1;
    c2[1] = l2;

    x1[0] = c1[0].getBlockX();
    x1[1] = c1[1].getBlockX();

    x2[0] = c2[0].getBlockX();
    x2[1] = c2[1].getBlockX();

    z1[0] = c1[0].getBlockZ();
    z1[1] = c1[1].getBlockZ();

    z2[0] = c2[0].getBlockZ();
    z2[1] = c2[1].getBlockZ();

    boolean x_out_left = x2[0] < x1[0] && x2[1] < x1[0];
    boolean x_out_right = x1[1] < x2[0] && x1[1] < x2[1];

    boolean x_out = x_out_left || x_out_right;
    Bukkit.getLogger().info("-----");
    Bukkit.getLogger().info("x_out=" + x_out);

    boolean z_out_left = z2[0] < z1[0] && z2[1] < z1[0];
    boolean z_out_right = z1[1] < z2[0] && z1[1] < z2[1];

    boolean z_out = z_out_left || z_out_right;
    Bukkit.getLogger().info("z_out=" + z_out);

    boolean out = x_out && z_out;
    Bukkit.getLogger().info("out=" + out);

    Bukkit.getLogger().info("x1|0=" + x1[0]);
    Bukkit.getLogger().info("x1|1=" + x1[1]);
    Bukkit.getLogger().info("z1|0=" + z1[0]);
    Bukkit.getLogger().info("z1|1=" + z1[1]);
    Bukkit.getLogger().info("x2|0=" + x2[0]);
    Bukkit.getLogger().info("x2|1=" + x2[1]);
    Bukkit.getLogger().info("z2|0=" + z2[0]);
    Bukkit.getLogger().info("z2|1=" + z2[1]);

    World world = region1.getWorld();
    List<Location> corners1 = new ArrayList<>();
    List<Location> corners2 = new ArrayList<>();

    corners1.add(new Location(world, x1[0], 0, x1[0]));
    corners1.add(new Location(world, x1[0], 0, x1[1]));
    corners1.add(new Location(world, x1[1], 0, x1[1]));
    corners1.add(new Location(world, x1[1], 0, x1[0]));

    corners2.add(new Location(world, x2[0], 0, x2[0]));
    corners2.add(new Location(world, x2[0], 0, x2[1]));
    corners2.add(new Location(world, x2[1], 0, x2[1]));
    corners2.add(new Location(world, x2[1], 0, x2[0]));

    // corners distances
    if (out) {
      Bukkit.getLogger().info("rectangle1 corners=" + corners1.size());
      Bukkit.getLogger().info("rectangle2 corners=" + corners2.size());

      for (Location corner1 : corners1) {
        // setCorner(region1.getGuild().getPlayers().get(0).getPlayer(),corner1,Material.BRICK);

        for (Location corner2 : corners2) {
          // Bukkit.getLogger().info("2("+cx2+","+cz2+")");
          // setCorner(region1.getGuild().getPlayers().get(0).getPlayer(),corner2,Material.BRICK);

          double cacheDistance = corner2.distance(corner1);

          if (distance > cacheDistance || distance == -1) {
            Bukkit.getLogger().info("Changed distance. " + distance + " -> " + cacheDistance);
            distance = cacheDistance;
          }
        }
      }
    } else {
      Bukkit.getLogger().info("side by side!");

      boolean x_inside = x1[0] < x2[0] && x2[1] < x1[1];

      if (x_inside) {
        Bukkit.getLogger().info("x_inside");
        int dif = Math.abs(x1[0] - x2[0]);
        Bukkit.getLogger().info("dif=" + dif);
        distance = dif;

        dif = Math.abs(x1[1] - x2[1]);
        Bukkit.getLogger().info("dif=" + dif);
        if (distance > dif || distance == -1) distance = dif;
      } else {
        Bukkit.getLogger().info("z_inside");
        int dif = Math.abs(z1[0] - z2[0]);
        Bukkit.getLogger().info("dif=" + dif);
        distance = dif;

        dif = Math.abs(z1[1] - z2[1]);
        Bukkit.getLogger().info("dif=" + dif);
        if (distance > dif || distance == -1) distance = dif;
      }
    }

    Bukkit.getLogger().info("distance=" + Math.round(distance));
    Bukkit.getLogger().info("Time: " + ((System.nanoTime() - millis)) + "ns");
    return Integer.parseInt(Math.round(distance) + "");
  }