diff --git a/main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java b/main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java index c9686cb..e5ff350 100644 --- a/main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java +++ b/main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java @@ -5,7 +5,6 @@ import io.github.thatsmusic99.headsplus.api.RLevel; import io.github.thatsmusic99.headsplus.api.events.CommunicateEvent; import io.github.thatsmusic99.headsplus.api.HeadsPlusAPI; -import io.github.thatsmusic99.headsplus.api.Level; import io.github.thatsmusic99.headsplus.commands.*; import io.github.thatsmusic99.headsplus.commands.maincommand.*; import io.github.thatsmusic99.headsplus.config.*; @@ -57,6 +56,7 @@ public class HeadsPlus extends JavaPlugin { + // Private variables for the plugin public final Logger log = Logger.getLogger("Minecraft"); private static HeadsPlus instance; private final PluginDescriptionFile pluginYml = getDescription(); @@ -67,6 +67,7 @@ public class HeadsPlus extends JavaPlugin { private static Object[] update = null; private Connection connection; private boolean con = false; + // Config variables private HeadsPlusMessagesConfig hpc; private HeadsPlusConfigHeads hpch; private HeadsPlusConfigHeadsX hpchx; @@ -81,6 +82,7 @@ public class HeadsPlus extends JavaPlugin { private HeadsPlusConfigItems items; private HeadsPlusConfigSounds sounds; private HeadsPlusConfigTextMenu menus; + // Other management stuff private final List challenges = new ArrayList<>(); private NMSManager nms; private final List commands = new ArrayList<>(); @@ -92,8 +94,13 @@ public class HeadsPlus extends JavaPlugin { @Override public void onEnable() { try { + // Set the instance instance = this; + + // Set up the NMS setupNMS(); + + // See if Messages config has to be set up before the locale (if NPE is thrown) try { hpc.getString("locale"); LocaleManager.class.newInstance().setupLocale(); @@ -101,27 +108,35 @@ public void onEnable() { hpc = new HeadsPlusMessagesConfig(true); LocaleManager.class.newInstance().setupLocale(); } + + // Build plugin instances createInstances(); + // Checks theme, believe it or not! debug("- Checking plugin theme.", 1); checkTheme(); debug("- Setting up favourites.json.", 1); - + // Handles recipes if (!getConfiguration().getPerks().getBoolean("disable-crafting")) { debug("- Recipes may be added. Creating...", 1); getServer().getPluginManager().registerEvents(new RecipePerms(), this); } + // If sellable heads are enabled and yet there isn't Vault if (!(econ()) && (getConfiguration().getPerks().getBoolean("sellHeads"))) { log.warning(hpc.getString("no-vault")); } + + // If Vault exists if (econ()) { setupPermissions(); } - + // Registers plugin events debug("- Registering listeners!", 1); registerEvents(); + + // Register debug("- Registering commands!", 1); registerCommands(); debug("- Registering subcommands!", 1); @@ -694,4 +709,8 @@ public void checkForMutuals() { } + + public void reloadDE() { + de.reload(); + } } diff --git a/main/java/io/github/thatsmusic99/headsplus/commands/maincommand/MCReload.java b/main/java/io/github/thatsmusic99/headsplus/commands/maincommand/MCReload.java index 119e21b..8b95c41 100644 --- a/main/java/io/github/thatsmusic99/headsplus/commands/maincommand/MCReload.java +++ b/main/java/io/github/thatsmusic99/headsplus/commands/maincommand/MCReload.java @@ -68,7 +68,7 @@ public void run() { HPPlayer.players.clear(); } }.runTaskLaterAsynchronously(HeadsPlus.getInstance(), 2); - + HeadsPlus.getInstance().reloadDE(); sender.sendMessage(reloadM); diff --git a/main/java/io/github/thatsmusic99/headsplus/config/HeadsPlusConfigTextMenu.java b/main/java/io/github/thatsmusic99/headsplus/config/HeadsPlusConfigTextMenu.java index 67fb636..3f72927 100644 --- a/main/java/io/github/thatsmusic99/headsplus/config/HeadsPlusConfigTextMenu.java +++ b/main/java/io/github/thatsmusic99/headsplus/config/HeadsPlusConfigTextMenu.java @@ -325,13 +325,19 @@ public static String translate(String section, String database, int page) throws .replaceAll("\\{page}", String.valueOf(page)) .replaceAll("\\{pages}", String.valueOf(ph.getTotalPages())))); Set it = ph.getContentsInPage(page).keySet(); + // System.out.println(it.size()); Collection it2 = ph.getContentsInPage(page).values(); + // System.out.println(it2.size()); for (int i = 0; i < it.size(); i++) { - int in = i + (ph.getContentsPerPage() * (ph.getCurrentPage() - 1)); - sb.append("\n").append(translateColors(ht.getConfig().getString("leaderboard.for-each-line") - .replaceAll("\\{pos}", String.valueOf(in)) - .replaceAll("\\{name}", ((OfflinePlayer)it.toArray()[i]).getName()) - .replaceAll("\\{score}", String.valueOf(it2.toArray()[i])))); + try { + int in = i + (ph.getContentsPerPage() * (ph.getCurrentPage() - 1)); + sb.append("\n").append(translateColors(ht.getConfig().getString("leaderboard.for-each-line") + .replaceAll("\\{pos}", String.valueOf(in)) + .replaceAll("\\{name}", ((OfflinePlayer)it.toArray()[i]).getName()) + .replaceAll("\\{score}", String.valueOf(it2.toArray()[i])))); + } catch (NullPointerException ignored) { + } + } return sb.toString(); } catch (IllegalArgumentException ex) { diff --git a/main/java/io/github/thatsmusic99/headsplus/listeners/DeathEvents.java b/main/java/io/github/thatsmusic99/headsplus/listeners/DeathEvents.java index c399280..6b129e1 100644 --- a/main/java/io/github/thatsmusic99/headsplus/listeners/DeathEvents.java +++ b/main/java/io/github/thatsmusic99/headsplus/listeners/DeathEvents.java @@ -36,7 +36,7 @@ public DeathEvents() { public final List ableEntities = new ArrayList<>(Arrays.asList(EntityType.BAT, EntityType.BLAZE, EntityType.CAVE_SPIDER, EntityType.CHICKEN, EntityType.COW, EntityType.CREEPER, EntityType.ENDER_DRAGON, EntityType.ENDERMAN, EntityType.ENDERMITE, EntityType.GHAST, EntityType.GUARDIAN, EntityType.HORSE, EntityType.IRON_GOLEM, EntityType.MAGMA_CUBE, EntityType.MUSHROOM_COW, EntityType.OCELOT, EntityType.PIG, EntityType.PIG_ZOMBIE, EntityType.RABBIT, EntityType.SHEEP, EntityType.SILVERFISH, EntityType.SKELETON, EntityType.SLIME, EntityType.SNOWMAN, EntityType.SPIDER, EntityType.SQUID, EntityType.VILLAGER, EntityType.WITCH, EntityType.WITHER, EntityType.ZOMBIE, EntityType.WOLF)); private final HeadsPlusConfigHeadsX hpchx = HeadsPlus.getInstance().getHeadsXConfig(); private final HeadsPlusConfigHeads hpch = HeadsPlus.getInstance().getHeadsConfig(); - public final HashMap>> heads = new HashMap<>(); + public static HashMap>> heads = new HashMap<>(); @EventHandler public void onEntityDeath(EntityDeathEvent e) { @@ -46,40 +46,46 @@ public void onEntityDeath(EntityDeathEvent e) { if (checkForMythicMob(e.getEntity())) return; HeadsPlusMainConfig c = hp.getConfiguration(); if (ableEntities.contains(e.getEntityType())) { - if (e.getEntity().getKiller() != null) { - if (!c.getWhitelist("world").getStringList("list").contains(e.getEntity().getWorld().getName())) { + if (!c.getWhitelist("world").getStringList("list").contains(e.getEntity().getWorld().getName())) { + if (e.getEntity().getKiller() != null) { if (!e.getEntity().getKiller().hasPermission("headsplus.bypass.whitelistw")) { if (c.getWhitelist("world").getBoolean("enabled")) { return; } } } - if (!c.getBlacklist("world").getStringList("list").contains(e.getEntity().getWorld().getName()) || e.getEntity().getKiller().hasPermission("headsplus.bypass.blacklistw") || !c.getBlacklist("world").getBoolean("enabled")) { - + if (c.getWhitelist("world").getBoolean("enabled")) { + return; + } + } + if (!c.getBlacklist("world").getStringList("list").contains(e.getEntity().getWorld().getName()) || e.getEntity().getKiller().hasPermission("headsplus.bypass.blacklistw") || !c.getBlacklist("world").getBoolean("enabled")) { String entity = e.getEntityType().toString().toLowerCase().replaceAll("_", ""); Random rand = new Random(); double chance1 = hpch.getConfig().getDouble(entity + ".chance"); double chance2 = (double) rand.nextInt(100); - if (HeadsPlus.getInstance().getNMS().getItemInHand(e.getEntity().getKiller()).containsEnchantment(Enchantment.LOOT_BONUS_MOBS) - && HeadsPlus.getInstance().getConfiguration().getMechanics().getBoolean("allow-looting-enchantment") - && !(HeadsPlus.getInstance().getConfiguration().getMechanics().getStringList("looting.ignored-entities").contains(e.getEntityType().name().replaceAll("_", "").toLowerCase()))) { - chance1 *= HeadsPlus.getInstance().getNMS().getItemInHand(e.getEntity().getKiller()).getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); + if (e.getEntity().getKiller() != null) { + if (HeadsPlus.getInstance().getNMS().getItemInHand(e.getEntity().getKiller()).containsEnchantment(Enchantment.LOOT_BONUS_MOBS) + && HeadsPlus.getInstance().getConfiguration().getMechanics().getBoolean("allow-looting-enchantment") + && !(HeadsPlus.getInstance().getConfiguration().getMechanics().getStringList("looting.ignored-entities").contains(e.getEntityType().name().replaceAll("_", "").toLowerCase()))) { + chance1 *= HeadsPlus.getInstance().getNMS().getItemInHand(e.getEntity().getKiller()).getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); + } } + if (chance1 == 0.0) return; if (chance2 <= chance1) { if (entity.equalsIgnoreCase("sheep") || entity.equalsIgnoreCase("parrot") || entity.equalsIgnoreCase("horse") || entity.equalsIgnoreCase("llama")) { - dropHead(e.getEntity(), e.getEntity().getKiller(), chance1 / 100 == 0 ? 1 : (int) (chance1 / 100)); + dropHead(e.getEntity(), e.getEntity().getKiller(), ((int) chance1 / 100) == 0 ? 1 : (int) (chance1 / 100)); } else { if (hpch.getConfig().getStringList(entity + ".name").isEmpty()) return; dropHead(e.getEntity(), e.getEntity().getKiller(), ((int) chance1 / 100) == 0 ? 1 : (int) (chance1 / 100)); } } } - } + } } catch (Exception ex) { new DebugPrint(ex, "Event (DeathEvents)", false, null); @@ -94,11 +100,16 @@ public void onPlayerDeath(PlayerDeathEvent ep) { HeadsPlusMainConfig c = hp.getConfiguration(); if (ep.getEntity().getKiller() != null) { if (!c.getWhitelist("world").getStringList("list").contains(ep.getEntity().getWorld().getName())) { - if (!ep.getEntity().getKiller().hasPermission("headsplus.bypass.whitelistw")) { - if (c.getWhitelist("world").getBoolean("enabled")) { - return; + if (ep.getEntity().getKiller() != null) { + if (!ep.getEntity().getKiller().hasPermission("headsplus.bypass.whitelistw")) { + if (c.getWhitelist("world").getBoolean("enabled")) { + return; + } } } + if (c.getWhitelist("world").getBoolean("enabled")) { + return; + } } if (c.getPerks().getStringList("drops.ignore-players").contains(ep.getEntity().getUniqueId().toString()) || c.getPerks().getStringList("drops.ignore-players").contains(ep.getEntity().getName())) return; @@ -107,10 +118,12 @@ public void onPlayerDeath(PlayerDeathEvent ep) { double chance1 = hpch.getConfig().getDouble("player.chance"); double chance2 = (double) rand.nextInt(100); NMSManager nms = hp.getNMS(); - if (nms.getItemInHand(ep.getEntity().getKiller()).containsEnchantment(Enchantment.LOOT_BONUS_MOBS) - && c.getMechanics().getBoolean("allow-looting-enchantment") - && !(c.getMechanics().getStringList("looting.ignored-entities").contains("player"))) { - chance1 *= HeadsPlus.getInstance().getNMS().getItemInHand(ep.getEntity().getKiller()).getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); + if (ep.getEntity().getKiller() != null) { + if (nms.getItemInHand(ep.getEntity().getKiller()).containsEnchantment(Enchantment.LOOT_BONUS_MOBS) + && c.getMechanics().getBoolean("allow-looting-enchantment") + && !(c.getMechanics().getStringList("looting.ignored-entities").contains("player"))) { + chance1 *= HeadsPlus.getInstance().getNMS().getItemInHand(ep.getEntity().getKiller()).getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); + } } if (chance1 == 0.0) return; if (chance2 <= chance1) { @@ -148,7 +161,7 @@ public void onPlayerDeath(PlayerDeathEvent ep) { PlayerHeadDropEvent event = new PlayerHeadDropEvent(ep.getEntity(), ep.getEntity().getKiller(), head, world, entityLoc); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - if (b) { + if (b && ep.getEntity().getKiller() != null) { hp.getEconomy().withdrawPlayer(ep.getEntity(), lostprice); ep.getEntity().sendMessage(hp.getMessagesConfig().getString("lost-money").replaceAll("\\{player}", ep.getEntity().getKiller().getName()).replaceAll("\\{price}", String.valueOf(lostprice))); } @@ -345,11 +358,11 @@ private void dropHead(Entity e, Player k, int a) { int thing; ItemStack i; List af = hasColor(e); + String mobName = e.getType().name().replaceAll("_", "").toLowerCase(); NMSManager nms = HeadsPlus.getInstance().getNMS(); try { if (af != null && !af.isEmpty()) { - thing = r.nextInt(af.size()); i = af.get(thing); } else { @@ -357,10 +370,7 @@ private void dropHead(Entity e, Player k, int a) { if (heads.get(e.getType()).get("default") == null) return; if (heads.get(e.getType()).get("default").size() < 1) return; if (e instanceof Sheep) { - thing = r.nextInt(hpch.getConfig().getStringList("sheep.name.default").size()); - - } else if (e instanceof Horse) { thing = r.nextInt(hpch.getConfig().getStringList("horse.name.default").size()); } else if (nms instanceof v1_12_NMS @@ -404,7 +414,9 @@ private void dropHead(Entity e, Player k, int a) { Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { world.dropItem(event.getLocation(), event.getSkull()); - HPPlayer.getHPPlayer(k).addXp(10); + if (k != null) { + HPPlayer.getHPPlayer(k).addXp(10); + } } } @@ -427,4 +439,10 @@ public EntityType prettyStringToEntity(String s) { } return null; } + + public void reload() { + heads = new HashMap<>(); + createList(); + setupHeads(); + } } \ No newline at end of file diff --git a/main/java/io/github/thatsmusic99/headsplus/listeners/LBEvents.java b/main/java/io/github/thatsmusic99/headsplus/listeners/LBEvents.java index ac6c3ea..552c750 100644 --- a/main/java/io/github/thatsmusic99/headsplus/listeners/LBEvents.java +++ b/main/java/io/github/thatsmusic99/headsplus/listeners/LBEvents.java @@ -18,13 +18,15 @@ public class LBEvents implements Listener { public void onHeadDrop(EntityHeadDropEvent e) { try { if (!e.isCancelled()) { - if (hp.isUsingLeaderboards()) { - if (hp.getConfiguration().getPerks().getBoolean("smite-player-if-they-get-a-head")) { - for (int i = 0; i < 5; i++) { - e.getLocation().getWorld().strikeLightning(e.getPlayer().getLocation()); + if (e.getPlayer() != null) { + if (hp.isUsingLeaderboards()) { + if (hp.getConfiguration().getPerks().getBoolean("smite-player-if-they-get-a-head")) { + for (int i = 0; i < 5; i++) { + e.getLocation().getWorld().strikeLightning(e.getPlayer().getLocation()); + } } + hp.getMySQLAPI().addOntoValue(e.getPlayer(), e.getEntityType().name(), "headspluslb", 1); } - hp.getMySQLAPI().addOntoValue(e.getPlayer(), e.getEntityType().name(), "headspluslb", 1); } } } catch (Exception ex) { @@ -37,13 +39,15 @@ public void onHeadDrop(EntityHeadDropEvent e) { public void onPHeadDrop(PlayerHeadDropEvent e) { try { if (!e.isCancelled()) { - if (hp.isUsingLeaderboards()) { - if (hp.getConfiguration().getPerks().getBoolean("smite-player-if-they-get-a-head")) { - for (int i = 0; i < 5; i++) { - e.getLocation().getWorld().strikeLightning(e.getKiller().getLocation()); + if (e.getKiller() != null) { + if (hp.isUsingLeaderboards()) { + if (hp.getConfiguration().getPerks().getBoolean("smite-player-if-they-get-a-head")) { + for (int i = 0; i < 5; i++) { + e.getLocation().getWorld().strikeLightning(e.getKiller().getLocation()); + } } + hp.getMySQLAPI().addOntoValue(e.getKiller(), "player", "headspluslb", 1); } - hp.getMySQLAPI().addOntoValue(e.getKiller(), "player", "headspluslb", 1); } } } catch (Exception ex) { diff --git a/main/resources/plugin.yml b/main/resources/plugin.yml index fcee8b7..db632d3 100644 --- a/main/resources/plugin.yml +++ b/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: io.github.thatsmusic99.headsplus.HeadsPlus name: HeadsPlus -version: 6.0.4-SNAPSHOT-1 +version: 6.0.4 api-version: 1.13 description: Spawns in heads with extra features. author: Thatsmusic99