Пример #1
0
  // Checks the item to the list in the config, gets the price, sees if the player has enough money,
  // gives the item to the player.
  private boolean itemChecker(String shop, Player player, ItemStack clickedItem) {

    // Checks to make sure the shop exists.
    Map<String, Object> shopItems;
    if (mobfighter.getConfig().getConfigurationSection("Shops").isConfigurationSection(shop))
      shopItems =
          mobfighter
              .getConfig()
              .getConfigurationSection("Shops")
              .getConfigurationSection(shop)
              .getValues(false);
    else return false;

    double price;

    // Double check that the shop has items then runs the rest.
    if (shopItems != null)
      for (String s : shopItems.keySet())
        if (clickedItem.getType().toString().equalsIgnoreCase(s)) {
          price = Double.parseDouble(shopItems.get(s).toString());
          if (VaultEco.getEconomy().getBalance(player) < price) {
            player.sendMessage(ChatColor.RED + "You do not have enough money!");
            return true;
          }
          VaultEco.getEconomy().withdrawPlayer(player, price);
          ItemStack item = new ItemStack(clickedItem);
          ItemMeta itemMeta = item.getItemMeta();
          itemMeta.setLore(null);
          item.setItemMeta(itemMeta);
          player.getInventory().addItem(item);
          player.updateInventory();
        }

    return true;
  }
Пример #2
0
 public VersionUpdater(JavaPlugin instance) {
   FileConfiguration fconf = instance.getConfig();
   List<String> messages = fconf.getStringList("Messages");
   int interval = fconf.getInt("Interval");
   boolean inSec = fconf.getBoolean("InSeconds");
   boolean debug = fconf.getBoolean("Debug");
   File configFile = new File(instance.getDataFolder(), "config.yml");
   configFile.delete();
   instance.saveDefaultConfig();
   instance.reloadConfig();
   fconf = instance.getConfig();
   fconf.set("Interval", interval);
   fconf.set("InSeconds", inSec);
   fconf.set("Debug", debug);
   fconf.set("Messages", messages);
   instance.saveConfig();
 }
Пример #3
0
 // Sets the configuration file's info in regards to the player's max health when they log off.
 @EventHandler(priority = EventPriority.NORMAL)
 public void logOff(PlayerQuitEvent e) {
   Player p = e.getPlayer();
   if (p.getMaxHealth() > 20) {
     mobfighter.getConfig().set("HealthBoost." + p.getDisplayName(), p.getMaxHealth());
     mobfighter.saveConfig();
   }
 }
Пример #4
0
  /**
   * Constructor for the ConsoleLogger.
   *
   * @param instance - The JavaPlugin instance that initiated this logmanager.
   * @param debug - If set to true, it will output debug info to the console.
   */
  public ConsoleLogger(JavaPlugin instance, String loggerName) {
    plugin = instance;
    this.logger = instance.getLogger();
    this.name = loggerName;

    ConsoleLogger.debug = plugin.getConfig().getBoolean("debug");

    ConsoleLogger.template = "v" + plugin.getDescription().getVersion() + ": ";
  }
Пример #5
0
  // 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);
    }
  }
Пример #6
0
  // No block breaking allowed on server.
  @EventHandler(priority = EventPriority.NORMAL)
  public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();

    // Block breaking allowed if the player has creative immunity.
    if (mobfighter.getConfig().getList("Creative Immunity").contains(player.getDisplayName()))
      return;

    event.setCancelled(true);
  }
Пример #7
0
 // Boosts the player's health based on the configuration file's info.
 @EventHandler(priority = EventPriority.NORMAL)
 public void logIn(PlayerLoginEvent e) {
   Player p = e.getPlayer();
   try {
     p.setMaxHealth(mobfighter.getConfig().getDouble("HealthBoost." + p.getDisplayName()));
   }
   // If the player isn't in the config file.
   catch (Exception ex) {
     p.resetMaxHealth();
   }
 }
Пример #8
0
 // Change kick message.
 @EventHandler
 public void onPlayerKick(PlayerKickEvent event) {
   if (!Utilities.getUtilities().onlyfirstjoin()) {
     String message = plugin.getConfig().getString("messages.kickmessage");
     if (!message.equalsIgnoreCase("none")) {
       event.setLeaveMessage(Utilities.getUtilities().format(message, event.getPlayer()));
     } else {
       event.setLeaveMessage(null);
     }
   }
 }
Пример #9
0
 public void printConfig(
     CommandSender p, int page, int lpp, boolean section, boolean usetranslation) {
   List<String> cfgprn = new ArrayList<String>();
   if (!plg.getConfig().getKeys(true).isEmpty())
     for (String k : plg.getConfig().getKeys(true)) {
       Object objvalue = plg.getConfig().get(k);
       String value = objvalue.toString();
       String str = k;
       if ((objvalue instanceof Boolean) && (usetranslation)) value = EnDis((Boolean) objvalue);
       if (objvalue instanceof MemorySection) {
         if (!section) continue;
       } else str = k + " : " + value;
       if (usetranslation) str = getMSG("cfgmsg_" + k.replaceAll("\\.", "_"), value);
       cfgprn.add(str);
     }
   String title =
       "&6&l"
           + this.project_current_version
           + " v"
           + des.getVersion()
           + " &r&6| "
           + getMSG("msg_config", '6');
   printPage(p, cfgprn, page, title, "", false);
 }
Пример #10
0
  // 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;
    }
  }
Пример #11
0
  public void loadConfig() {
    // copy default config.yml into place if it's not there
    File file = new File(getDataFolder(), "config.yml");
    if (!file.exists()) {
      jarUtil.copyConfigFromJar("config.yml", file);
    }

    if (!configLoaded) {
      super.getConfig();
      configLoaded = true;
    } else super.reloadConfig();

    logOresConfig = new LogOresConfig(this);
    logOresConfig.processConfig();

    if (blockListener != null) blockListener.reloadConfig();
    if (oreProcessor != null) oreProcessor.reloadConfig();
  }
Пример #12
0
 public Config(JavaPlugin plugin) {
   usePermissions = plugin.getConfig().getBoolean("config.usepermissions");
 }
Пример #13
0
 /**
  * Set whether or not to output debug information to the console.
  *
  * @param newstate - True to output, otherwise false.
  */
 public static synchronized void setDebug(boolean newstate) {
   ConsoleLogger.debug = newstate;
   plugin.getConfig().set("debug", newstate);
   plugin.saveConfig();
 }
Пример #14
0
 // Gets the list of sellable items from the configuration file.
 static void fillSellables() {
   sellingItems =
       mobfighter.getConfig().getConfigurationSection("Sellable Items").getValues(false);
 }
Пример #15
0
  // Handles player interaction with anvil while in or out of creative.
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.NORMAL)
  public void anvilFix(final InventoryClickEvent e) {
    if (!e.isCancelled()) {
      HumanEntity ent = e.getWhoClicked();

      // Anvil used with survival
      if (ent instanceof Player) {
        final Player player = (Player) ent;
        Inventory inv = e.getInventory();

        // Anvil used with creative:
        if (player.getGameMode() == GameMode.CREATIVE) {
          if (inv instanceof AnvilInventory) {
            AnvilInventory anvil = (AnvilInventory) inv;
            InventoryView view = e.getView();
            int rawSlot = e.getRawSlot();
            if (rawSlot == view.convertSlot(rawSlot)) {
              if (rawSlot == 2) {
                ItemStack[] items = anvil.getContents();
                ItemStack item1 = items[0];
                ItemStack item2 = items[1];
                if (item1 != null && item2 != null) {
                  int id1 = item1.getTypeId();
                  int id2 = item2.getTypeId();
                  if (id1 != 0 && id2 != 0) {
                    ItemStack item3 = e.getCurrentItem();
                    if (item3 != null) {
                      ItemMeta meta = item3.getItemMeta();
                      if (meta != null) {
                        // Player has to have 60 or more levels to use the creative combine.
                        if (player.getLevel() >= 60) {
                          player.setLevel(player.getLevel() - 60);
                          player.sendMessage(ChatColor.GREEN + "Repair/Combine Successful!");
                          Bukkit.getServer()
                              .getScheduler()
                              .scheduleSyncDelayedTask(
                                  mobfighter,
                                  new Runnable() {
                                    public void run() {
                                      // Bypass being set to survival after using anvil if the
                                      // player has creative immunity.
                                      if (mobfighter
                                          .getConfig()
                                          .getList("Creative Immunity")
                                          .contains(player.getDisplayName())) return;
                                      // Sets the player back to survival once the anvil is used.
                                      e.getWhoClicked().getOpenInventory().close();
                                      player.setGameMode(GameMode.SURVIVAL);
                                    }
                                  },
                                  20 * 2);
                        } // End of creative combine.
                      } // Didn't have enough levels to combine/finishing.
                    } // Item 3 was/wasn't null.
                  } // Item 1 & 2 id's were/weren't null.
                } // Item 1 & 2 was/wasn't null.
              } // End of (rawSlot == 2)
            } // End of convert view
          } // End of anvil inventory
          else {
            // Bypass having the player's inventory closed if they have creative immunity.
            if (mobfighter
                .getConfig()
                .getList("Creative Immunity")
                .contains(player.getDisplayName())) e.setCancelled(false);
            // Closes the player's inventory after the anvil is used.
            else {
              e.setCancelled(true);
              player.closeInventory();
            }
          }
        } // End of anvil with creative
      } // End of anvil with survival
    } // End of !isCancelled
  } // End of anvilFix
Пример #16
0
  // Handles multiple instances of player clicks.
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.HIGH)
  public void playerClick(PlayerInteractEvent event) {
    final Player player = event.getPlayer();

    if (event.getAction() == Action.RIGHT_CLICK_AIR
        || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
      // Creative mode switch
      if (player.getItemInHand().getType().equals(Material.BRICK)) {
        // Bypass switch and level loss.
        if (mobfighter.getConfig().getList("Creative Immunity").contains(player.getDisplayName()))
          return;
        if (player.getLevel() >= 60) {
          player.setItemInHand(new ItemStack(Material.AIR));
          player.setLevel(player.getLevel() - 60);
          player.setGameMode(GameMode.CREATIVE);
        } else
          player.sendMessage(ChatColor.RED + "You need to be at least level 60 to get creative!");
      }

      // Health Boost, Stat Boost, and Crafting
      if (player.getItemInHand().getType().equals(Material.RED_MUSHROOM)
          && player.getItemInHand().getItemMeta().hasDisplayName()
          && player
              .getItemInHand()
              .getItemMeta()
              .getDisplayName()
              .equalsIgnoreCase(ChatColor.DARK_RED + "Health Boost")) {
        int amount = player.getItemInHand().getAmount();
        player.setItemInHand(new ItemStack(Material.AIR));
        while (amount
            > 0) // Add health and refunds the money spent buying it if the player has used 5
                 // already.
        {
          if (player.getMaxHealth() >= 40) {
            player.setMaxHealth(40);
            player.sendMessage(ChatColor.RED + "Your health is already boosted to the max!");
            VaultEco.getEconomy()
                .depositPlayer(
                    player, Double.parseDouble(EliteShop.shop.getString("RED_MUSHROOM")));
            player.sendMessage(
                ChatColor.GREEN + "Refunded: $" + EliteShop.shop.getString("RED_MUSHROOM"));
          } else player.setMaxHealth(player.getMaxHealth() + 4);
          amount--;
        }
        if (player.getMaxHealth() > 20) // Sets max health in config and then reloads to apply.
        {
          mobfighter
              .getConfig()
              .set("HealthBoost." + player.getDisplayName(), player.getMaxHealth());
          mobfighter.saveConfig();
        }
      } else if (player.getItemInHand().getType().equals(Material.STONE_BUTTON)
          && player.getItemInHand().getItemMeta().hasDisplayName()
          && player
              .getItemInHand()
              .getItemMeta()
              .getDisplayName()
              .equalsIgnoreCase(ChatColor.GREEN + "Stat Boost")) {
        player.setItemInHand(new ItemStack(Material.AIR));
        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0));
        player.addPotionEffect(
            new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE, 0));
        player.addPotionEffect(
            new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
        player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, Integer.MAX_VALUE, 0));
        player.sendMessage(ChatColor.GREEN + "Stat Boost Activated!");
      } else if (player.getItemInHand().getType().equals(Material.WORKBENCH)) {
        if (mobfighter.getConfig().getList("Creative Immunity").contains(player.getDisplayName()))
          return;
        player.sendMessage(ChatColor.GRAY + "Type: /craft");
      }

      // Get special items for end-game armor set.
      if (player.getItemInHand().getType().equals(Material.SPONGE)) {
        player.getInventory().clear();
        ItemStack coal = new ItemStack(Material.COAL, 64);
        ItemMeta meta = coal.getItemMeta();
        meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Undead Heart");
        coal.setItemMeta(meta);
        int i = 0;
        while (i < 36) {
          player.getInventory().addItem(coal);
          i++;
        }
        player.updateInventory();
      }

      // Opens the main shop by right-clicking the shop paper.
      if (player.getItemInHand().getType().equals(Material.PAPER))
        player.openInventory(MainShop.getShop());
    } // End of Right-click

    if (event.getAction() == Action.LEFT_CLICK_AIR
        || event.getAction() == Action.LEFT_CLICK_BLOCK) {
      if (player.getItemInHand().getType().equals(Material.SPONGE)) {
        player.getInventory().clear();
        ItemStack emerald = new ItemStack(Material.EMERALD, 64);
        ItemMeta meta = emerald.getItemMeta();
        meta.setDisplayName(ChatColor.DARK_GREEN + "Tainted Soul");
        emerald.setItemMeta(meta);
        int n = 0;
        while (n < 36) {
          player.getInventory().addItem(emerald);
          n++;
        }
        player.updateInventory();
      }
    }
  }