Exemple #1
0
  public ThirstSchedule(JavaPlugin plugin) {
    ThirstSchedule.plugin = plugin;

    // Schedule to calculate thirst
    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncRepeatingTask(
            plugin,
            new Runnable() {
              public void run() {
                ThirstSchedule.calculateThirst();
              }
            },
            20L,
            Settings.getConfig().getLong(Thirst.TICKS));

    // Schedule to damage due to thirst
    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncRepeatingTask(
            plugin,
            new Runnable() {
              public void run() {
                ThirstSchedule.calculateThirstDamage();
              }
            },
            20L,
            Settings.getConfig().getLong(Thirst.DAMAGE_TICKS));
  }
 // --------------------------------------------------------------------------- extractDefaultFile
 public static void extractDefaultFile(JavaPlugin plugin, String filePath) {
   String[] split = filePath.split("/");
   String fileName = split[split.length - 1];
   File actual = new File(filePath);
   if (!actual.exists()) {
     InputStream input = plugin.getClass().getResourceAsStream("/default/" + fileName);
     if (input != null) {
       plugin
           .getServer()
           .getLogger()
           .log(Level.INFO, "Create default file " + fileName + " for " + filePath);
       FileOutputStream output = null;
       try {
         output = new FileOutputStream(actual);
         byte[] buf = new byte[8192];
         int length = 0;
         while ((length = input.read(buf)) > 0) {
           output.write(buf, 0, length);
         }
         plugin.getServer().getLogger().log(Level.INFO, "Default file written " + filePath);
       } catch (Exception e) {
         e.printStackTrace();
       }
       try {
         input.close();
       } catch (Exception e) {
       }
       try {
         output.close();
       } catch (Exception e) {
       }
     }
   }
 }
 public synchronized void enable() {
   plugin
       .getServer()
       .getPluginManager()
       .registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin);
   plugin
       .getServer()
       .getPluginManager()
       .registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin);
 }
 private void registerChannels() {
   if (!plugin.getServer().getMessenger().isOutgoingChannelRegistered(plugin, "Iceball")) {
     plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "Iceball");
   }
   if (!this.plugin
       .getServer()
       .getMessenger()
       .isOutgoingChannelRegistered(this.plugin, "BungeeCord")) {
     this.plugin
         .getServer()
         .getMessenger()
         .registerOutgoingPluginChannel(this.plugin, "BungeeCord");
   }
 }
  public boolean doExecute(
      JavaPlugin plugin, CommandSender sender, Player player, String command, String[] args)
      throws Throwable {
    boolean retval = true;

    StringBuilder commandLine = new StringBuilder(command);
    for (int i = 0; i < args.length; i++) {
      commandLine.append(" ");
      commandLine.append(args[i]);
    }

    boolean cmdret = false;
    PermissionAttachment attachment = null;
    try {
      PluginCommand cmd = plugin.getServer().getPluginCommand(command);
      attachment =
          player.addAttachment(
              plugin, cmd.getPermission(), true, 20); // we add the permission to the player...
      // we let this expire after 20 ticks (one second) to make sure that he doesn't get it forever
      // by accident
    } catch (Throwable t) {
      // t.printStackTrace(); //No stacktrace since this can happen

      // apparently this failed. last chance: give him all permissions
      attachment = player.addAttachment(plugin, 20);
      for (Permission p : plugin.getServer().getPluginManager().getPermissions()) {
        attachment.setPermission(p, true);
      }
    }

    try {
      cmdret =
          plugin
              .getServer()
              .dispatchCommand(player, commandLine.toString()); // ... execute the command ...
    } catch (Exception e) {
      e.printStackTrace();
      retval = false;
    }

    if (attachment != null) player.removeAttachment(attachment); // ... and remove the permission.

    if (retval) {
      if (cmdret) sender.sendMessage("Done.");
      else sender.sendMessage("Couldn't find the specified command.");
    }

    return retval;
  }
Exemple #6
0
  public NPCManager(JavaPlugin plugin) throws IOException {
    mcServer = ((CraftServer) plugin.getServer()).getServer();

    npcNetworkManager = new NPCNetworkManager();
    NPCManager.plugin = plugin;
    taskid =
        Bukkit.getServer()
            .getScheduler()
            .scheduleSyncRepeatingTask(
                plugin,
                new Runnable() {
                  public void run() {
                    HashSet<String> toRemove = new HashSet<String>();
                    for (String i : bankers.keySet()) {
                      Entity j = bankers.get(i).getEntity();
                      j.z();
                      if (j.dead) {
                        toRemove.add(i);
                      }
                    }
                    for (String n : toRemove) {
                      bankers.remove(n);
                    }
                  }
                },
                1L,
                1L);
    Bukkit.getServer().getPluginManager().registerEvents(new SL(), plugin);
    Bukkit.getServer().getPluginManager().registerEvents(new WL(), plugin);
  }
 public static Inventory cloneInventory(JavaPlugin plugin, Inventory inv) {
   Inventory inv2 = plugin.getServer().createInventory(null, inv.getSize());
   for (int i = 0; i < inv.getSize(); i++) {
     inv2.setItem(i, inv.getItem(i) == null ? null : inv.getItem(i).clone());
   }
   return inv2;
 }
  private synchronized void broadcastToListeners(String level, String msg) {

    String label = null;

    switch (level) {
      case "info":
        label = ChatColor.GREEN + "INFO";
        break;
      case "warning":
        label = ChatColor.YELLOW + "WARNING";
        break;
      case "severe":
        label = ChatColor.DARK_RED + "SEVERE";
        break;
      case "debug":
        label = ChatColor.BLUE + "DEBUG";
        break;
      default:
        label = "Default label";
    }

    for (String playername : listeners) {
      Player player = plugin.getServer().getPlayer(playername);

      if (player != null) {
        player.sendMessage(label + " [" + this.name + "] - " + ChatColor.WHITE + msg);
      } else {
        listeners.remove(playername);
      }
    }
  }
Exemple #9
0
 public static void calculateThirst() {
   Player[] players = plugin.getServer().getOnlinePlayers();
   for (Player player : players) {
     if (Thirst.isAllowed(player) && player.getLevel() > 0) {
       player.setLevel(player.getLevel() - 1);
       sendPlayerThirstMessage(player);
     }
   }
 }
Exemple #10
0
 public boolean cancel() {
   if (isRunning()) {
     plugin.getServer().getScheduler().cancelTask(taskId);
     taskId = -1;
     return true;
   } else {
     return false;
   }
 }
 /*
  * Установка блока с проверкой на приват
  */
 public boolean placeBlock(Block block, Player p, Material newType, byte newData, boolean phys) {
   BlockState state = block.getState();
   block.setTypeIdAndData(newType.getId(), newData, phys);
   BlockPlaceEvent event =
       new BlockPlaceEvent(state.getBlock(), state, block, p.getItemInHand(), p, true);
   plg.getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) state.update(true);
   return event.isCancelled();
 }
  private static Plugin getWorldEdit(JavaPlugin plugin) {
    try {
      Plugin wPlugin = plugin.getServer().getPluginManager().getPlugin("WorldEdit");

      if ((wPlugin == null) || (!(wPlugin instanceof WorldEditPlugin))) {
        return null;
      }

      return (WorldEditPlugin) wPlugin;
    } catch (NoClassDefFoundError ex) {
      return null;
    }
  }
Exemple #13
0
 public static void calculateThirstDamage() {
   Player[] players = plugin.getServer().getOnlinePlayers();
   for (Player player : players) {
     if (Thirst.isAllowed(player) && player.getLevel() == 0) {
       if (!player.isOp() || !Settings.getConfig().getBoolean("world.op-is-god")) {
         player.damage(Settings.getConfig().getInt(Thirst.DAMAGE_HIT));
       }
       if (player.getHealth() == Settings.getConfig().getInt(Thirst.DEATH_LVL)) {
         player.sendMessage(ChatColor.RED + Messages.getConfig().getString(Thirst.DEATH_MSG));
       }
     }
   }
 }
  // First Join Detection
  @EventHandler(priority = EventPriority.LOWEST)
  public void firstJoinDetection(PlayerJoinEvent event) {
    // Define our variables.
    Player player = event.getPlayer();

    // Call the first join event.
    Boolean b = player.hasPlayedBefore();
    if (plugin.getConfig().getBoolean("settings.debug")) {
      b = false;
    }
    if (!b) {
      plugin.getServer().getPluginManager().callEvent(new FirstJoinEvent(event));
      return;
    }
  }
  protected boolean doExecute(
      JavaPlugin plugin, CommandSender sender, Player player, String command, String[] args)
      throws Throwable {
    StringBuilder commandLine = new StringBuilder(command);
    for (int i = 0; i < args.length; i++) {
      commandLine.append(" ");
      commandLine.append(args[i]);
    }

    PluginCommand cmd = null;
    PermissionAttachment attachment = null;
    try {
      cmd = plugin.getServer().getPluginCommand(command);
      attachment =
          player.addAttachment(
              plugin, cmd.getPermission(), true, 20); // we add the permission to the player...
      // we let this expire after 20 ticks (one second) to make sure that he doesn't get it forever
      // by accident
    } catch (Throwable t) {
      // t.printStackTrace(); //No stacktrace since this can happen

      // apparently this failed. last chance: give him all permissions
      attachment = player.addAttachment(plugin, 20);
      for (Permission p : plugin.getServer().getPluginManager().getPermissions()) {
        attachment.setPermission(p, true);
      }
    }

    player.performCommand(commandLine.toString()); // ... execute the command ...

    if (attachment != null) player.removeAttachment(attachment); // ... and remove the permission.

    sender.sendMessage("Done.");

    return true; // basically this just can't fail
  }
  // Join Handling
  @EventHandler
  public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    if (!Utilities.getUtilities().onlyfirstjoin()) {
      // Variables
      StringBuilder joinmsg = new StringBuilder();

      // Show Join Message and Number on Join
      if (player.hasPlayedBefore()) {
        String message = plugin.getConfig().getString("messages.joinmessage");
        if (!message.equalsIgnoreCase("none")) {
          joinmsg.append(Utilities.getUtilities().format(message, player));
          if (plugin.getConfig().getBoolean("settings.numberonjoin")) {
            joinmsg.append(
                "\n"
                    + Utilities.getUtilities()
                        .format(plugin.getConfig().getString("messages.numbermessage"), player));
          }
          event.setJoinMessage(joinmsg.toString());
        } else {
          event.setJoinMessage(null);
        }
      }
    }

    // Check for Updates!
    if (player.isOp()
        && plugin.getConfig().getBoolean("settings.updatecheck")
        && Utilities.getUtilities().needsUpdate()) {
      plugin
          .getServer()
          .getScheduler()
          .scheduleSyncDelayedTask(
              plugin,
              new Runnable() {
                public void run() {
                  player.sendMessage("§e[§lFirstJoinPlus§r§e] §aA new version is available!");
                  player.sendMessage(
                      "§e[§lFirstJoinPlus§r§e] §aDownload it at: §ohttp://dev.bukkit.org/server-mods/firstjoinplus/");
                }
              },
              100L);
    }
  }
  public void importYML() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());
      File perms = new File("plugins/bPermissions/worlds/" + world.getName() + ".yml");
      if (perms.exists()) {
        System.out.println("Importing world: " + world.getName());
        YamlConfiguration pConfig = new YamlConfiguration(); // new Configuration(perms);
        pConfig.load(perms);
        // Here we grab the different bits and bobs
        ConfigurationSection users = pConfig.getConfigurationSection("players");
        ConfigurationSection groups = pConfig.getConfigurationSection("groups");

        // Load users
        if (users != null && users.getKeys(false) != null && users.getKeys(false).size() > 0) {
          Set<String> u = users.getKeys(false);
          for (String usr : u) {
            System.out.println("Importing user: "******"Importing group: " + grp);
            List<String> p = groups.getStringList(grp);
            if (p != null && p.size() > 0)
              for (String perm : p)
                wd.getGroup(grp).getPermissions().add(Permission.loadFromString(perm));
          }
        }
      }
      // Forgot to save after importing!
      wd.save();
    }
    wm.cleanup();
  }
 /* Вызывается автоматом при старте плагина,
  * пишет сообщение о выходе новой версии в лог-файл
  */
 public void updateMsg() {
   plg.getServer()
       .getScheduler()
       .runTaskAsynchronously(
           plg,
           new Runnable() {
             public void run() {
               updateLastVersion();
               if (isUpdateRequired()) {
                 log.info(
                     "["
                         + des.getName()
                         + "] "
                         + project_name
                         + " v"
                         + des.getVersion()
                         + " is outdated! Recommended version is v"
                         + project_last_version);
                 log.info("[" + des.getName() + "] " + project_bukkitdev);
               }
             }
           });
 }
Exemple #19
0
 public Timer(JavaPlugin p) {
   p.getServer().getScheduler().scheduleAsyncRepeatingTask(p, this, 0, 1);
 }
Exemple #20
0
 public void schedule(JavaPlugin plugin, long delay) {
   cancel();
   this.plugin = plugin;
   this.taskId = scheduleTask(plugin.getServer().getScheduler(), plugin, delay);
 }
Exemple #21
0
 // Constructor
 public PInteractEvent(JavaPlugin jp) {
   plugin = jp;
   plugin.getServer().getPluginManager().registerEvents(this, plugin);
 }
  public void importGroupManager() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());

      File users = new File("plugins/GroupManager/worlds/" + world.getName() + "/users.yml");
      File groups = new File("plugins/GroupManager/worlds/" + world.getName() + "/groups.yml");

      if (users.exists() && groups.exists()) {
        System.out.println("Importing world: " + world.getName());

        YamlConfiguration uConfig = new YamlConfiguration();
        YamlConfiguration gConfig = new YamlConfiguration();
        try {
          uConfig.load(users);
          gConfig.load(groups);
        } catch (Exception e) {
          e.printStackTrace();
        }
        ConfigurationSection usConfig = uConfig.getConfigurationSection("users");
        ConfigurationSection grConfig = gConfig.getConfigurationSection("groups");

        Set<String> usersList = null;
        if (usConfig != null) usersList = usConfig.getKeys(false);
        Set<String> groupsList = null;
        if (grConfig != null) groupsList = grConfig.getKeys(false);

        if (usersList != null)
          for (String player : usersList) {
            System.out.println("Importing user: "******"users." + player + ".permissions");
              List<String> i = uConfig.getStringList("users." + player + ".subgroups");
              i.add(uConfig.getString("users." + player + ".group"));

              String prefix = uConfig.getString("users." + player + ".info." + "prefix");
              String suffix = uConfig.getString("users." + player + ".info." + "suffix");

              if (p != null) user.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                user.getGroupsAsString().clear();
                user.getGroupsAsString().addAll(i);
              }
              if (prefix != null) user.setValue("prefix", prefix);
              if (suffix != null) user.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing user: "******"Importing group: " + group);
            Group gr = wd.getGroup(group);
            try {
              List<String> p = gConfig.getStringList("groups." + group + ".permissions");
              List<String> i = gConfig.getStringList("groups." + group + ".inheritance");

              String prefix = gConfig.getString("groups." + group + ".info." + "prefix");
              String suffix = gConfig.getString("groups." + group + ".info." + "suffix");

              if (gConfig.getBoolean("groups." + group + ".default")) {
                wd.setDefaultGroup(group);
                System.out.println("DEFAULT GROUP DETECTED: " + group);
              }
              if (p != null) gr.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                List<String> fp = new ArrayList<String>();
                for (int j = 0; j < i.size(); j++) {
                  String fpp = i.get(j);
                  if (fpp.startsWith("g:")) {
                    // do nothing
                  } else {
                    fp.add(fpp);
                  }
                }
                i.clear();
                i.addAll(fp);
                gr.getGroupsAsString().addAll(i);
              }
              if (prefix != null) gr.setValue("prefix", prefix);
              if (suffix != null) gr.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing group: " + group);
            }
          }
        wd.save();
      }
    }
    wm.cleanup();
  }
  public void importPEX() throws Exception {
    File file = new File("plugins/PermissionsEx/permissions.yml");
    // No point doing anything if the file doesn't exist
    if (!file.exists()) {
      System.err.println("File not exist");
      return;
    }
    YamlConfiguration perm = new YamlConfiguration();
    perm.load(file);

    World world = plugin.getServer().getWorlds().get(0);
    de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());

    ConfigurationSection users = perm.getConfigurationSection("users");
    ConfigurationSection groups = perm.getConfigurationSection("groups");

    if (users.getKeys(false) != null && users.getKeys(false).size() > 0) {
      for (String user : users.getKeys(false)) {
        List<String> g = users.getStringList(user + ".group");
        List<String> p = users.getStringList(user + ".permissions");
        User u = wd.getUser(user);
        // Remove the existing groups
        u.getGroupsAsString().clear();
        // Add all the groups
        if (g != null && g.size() > 0)
          for (String gr : g) {
            u.addGroup(gr);
          }
        if (p != null && p.size() > 0)
          for (String pr : p) {
            if (pr.startsWith("-")) {
              u.addPermission(pr.replace("-", ""), false);
            } else {
              u.addPermission(pr, true);
            }
          }
        String prefix = users.getString(user + ".prefix");
        if (prefix != null) u.setValue("prefix", prefix);
        String suffix = users.getString(user + ".suffix");
        if (suffix != null) u.setValue("suffix", suffix);
      }
    }

    if (groups.getKeys(false) != null && groups.getKeys(false).size() > 0) {
      for (String group : groups.getKeys(false)) {
        if (groups.getBoolean(group + ".default")) {
          wd.setDefaultGroup(group);
          System.out.println("DEFAULT GROUP DETECTED: " + group);
        }
        List<String> g = groups.getStringList(group + ".inheritance");
        List<String> p = groups.getStringList(group + ".permissions");
        Group u = wd.getGroup(group);
        // Remove the existing groups
        u.getGroupsAsString().clear();
        // Add all the groups
        if (g != null && g.size() > 0)
          for (String gr : g) {
            u.addGroup(gr);
          }
        if (p != null && p.size() > 0)
          for (String pr : p) {
            if (pr.startsWith("-")) {
              u.addPermission(pr.replace("-", ""), false);
            } else {
              u.addPermission(pr, true);
            }
          }
        String prefix = groups.getString(group + ".prefix");
        if (prefix != null) u.setValue("prefix", prefix);
        String suffix = groups.getString(group + ".suffix");
        if (suffix != null) u.setValue("suffix", suffix);
        String priority = groups.getString(group + ".options.rank");
        if (priority != null) u.setValue("priority", priority);
      }
    }
  }
 /*
  * Отправка цветного сообщения в консоль
  */
 public void SC(String msg) {
   plg.getServer()
       .getConsoleSender()
       .sendMessage(ChatColor.translateAlternateColorCodes('&', px + msg));
 }
 /*
  * Бродкаст сообщения, использую при отладке
  */
 public void BC(String msg) {
   plg.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', px + msg));
 }
  public void importPermissions3() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());

      File users = new File("plugins/Permissions/" + world.getName() + "/users.yml");
      File groups = new File("plugins/Permissions/" + world.getName() + "/groups.yml");

      if (users.exists() && groups.exists()) {
        System.out.println("Importing world: " + world.getName());

        YamlConfiguration uConfig = new YamlConfiguration();
        YamlConfiguration gConfig = new YamlConfiguration();
        try {
          uConfig.load(users);
          gConfig.load(groups);
        } catch (Exception e) {
          e.printStackTrace();
        }
        ConfigurationSection usConfig = uConfig.getConfigurationSection("users");
        ConfigurationSection grConfig = gConfig.getConfigurationSection("groups");

        Set<String> usersList = null;
        if (usConfig != null) usersList = usConfig.getKeys(false);
        Set<String> groupsList = null;
        if (grConfig != null) groupsList = grConfig.getKeys(false);

        if (usersList != null)
          for (String player : usersList) {
            System.out.println("Importing user: "******"users." + player + ".permissions");
              List<String> i = uConfig.getStringList("users." + player + ".groups");

              String prefix = uConfig.getString("users." + player + ".info." + "prefix");
              String suffix = uConfig.getString("users." + player + ".info." + "suffix");

              if (p != null) user.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                user.getGroupsAsString().clear();
                user.getGroupsAsString().addAll(i);
              }
              if (prefix != null) user.setValue("prefix", prefix);
              if (suffix != null) user.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing user: "******"Importing group: " + group);
            Group gr = wd.getGroup(group);
            try {
              List<String> p = gConfig.getStringList("groups." + group + ".permissions");
              List<String> i = gConfig.getStringList("groups." + group + ".inheritance");

              String prefix = gConfig.getString("groups." + group + ".info." + "prefix");
              String suffix = gConfig.getString("groups." + group + ".info." + "suffix");
              if (p != null) gr.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) gr.getGroupsAsString().addAll(i);
              if (prefix != null) gr.setValue("prefix", prefix);
              if (suffix != null) gr.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing group: " + group);
            }
          }
        wd.save();
      }
    }
    wm.cleanup();
  }
 public QuickPickup(JavaPlugin p) {
   p.getServer().getPluginManager().registerEvents(this, p);
 }
 public PlayerListener(JavaPlugin plugin) {
   plugin.getServer().getPluginManager().registerEvents(this, plugin);
 }
 @Override
 public void run() {
   for (Player player : plugin.getServer().getOnlinePlayers()) player.sendMessage(msg);
 }