Exemplo n.º 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;
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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());
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
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();
   }
 }
Exemplo n.º 6
0
  public CraftPlayer(CraftServer server, net.minecraft.entity.player.EntityPlayerMP entity) {
    super(server, entity);

    firstPlayed = System.currentTimeMillis();
  }
Exemplo n.º 7
0
 public static boolean isTagged(final Player player) {
   return SpawnTagHandler.spawnTags.containsKey(player.getName())
       && SpawnTagHandler.spawnTags.get(player.getName()) > System.currentTimeMillis();
 }
Exemplo n.º 8
0
 public static long getTag(final Player player) {
   return SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis();
 }
Exemplo n.º 9
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());
    }
  }
Exemplo n.º 10
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));
      }
    }
  }