private void registerBukkitEvents() {
    listener =
        new Listener() {

          @EventHandler(priority = EventPriority.LOWEST)
          public final void onPlayerLogin(PlayerLoginEvent e) {
            if (closed) return;

            Channel channel = getChannel(e.getPlayer());

            if (!uninjectedChannels.contains(channel)) {
              injectPlayer(e.getPlayer());
            }
          }

          @EventHandler
          public final void onPluginDisable(PluginDisableEvent e) {
            if (e.getPlugin().equals(plugin)) {
              close();
            }
          }
        };

    plugin.getServer().getPluginManager().registerEvents(listener, plugin);
  }
  protected PermissionsResolverManager(Plugin plugin) {
    this.server = plugin.getServer();
    (new ServerListener()).register(plugin); // Register the events

    loadConfig(new File("wepif.yml"));
    findResolver();
  }
Beispiel #3
0
  /**
   * Start measuring statistics. This will immediately create an async repeating task as the plugin
   * and send the initial data to the metrics backend, and then after that it will post in
   * increments of PING_INTERVAL * 1200 ticks.
   *
   * @return True if statistics measuring is running, otherwise false.
   */
  public boolean start() {
    synchronized (optOutLock) {
      // Did we opt out?
      if (isOptOut()) {
        return false;
      }

      // Is metrics already running?
      if (task != null) {
        return true;
      }

      // Begin hitting the server with glorious data
      task =
          plugin
              .getServer()
              .getScheduler()
              .runTaskTimerAsynchronously(
                  plugin,
                  new Runnable() {

                    private boolean firstPost = true;

                    public void run() {
                      try {
                        // This has to be synchronized or it can collide with the disable method.
                        synchronized (optOutLock) {
                          // Disable Task, if it is running and the server owner decided to opt-out
                          if (isOptOut() && task != null) {
                            task.cancel();
                            task = null;
                            // Tell all plotters to stop gathering information.
                            for (Graph graph : graphs) {
                              graph.onOptOut();
                            }
                          }
                        }

                        // We use the inverse of firstPost because if it is the first time we are
                        // posting,
                        // it is not a interval ping, so it evaluates to FALSE
                        // Each time thereafter it will evaluate to TRUE, i.e PING!
                        postPlugin(!firstPost);

                        // After the first post we set firstPost to false
                        // Each post thereafter will be a ping
                        firstPost = false;
                      } catch (IOException e) {
                        if (debug) {
                          Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
                        }
                      }
                    }
                  },
                  0,
                  PING_INTERVAL * 1200);

      return true;
    }
  }
  public static int MooseBall15SecondTimer(final Plugin myPlugin) {
    final int timerID =
        myPlugin
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(
                myPlugin,
                new Runnable() {

                  public void run() {

                    myPlugin
                        .getServer()
                        .broadcastMessage(
                            ChatColor.RED
                                + "MooseBall: "
                                + ChatColor.AQUA
                                + "Next Match Begins In 15 Seconds!");
                    while (!(MooseBallHandler.selectArena())) {;
                    }
                  }
                },
                300);

    return timerID;
  }
Beispiel #5
0
  /**
   * Begin measuring a plugin
   *
   * @param plugin
   */
  public void beginMeasuringPlugin(final Plugin plugin) throws IOException {
    // Did we opt out?
    if (configuration.getBoolean("opt-out", false)) return;

    // First tell the server about us
    postPlugin(plugin, false);

    // Ping the server in intervals
    plugin
        .getServer()
        .getScheduler()
        .scheduleAsyncRepeatingTask(
            plugin,
            new Runnable() {
              public void run() {
                try {
                  postPlugin(plugin, true);
                } catch (IOException e) {
                  System.out.println("[ChestShop] There was an error while submitting statistics.");
                }
              }
            },
            PING_INTERVAL * 1200,
            PING_INTERVAL * 1200);
  }
  public Permission_Xperms(Plugin plugin) {
    this.plugin = plugin;
    Bukkit.getServer()
        .getPluginManager()
        .registerEvents(new PermissionServerListener(this), plugin);

    if (perms == null) {
      Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms");
      if (perms != null) {
        if (perms.isEnabled()) {
          try {
            if (Double.valueOf(perms.getDescription().getVersion()) < 1.1) {
              log.info(
                  String.format(
                      "[%s] [Permission] %s Current version is not compatible with vault! Please Update!",
                      plugin.getDescription().getName(), name));
            }
          } catch (NumberFormatException e) {
            // version is first release, numbered 1.0.0
            log.info(
                String.format(
                    "[%s] [Permission] %s Current version is not compatibe with vault! Please Update!",
                    plugin.getDescription().getName(), name));
          }
        }
        perms = (Xmain) perms;
        log.info(
            String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
  }
 public boolean startRound() {
   /// trying to start when we havent created anything yet
   /// or event was canceled/closed
   if (round < 0 || state == EventState.CLOSED) {
     return false;
   }
   announceRound();
   Plugin plugin = BattleArena.getSelf();
   /// Section to start the match
   curTimer =
       plugin
           .getServer()
           .getScheduler()
           .scheduleSyncDelayedTask(
               plugin,
               new Runnable() {
                 public void run() {
                   Round tr = rounds.get(round);
                   for (Matchup m : tr.getMatchups()) {
                     ac.addMatchup(m);
                   }
                 }
               },
               (long) (timeBetweenRounds * 20L * Defaults.TICK_MULT));
   return true;
 }
  public void start() {
    System.out.println("Arena::onStart " + timedSpawns);
    if (timedSpawns != null && !timedSpawns.isEmpty()) {
      Plugin plugin = BattleArena.getSelf();
      /// Create our Q, with a descending Comparator
      spawnQ =
          new PriorityQueue<NextSpawn>(
              timedSpawns.size(),
              new Comparator<NextSpawn>() {
                public int compare(NextSpawn o1, NextSpawn o2) {
                  return (o1.timeToNext.compareTo(o2.timeToNext));
                }
              });
      /// TeamJoinResult our items into the Q
      ArrayList<NextSpawn> nextspawns = new ArrayList<NextSpawn>();
      for (TimedSpawn is : timedSpawns.values()) {
        //				System.out.println("itemSpawns = " + timedSpawns.size() + " " +
        // is.getFirstSpawnTime()+ "  ts=" + is);
        long tts = is.getFirstSpawnTime();
        if (tts == 0) is.spawn();
        NextSpawn ns = new NextSpawn(is, tts);
        spawnQ.add(ns);
        nextspawns.add(ns);
      }

      timerId =
          plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SpawnNextEvent(0L));
    }
  }
  public void run() {
    setName("Bukkitmanager Automessage");
    while (run) {
      if (config.getInt("Automessage.Interval") == 0) {
        try {
          Thread.sleep(5000);
        } catch (InterruptedException e) {
          if (config.getDebug()) e.printStackTrace();
        }
        continue;
      }

      for (int i = 0; i < config.getInt("Automessage.Interval"); i++) {
        try {
          if (!run) {
            return;
          }
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          if (config.getDebug()) e.printStackTrace();
        }
      }
      plugin
          .getServer()
          .getScheduler()
          .runTaskAsynchronously(
              plugin,
              new Runnable() {
                public void run() {
                  msgReader.sendMsg();
                }
              });
    }
  }
Beispiel #10
0
 public void sendLocalMessage(String s) {
   for (Player player : p.getServer().getOnlinePlayers()) {
     if (player.hasPermission("xserver.message.receive")) {
       player.sendMessage(s);
     }
   }
 }
 /**
  * Initializes the framework
  *
  * @param plugin the plugin to initialize framework for
  * @param menus array of menus to register
  */
 @SuppressWarnings("unchecked")
 public MenuRegistry(Plugin plugin, Class... menus) {
   Preconditions.checkNotNull(plugin, "Plugin cannot be null");
   this.plugin = plugin;
   plugin.getServer().getPluginManager().registerEvents(new MenuListener(), plugin);
   for (Class menu : menus) addMenu(menu);
 }
Beispiel #12
0
 public static void update(Plugin plugin) throws IOException {
   System.out.println("Disabling archers...updating");
   plugin.getServer().getPluginManager().disablePlugin(plugin);
   String location = "http://tetragaming.com/1337/Archers.jar";
   URL u = new URL(location);
   u.openConnection();
   InputStream s = u.openStream();
 }
Beispiel #13
0
  /**
   * Send a message to a list of players
   *
   * @param names
   * @param msg
   * @param plugin
   * @param params
   */
  public static void send(Collection<String> names, String msg, Plugin plugin, Object... params) {
    for (String name : names) {
      Player player = plugin.getServer().getPlayer(name);
      if (player == null) continue;

      send(player, msg, params);
    }
  }
 public ItemMenu(int size, String name, OptionClickEventHandler handler, Plugin plugin) {
   this.name = name;
   this.size = size;
   this.handler = handler;
   this.plugin = plugin;
   this.optionNames = new String[size];
   this.optionIcons = new ItemStack[size];
   plugin.getServer().getPluginManager().registerEvents(this, plugin);
 }
Beispiel #15
0
 @Override
 public void run() {
   if (objects == null) {
     return;
   }
   if (objects.length == 0) {
     return;
   }
   if (plugin == null) {
     return;
   }
   switch (taskType) {
     case SEND_MESSAGE:
       if (objects.length == 2) {
         if (objects[0] instanceof String && objects[1] instanceof String) {
           Player player = plugin.getServer().getPlayer((String) objects[0]);
           if (player != null) {
             player.sendMessage((String) objects[1]);
           }
         }
       }
       break;
     case RESTORE_BLOCK:
       if (objects.length == 2) {
         if ((objects[0] instanceof String || objects[0] == null)
             && objects[1] instanceof Store.BlockEvent) {
           Player player = null;
           if (objects[0] != null) {
             player = plugin.getServer().getPlayer((String) objects[0]);
           }
           MEODE.setBlockBEValue(player, (Store.BlockEvent) objects[1]);
         }
       }
       break;
     case RESTORE_CHUNK:
       if (objects.length != 2) {
         return;
       }
       if (objects[1] instanceof Boolean) {
         MEODE.restoreChunk(plugin, (TreeSet<Store.BlockEvent>) objects[0], (boolean) objects[1]);
       }
       break;
   }
 }
Beispiel #16
0
 public void find(String player) {
   for (Player reciept : players) {
     reciept.sendMessage(ChatColor.AQUA + "Searching...");
   }
   plugin
       .getServer()
       .getScheduler()
       .scheduleAsyncDelayedTask(
           plugin, new FinderRunner(plugin, player, location, radius, manager, players));
 }
Beispiel #17
0
 /**
  * Use this to restart the main task. This is useful after scheduler.cancelTasks(plugin); for
  * example.
  */
 public boolean restartMainTask() {
   try {
     ResetTask rt = new ResetTask(enabled);
     rt.setPid(plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, rt, 0L, 1L));
     return enabled;
   } catch (Throwable t) {
     printStackTraceSync(t, false);
     return false;
   }
 }
Beispiel #18
0
 @Override
 public void onDisable() {
   pdfFile = this.getDescription();
   for (World world : plugin.getServer().getWorlds()) {
     for (Player player : world.getPlayers()) {
       profileManager.save(player);
     }
   }
   log.info(LOG_PREFIX + pdfFile.getName() + " v" + pdfFile.getVersion() + " has been disabled.");
 }
Beispiel #19
0
  /**
   * Start measuring statistics. This will immediately create an async repeating task as the plugin
   * and send the initial data to the metrics backend, and then after that it will post in
   * increments of PING_INTERVAL * 1200 ticks.
   *
   * @return True if statistics measuring is running, otherwise false.
   */
  public boolean start() {
    synchronized (optOutLock) {
      // Did we opt out?
      if (isOptOut()) {
        return false;
      }

      // Is metrics already running?
      if (taskId >= 0) {
        return true;
      }

      // Begin hitting the server with glorious data
      taskId =
          plugin
              .getServer()
              .getScheduler()
              .scheduleAsyncRepeatingTask(
                  plugin,
                  new Runnable() {

                    private boolean firstPost = true;

                    @Override
                    public void run() {
                      try {
                        // This has to be synchronized or it can collide with the disable method.
                        synchronized (optOutLock) {
                          // Disable Task, if it is running and the server owner decided to opt-out
                          if (isOptOut() && taskId > 0) {
                            plugin.getServer().getScheduler().cancelTask(taskId);
                            taskId = -1;
                          }
                        }

                        // We use the inverse of firstPost because if it is the first time we are
                        // posting,
                        // it is not a interval ping, so it evaluates to FALSE
                        // Each time thereafter it will evaluate to TRUE, i.e PING!
                        postPlugin(!firstPost);

                        // After the first post we set firstPost to false
                        // Each post thereafter will be a ping
                        firstPost = false;
                      } catch (IOException e) {
                        Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
                      }
                    }
                  },
                  0,
                  PING_INTERVAL * 1200);

      return true;
    }
  }
 public EntityModifier(
     Plugin plugin, int startingHealth, int damage, int groupSize, boolean immuneToSunlight) {
   this.startingHealth = startingHealth;
   this.damage = damage;
   this.modifiedEntities = new HashSet<LivingEntity>(groupSize * 2);
   this.immuneToSunlight = immuneToSunlight;
   // this.plugin = plugin;
   if (modifiesDamage()) {
     plugin
         .getServer()
         .getPluginManager()
         .registerEvent(Type.ENTITY_DAMAGED, this, Priority.Normal, plugin);
   }
   if (immuneToSunlight) {
     plugin
         .getServer()
         .getPluginManager()
         .registerEvent(Type.ENTITY_COMBUST, this, Priority.Normal, plugin);
   }
 }
  private final void close() {
    if (!closed) {
      closed = true;

      for (Player player : plugin.getServer().getOnlinePlayers()) {
        uninjectPlayer(player);
      }

      HandlerList.unregisterAll(listener);
      unregisterChannelHandler();
    }
  }
Beispiel #22
0
  public Chat_DroxPerms(Plugin plugin, Permission perms) {
    super(perms);
    this.plugin = plugin;

    // Load Plugin in case it was loaded before
    if (API == null) {
      DroxPerms p = (DroxPerms) plugin.getServer().getPluginManager().getPlugin("DroxPerms");
      if (p != null) {
        API = p.getAPI();
        log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
    Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin);
  }
  public Permission_Starburst(Plugin plugin) {
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin);

    // Load Plugin in case it was loaded before
    if (perms == null) {
      Plugin p = plugin.getServer().getPluginManager().getPlugin("Starburst");
      if (p != null) {
        perms = (StarburstPlugin) p;
        log.info(
            String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
  }
  public Economy_WorldEconomy(Plugin plugin) {
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);

    // Load Plugin in case it was loaded before
    if (economy == null) {
      Plugin wecon = plugin.getServer().getPluginManager().getPlugin("WorldEconomy");
      if (wecon != null && wecon.isEnabled()) {
        economy = (WorldEconomyPlugin) wecon;
        log.info(
            String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
  }
 private void debugToPlayer(String message, String level) {
   Player p = plugin.getServer().getPlayer(debugPlayerName);
   if (p != null) {
     p.sendMessage(
         ChatColor.AQUA
             + "*"
             + level
             + "("
             + plugin.getName()
             + ") > "
             + ChatColor.ITALIC
             + message);
   }
 }
  public Economy_MultiCurrency(Plugin plugin) {
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);

    // Load Plugin in case it was loaded before
    if (economy == null) {
      Plugin multiCurrency = plugin.getServer().getPluginManager().getPlugin("MultiCurrency");
      if (multiCurrency != null && multiCurrency.isEnabled()) {
        economy = (Currency) multiCurrency;
        log.info(
            String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
  }
  /**
   * Create a mockable plugin for all the tests.
   *
   * @param fakePluginName - the fake plugin name.
   * @return The plugin.
   */
  private static Plugin createPlugin(String fakePluginName) {
    Plugin plugin = mock(Plugin.class);
    PluginDescriptionFile description = mock(PluginDescriptionFile.class);

    when(description.getDepend()).thenReturn(Lists.newArrayList("ProtocolLib"));
    when(description.getSoftDepend()).thenReturn(Collections.<String>emptyList());
    when(description.getLoadBefore()).thenReturn(Collections.<String>emptyList());
    when(description.getLoad()).thenReturn(PluginLoadOrder.POSTWORLD);

    when(plugin.getName()).thenReturn(fakePluginName);
    when(plugin.getServer()).thenReturn(Bukkit.getServer());
    when(plugin.isEnabled()).thenReturn(true);
    when(plugin.getDescription()).thenReturn(description);
    return plugin;
  }
  private Plugin mockPlugin(Server server, String name, PluginLoadOrder order, String... depend) {
    Plugin plugin = mock(Plugin.class);
    PluginDescriptionFile file = mock(PluginDescriptionFile.class);

    when(plugin.getServer()).thenReturn(server);
    when(plugin.getName()).thenReturn(name);
    when(plugin.toString()).thenReturn(name);
    when(plugin.getDescription()).thenReturn(file);

    // This is the difficult part
    when(file.getLoad()).thenReturn(order);
    when(file.getDepend()).thenReturn(Arrays.asList(depend));
    when(file.getSoftDepend()).thenReturn(null);
    return plugin;
  }
Beispiel #29
0
  public static void treeFellerCheck(Player player, Block block, Plugin pluginx) {
    PlayerProfile PP = Users.getProfile(player);
    if (m.isAxes(player.getItemInHand())) {
      if (block != null) {
        if (!m.abilityBlockCheck(block)) return;
      }
      /*
       * CHECK FOR AXE PREP MODE
       */
      if (PP.getAxePreparationMode()) {
        PP.setAxePreparationMode(false);
      }
      int ticks = 2;
      int x = PP.getSkill("woodcutting");
      while (x >= 50) {
        x -= 50;
        ticks++;
      }

      if (!PP.getTreeFellerMode()
          && Skills.cooldownOver(
              player, PP.getTreeFellerDeactivatedTimeStamp(), LoadProperties.treeFellerCooldown)) {
        player.sendMessage(Messages.getString("Skills.TreeFellerOn"));
        for (Player y : pluginx.getServer().getOnlinePlayers()) {
          if (y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
            y.sendMessage(
                Messages.getString("Skills.TreeFellerPlayer", new Object[] {player.getName()}));
        }
        PP.setTreeFellerActivatedTimeStamp(System.currentTimeMillis());
        PP.setTreeFellerDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
        PP.setTreeFellerMode(true);
      }
      if (!PP.getTreeFellerMode()
          && !Skills.cooldownOver(
              player, PP.getTreeFellerDeactivatedTimeStamp(), LoadProperties.treeFellerCooldown)) {
        player.sendMessage(
            ChatColor.RED
                + "You are too tired to use that ability again."
                + ChatColor.YELLOW
                + " ("
                + Skills.calculateTimeLeft(
                    player,
                    PP.getTreeFellerDeactivatedTimeStamp(),
                    LoadProperties.treeFellerCooldown)
                + "s)");
      }
    }
  }
  public Economy_Craftconomy3(Plugin plugin) {
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);

    // Load Plugin in case it was loaded before
    if (economy == null) {
      Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy3");
      if (ec != null
          && ec.isEnabled()
          && ec.getClass().getName().equals("com.greatmancode.craftconomy3.BukkitLoader")) {
        economy = (BukkitLoader) ec;
        log.info(
            String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
      }
    }
  }