Fixed compatibility issues on 1.12

This commit is contained in:
Lilac 2019-09-28 18:26:38 +01:00
parent 03b514551e
commit bba08bc0fe
3 changed files with 15 additions and 11 deletions

View File

@ -81,7 +81,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
public FileManager(EpicEnchants instance) {
super(instance);
directory = instance.isServerVersionAtLeast(ServerVersion.V1_12) ? "master" : "legacy";
directory = instance.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
Bukkit.getConsoleSender().sendMessage("Using the " + directory + " configurations because version is " + instance.getServerVersion().name());
}

View File

@ -35,7 +35,9 @@ public class EnchanterMenu extends FastInv {
int expCost = section.getInt("exp-cost");
int ecoCost = section.getInt("eco-cost");
int xpLeft = Math.max(expCost - player.getLevel(), 0);
double ecoLeft = ecoCost - instance.getEconomy().getBalance(player) < 0 ? 0 : ecoCost - instance.getEconomy().getBalance(player);
double ecoLeft = 0.0d;
if (instance.getEconomy() != null)
ecoLeft = ecoCost - instance.getEconomy().getBalance(player) < 0 ? 0 : ecoCost - instance.getEconomy().getBalance(player);
Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase())
.orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group")));
ItemStack itemStack = new ItemBuilder(section,
@ -50,18 +52,20 @@ public class EnchanterMenu extends FastInv {
return;
}
if (!instance.getEconomy().hasBalance((player), ecoCost) || getExp(player) < expCost) {
if (instance.getEconomy() != null && !instance.getEconomy().hasBalance((player), ecoCost) || getExp(player) < expCost) {
instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player);
return;
}
instance.getEconomy().withdrawBalance(player, ecoCost);
instance.getLocale().getMessage("enchanter.success")
.processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor())
.processPlaceholder("eco_cost", ecoCost)
.processPlaceholder("exp_cost", expCost)
.sendPrefixedMessage(player);
if (instance.getEconomy() != null) {
instance.getEconomy().withdrawBalance(player, ecoCost);
instance.getLocale().getMessage("enchanter.success")
.processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor())
.processPlaceholder("eco_cost", ecoCost)
.processPlaceholder("exp_cost", expCost)
.sendPrefixedMessage(player);
}
changeExp(player, -expCost);
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));

View File

@ -19,7 +19,7 @@ public class ItemGroup {
public ItemGroup(EpicEnchants instance) {
groupMap = HashMultimap.create();
if (instance.isServerVersionAtLeast(ServerVersion.V1_12)) setupMaster();
if (instance.isServerVersionAtLeast(ServerVersion.V1_13)) setupMaster();
else setupLegacy();
}