예제 #1
0
  @Override
  public void onEnable() {
    instance = this;

    this.getConfig().options().copyDefaults(true);
    this.saveConfig();

    /* COMMAND */
    this.getCommand("gspos").setExecutor(new PositionCommand());
    this.getCommand("gsitem").setExecutor(new ItemCommand());
    this.getCommand("gspunish").setExecutor(new PunishmentsManager());

    /* LISTENER */
    Bukkit.getPluginManager().registerEvents(new TaserListener(), this);
    Bukkit.getPluginManager().registerEvents(new BombJacketListener(), this);
    Bukkit.getPluginManager().registerEvents(new PositionListener(), this);
    Bukkit.getPluginManager().registerEvents(new GuillotioneListener(), this);
    Bukkit.getPluginManager().registerEvents(new MeteorListener(), this);
    Bukkit.getPluginManager().registerEvents(new RoketListener(), this);
    Bukkit.getPluginManager().registerEvents(new PunishmentsManager(), this);

    System.out.println(" --=<>=---==---===<(O)>===---==---=<>=-- ");
    System.out.println(
        "   "
            + JavaPlugin.getPlugin(this.getClass()).getDescription().getFullName()
            + " plugin loaded...");
    System.out.println("   Made by the PixelCrew Developer's:");
    System.out.println("        http://www.pixelcrew.org");
    System.out.println(" --=<>=---==---===<(O)>===---==---=<>=--");
  }
예제 #2
0
  @EventHandler
  public void move(PlayerMoveEvent event) {
    if (worldGuard == null) return;

    Player player = event.getPlayer();

    if (!regionsVisited.containsKey(player.getUniqueId()))
      regionsVisited.put(player.getUniqueId(), new ArrayList<>());

    RegionContainer container = worldGuard.getWorldGuard().getRegionContainer();
    RegionManager manager = container.get(player.getWorld());
    if (manager == null) return;

    ApplicableRegionSet regions = manager.getApplicableRegions(event.getTo());
    List<ProtectedRegion> visited = regionsVisited.get(player.getUniqueId());

    try {
      for (ProtectedRegion region : regions.getRegions()) {
        if (!visited.contains(region)) {
          // i've never seen this place before in my life... or maybe in 30 seconds
          visited.add(region);
          Bukkit.getScheduler()
              .runTaskLaterAsynchronously(
                  JavaPlugin.getPlugin(Tyrant.class), () -> enter(player, region), 1);
        }
      }

      Bukkit.getScheduler()
          .runTaskLater(
              JavaPlugin.getPlugin(Tyrant.class),
              () -> {
                for (ProtectedRegion region2 : visited) {
                  if (!regions.getRegions().contains(region2)) {
                    // leaving the tavern
                    visited.remove(region2);
                    Bukkit.getScheduler()
                        .runTaskLaterAsynchronously(
                            JavaPlugin.getPlugin(Tyrant.class), () -> exit(player), 1);
                  }
                }
              },
              1);
    } catch (ConcurrentModificationException e) {
      e.printStackTrace();
    }
  }
예제 #3
0
public class Archer implements KitAction {

  private ZombieEscape plugin = JavaPlugin.getPlugin(ZombieEscape.class);

  @Override
  public void giveKit(Player player) {
    plugin.getGameArena().giveDefaults(player);
    player.getInventory().setItem(8, new ItemStack(Material.ARROW, 16));
  }

  @Override
  public void interact(PlayerInteractEvent event, Player player, ItemStack itemStack) {}
}
 @Override
 public Thread newThread(Runnable r) {
   return new Thread(r, JavaPlugin.getPlugin(ProtocolSupport.class) + "-errlog-thread");
 }
public class AsyncErrorLogger {

  private static final boolean enabled =
      Utils.getJavaPropertyValue(
          "protocolsupport.errlog.errlog", true, Converter.STRING_TO_BOOLEAN);
  private static final long maxFileSize =
      Utils.getJavaPropertyValue(
          "protocolsupport.errlog.maxsize", 1024L * 1024L * 20L, Converter.STRING_TO_LONG);
  private static final String filePath =
      Utils.getJavaPropertyValue(
          "protocolsupport.errlog.path",
          JavaPlugin.getPlugin(ProtocolSupport.class).getName() + "-errlog",
          Converter.NONE);

  public static final AsyncErrorLogger INSTANCE = new AsyncErrorLogger();

  private final ExecutorService executor =
      Executors.newSingleThreadExecutor(
          new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
              return new Thread(r, JavaPlugin.getPlugin(ProtocolSupport.class) + "-errlog-thread");
            }
          });

  public void start() {}

  public void stop() {
    executor.shutdown();
    try {
      executor.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    synchronized (writer) {
      if (writer != null) {
        writer.close();
      }
    }
  }

  private PrintWriter writer;

  private AsyncErrorLogger() {
    if (!enabled) {
      stop();
      return;
    }
    try {
      File logfile = new File(filePath);
      if (logfile.length() > maxFileSize) {
        logfile.delete();
      }
      logfile.createNewFile();
      writer = new PrintWriter(new FileOutputStream(logfile, true));
    } catch (Exception e) {
      ProtocolSupport.logWarning("Unable to create error log");
      stop();
    }
  }

  public void log(final Throwable t, final Object... info) {
    if (executor.isShutdown()) {
      return;
    }
    try {
      executor.submit(
          new Runnable() {
            @Override
            public void run() {
              synchronized (writer) {
                writer.println(
                    "Error occured at "
                        + new SimpleDateFormat("yyyy-MM-dd-HH-mm", Locale.ROOT).format(new Date()));
                writer.println("Additional info: " + StringUtils.join(info, ", "));
                writer.println("Exception class: " + t.getClass().getName());
                writer.println("Exception message: " + t.getMessage());
                writer.println("Exception log:");
                t.printStackTrace(writer);
                writer.println();
              }
            }
          });
    } catch (RejectedExecutionException e) {
    }
  }
}