Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
6.0.4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Mar 31, 2019
1 parent c8bc61d commit 5500b86
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 44 deletions.
25 changes: 22 additions & 3 deletions main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -81,6 +82,7 @@ public class HeadsPlus extends JavaPlugin {
private HeadsPlusConfigItems items;
private HeadsPlusConfigSounds sounds;
private HeadsPlusConfigTextMenu menus;
// Other management stuff
private final List<Challenge> challenges = new ArrayList<>();
private NMSManager nms;
private final List<IHeadsPlusCommand> commands = new ArrayList<>();
Expand All @@ -92,36 +94,49 @@ 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();
} catch (NullPointerException ex) {
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);
Expand Down Expand Up @@ -694,4 +709,8 @@ public void checkForMutuals() {


}

public void reloadDE() {
de.reload();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void run() {
HPPlayer.players.clear();
}
}.runTaskLaterAsynchronously(HeadsPlus.getInstance(), 2);

HeadsPlus.getInstance().reloadDE();
sender.sendMessage(reloadM);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OfflinePlayer> it = ph.getContentsInPage(page).keySet();
// System.out.println(it.size());
Collection<Integer> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DeathEvents() {
public final List<EntityType> 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<EntityType, HashMap<String, List<ItemStack>>> heads = new HashMap<>();
public static HashMap<EntityType, HashMap<String, List<ItemStack>>> heads = new HashMap<>();

@EventHandler
public void onEntityDeath(EntityDeathEvent e) {
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -345,22 +358,19 @@ private void dropHead(Entity e, Player k, int a) {
int thing;
ItemStack i;
List<ItemStack> 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 {
if (heads.get(e.getType()) == null) return;
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
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -427,4 +439,10 @@ public EntityType prettyStringToEntity(String s) {
}
return null;
}

public void reload() {
heads = new HashMap<>();
createList();
setupHeads();
}
}
24 changes: 14 additions & 10 deletions main/java/io/github/thatsmusic99/headsplus/listeners/LBEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5500b86

Please sign in to comment.