Fix "/is admin level" page 3+ in 1.12-, also remove gaps

This commit is contained in:
Esophose 2019-02-22 00:54:16 -07:00
parent 1912bcd5e8
commit 3163f5a734
4 changed files with 1094 additions and 492 deletions

View File

@ -56,7 +56,7 @@ public class ValueCommand extends SubCommand {
materials = Materials.fromString(player.getItemInHand().getType().name());
}
if (materials != null && levellingManager.containsMaterials(materials)) {
if (materials != null && levellingManager.containsMaterial(materials)) {
Material material = levellingManager.getMaterial(materials);
double level = (double) material.getPoints()
/ (double) fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))

View File

@ -1,5 +1,23 @@
package me.goodandevil.skyblock.levelling;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.api.event.island.IslandLevelChangeEvent;
import me.goodandevil.skyblock.config.FileManager.Config;
@ -12,23 +30,6 @@ import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.version.NMSUtil;
import me.goodandevil.skyblock.utils.version.Sounds;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
public class LevellingManager {
@ -196,15 +197,15 @@ public class LevellingManager {
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString("Materials") != null) {
for (String materialList : configLoad.getConfigurationSection("Materials").getKeys(false)) {
for (String materialKey : configLoad.getConfigurationSection("Materials").getKeys(false)) {
try {
Materials materials = Materials.fromString(materialList);
Materials material = Materials.fromString(materialKey);
if (!containsMaterials(materials)) {
addMaterial(materials, configLoad.getInt("Materials." + materialList + ".Points"));
if (!containsMaterial(material)) {
addMaterial(material, configLoad.getInt("Materials." + materialKey + ".Points"));
}
} catch (Exception e) {
Bukkit.getServer().getLogger().log(Level.WARNING, "SkyBlock | Error: The material '" + materialList
Bukkit.getServer().getLogger().log(Level.WARNING, "SkyBlock | Error: The material '" + materialKey
+ "' is not a Material type. Make sure the material name is a 1.13 material name. Please correct this in the 'levelling.yml' file.");
}
}
@ -223,7 +224,7 @@ public class LevellingManager {
materialStorage.remove(material);
}
public boolean containsMaterials(Materials materials) {
public boolean containsMaterial(Materials materials) {
for (Material materialList : materialStorage) {
if (materialList.getMaterials().name().equals(materials.name())) {
return true;

View File

@ -3,6 +3,7 @@ package me.goodandevil.skyblock.menus.admin;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -13,6 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -56,6 +58,16 @@ public class Levelling implements Listener {
List<me.goodandevil.skyblock.levelling.Material> levellingMaterials = levellingManager.getMaterials();
// Filter out materials that won't be displayed in the GUI properly
Inventory testInventory = Bukkit.createInventory(null, 9);
levellingMaterials = levellingMaterials.stream().filter(x -> {
ItemStack itemStack = new ItemStack(MaterialUtil.correctMaterial(x.getItemStack().getType()), 1, x.getItemStack().getDurability());
if (itemStack == null || itemStack.getItemMeta() == null) return false;
testInventory.clear();
testInventory.setItem(0, itemStack);
return testInventory.getItem(0) != null;
}).collect(Collectors.toList());
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
@ -315,7 +327,7 @@ public class Levelling implements Listener {
messageManager.sendMessage(player,
configLoad.getString("Island.Admin.Levelling.Permission.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
} else if (levellingManager.containsMaterials(materials)) {
} else if (levellingManager.containsMaterial(materials)) {
if (event1.getName().matches("[0-9]+")) {
int materialPoints = Integer.valueOf(event1.getName());
materialList.setPoints(materialPoints);
@ -427,7 +439,7 @@ public class Levelling implements Listener {
materials = Materials.fromString(event.getCurrentItem().getType().name());
}
if (levellingManager.containsMaterials(materials)) {
if (levellingManager.containsMaterial(materials)) {
messageManager.sendMessage(player, configLoad.getString("Island.Admin.Levelling.Already.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);