mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-23 02:35:25 +01:00
Island levelling improvements
This commit is contained in:
parent
868ec061c9
commit
abddc11159
@ -4,7 +4,7 @@ import me.goodandevil.skyblock.command.SubCommand;
|
||||
import me.goodandevil.skyblock.config.FileManager;
|
||||
import me.goodandevil.skyblock.config.FileManager.Config;
|
||||
import me.goodandevil.skyblock.levelling.LevellingManager;
|
||||
import me.goodandevil.skyblock.levelling.Material;
|
||||
import me.goodandevil.skyblock.levelling.LevellingMaterial;
|
||||
import me.goodandevil.skyblock.message.MessageManager;
|
||||
import me.goodandevil.skyblock.sound.SoundManager;
|
||||
import me.goodandevil.skyblock.utils.NumberUtil;
|
||||
@ -46,7 +46,7 @@ public class ValueCommand extends SubCommand {
|
||||
}
|
||||
|
||||
if (materials != null && levellingManager.containsMaterial(materials)) {
|
||||
Material material = levellingManager.getMaterial(materials);
|
||||
LevellingMaterial material = levellingManager.getMaterial(materials);
|
||||
double level = (double) material.getPoints()
|
||||
/ (double) fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||
.getFileConfiguration().getInt("Island.Levelling.Division");
|
||||
|
@ -738,6 +738,9 @@ public class IslandManager {
|
||||
|
||||
setNextAvailableLocation(world, islandLocation);
|
||||
saveNextAvailableLocation(world);
|
||||
|
||||
// Recalculate island level
|
||||
Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> skyblock.getLevellingManager().calculatePoints(null, island), 20L);
|
||||
}
|
||||
|
||||
public Set<UUID> getVisitorsAtIsland(Island island) {
|
||||
|
@ -1,23 +1,5 @@
|
||||
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;
|
||||
@ -30,12 +12,22 @@ 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.*;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class LevellingManager {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
private List<Material> materialStorage = new ArrayList<>();
|
||||
private List<LevellingMaterial> materialStorage = new ArrayList<>();
|
||||
|
||||
public LevellingManager(SkyBlock skyblock) {
|
||||
this.skyblock = skyblock;
|
||||
@ -59,8 +51,6 @@ public class LevellingManager {
|
||||
if (!chunk.isComplete()) return;
|
||||
cancel();
|
||||
|
||||
Map<String, Integer> materials = new HashMap<>();
|
||||
|
||||
Method getBlockTypeMethod = null;
|
||||
Method getBlockTypeIdMethod = null;
|
||||
Method getBlockTypeDataMethod = null;
|
||||
@ -76,6 +66,8 @@ public class LevellingManager {
|
||||
}
|
||||
}
|
||||
|
||||
Map<LevellingData, Integer> levellingData = new HashMap<>();
|
||||
|
||||
for (ChunkSnapshot chunkSnapshotList : chunk.getChunkSnapshots()) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
@ -114,51 +106,33 @@ public class LevellingManager {
|
||||
blockData = (int) getBlockTypeDataMethod.invoke(chunkSnapshotList, x, y, z);
|
||||
}
|
||||
|
||||
if (blockMaterial == org.bukkit.Material.AIR) continue;
|
||||
if (blockMaterial == org.bukkit.Material.AIR)
|
||||
continue;
|
||||
|
||||
for (Material materialList : materialStorage) {
|
||||
if (materialList == null) continue;
|
||||
ItemStack is;
|
||||
try {
|
||||
is = materialList.getItemStack();
|
||||
} catch (Exception ignored) {
|
||||
continue;
|
||||
int amount = 1;
|
||||
if (blockMaterial == Materials.SPAWNER.parseMaterial()
|
||||
&& Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
|
||||
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
|
||||
com.songoda.epicspawners.api.EpicSpawners epicSpawners =
|
||||
com.songoda.epicspawners.api.EpicSpawnersAPI.getImplementation();
|
||||
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
|
||||
if (epicSpawners.getSpawnerManager().isSpawner(location)) {
|
||||
amount = epicSpawners.getSpawnerManager()
|
||||
.getSpawnerFromWorld(location).getSpawnerDataCount();
|
||||
}
|
||||
|
||||
if (blockMaterial != materialList.getItemStack().getType()) continue;
|
||||
if (NMSVersion < 13) {
|
||||
if (blockData != is.getData().getData()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
if (blockMaterial == Materials.SPAWNER.parseMaterial()
|
||||
&& Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
|
||||
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
|
||||
com.songoda.epicspawners.api.EpicSpawners epicSpawners =
|
||||
com.songoda.epicspawners.api.EpicSpawnersAPI.getImplementation();
|
||||
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
|
||||
if (epicSpawners.getSpawnerManager().isSpawner(location)) {
|
||||
amount = epicSpawners.getSpawnerManager()
|
||||
.getSpawnerFromWorld(location).getSpawnerDataCount();
|
||||
}
|
||||
} else if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial)) {
|
||||
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
|
||||
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
|
||||
if (stackableManager.isStacked(location)) {
|
||||
Stackable stackable = stackableManager.getStack(location, blockMaterial);
|
||||
amount = stackable.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
if (materials.containsKey(materialList.getMaterials().name())) {
|
||||
materials.put(materialList.getMaterials().name(),
|
||||
materials.get(materialList.getMaterials().name()) + amount);
|
||||
} else {
|
||||
materials.put(materialList.getMaterials().name(), amount);
|
||||
} else if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial)) {
|
||||
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
|
||||
Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z);
|
||||
if (stackableManager.isStacked(location)) {
|
||||
Stackable stackable = stackableManager.getStack(location, blockMaterial);
|
||||
amount = stackable.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
LevellingData data = new LevellingData(blockMaterial, (byte)blockData);
|
||||
Integer totalAmountInteger = levellingData.get(data);
|
||||
int totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount;
|
||||
levellingData.put(data, totalAmount);
|
||||
} catch (IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
@ -168,6 +142,12 @@ public class LevellingManager {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Integer> materials = new HashMap<>();
|
||||
for (LevellingData data : levellingData.keySet()) {
|
||||
int amount = levellingData.get(data);
|
||||
materials.put(data.getMaterials().name(), amount);
|
||||
}
|
||||
|
||||
if (materials.size() == 0) {
|
||||
if (player != null) {
|
||||
skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager()
|
||||
@ -218,15 +198,15 @@ public class LevellingManager {
|
||||
}
|
||||
|
||||
public void addMaterial(Materials materials, int points) {
|
||||
materialStorage.add(new Material(materials, points));
|
||||
materialStorage.add(new LevellingMaterial(materials, points));
|
||||
}
|
||||
|
||||
public void removeMaterial(Material material) {
|
||||
public void removeMaterial(LevellingMaterial material) {
|
||||
materialStorage.remove(material);
|
||||
}
|
||||
|
||||
public boolean containsMaterial(Materials materials) {
|
||||
for (Material materialList : materialStorage) {
|
||||
for (LevellingMaterial materialList : materialStorage) {
|
||||
if (materialList.getMaterials().name().equals(materials.name())) {
|
||||
return true;
|
||||
}
|
||||
@ -235,8 +215,8 @@ public class LevellingManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Material getMaterial(Materials materials) {
|
||||
for (Material materialList : materialStorage) {
|
||||
public LevellingMaterial getMaterial(Materials materials) {
|
||||
for (LevellingMaterial materialList : materialStorage) {
|
||||
if (materialList.getMaterials().name().equals(materials.name())) {
|
||||
return materialList;
|
||||
}
|
||||
@ -245,7 +225,40 @@ public class LevellingManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Material> getMaterials() {
|
||||
public List<LevellingMaterial> getMaterials() {
|
||||
return materialStorage;
|
||||
}
|
||||
|
||||
private class LevellingData {
|
||||
private final Material material;
|
||||
private final byte data;
|
||||
|
||||
private LevellingData(Material material, byte data) {
|
||||
this.material = material;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof LevellingData)) return false;
|
||||
LevellingData data = (LevellingData)obj;
|
||||
if (this == obj) return true;
|
||||
return this.material == data.material && this.data == data.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.material, this.data);
|
||||
}
|
||||
|
||||
private Materials getMaterials() {
|
||||
if (NMSUtil.getVersionNumber() > 12) {
|
||||
try {
|
||||
return Materials.fromString(material.name());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
return Materials.getMaterials(this.material, this.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.goodandevil.skyblock.utils.version.Materials;
|
||||
|
||||
public class Material {
|
||||
public class LevellingMaterial {
|
||||
|
||||
private Materials materials;
|
||||
private int points;
|
||||
|
||||
public Material(Materials materials, int points) {
|
||||
public LevellingMaterial(Materials materials, int points) {
|
||||
this.materials = materials;
|
||||
this.points = points;
|
||||
}
|
@ -2,6 +2,7 @@ package me.goodandevil.skyblock.menus;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
@ -193,9 +194,10 @@ public class Levelling {
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
Map<String, Integer> testIslandMaterials = level.getMaterials();
|
||||
Map<String, Integer> islandMaterials = new HashMap<>();
|
||||
Map<String, Integer> islandMaterials = level.getMaterials();
|
||||
|
||||
Config mainConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
|
||||
Config settingsConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||
|
||||
// Filter out ItemStacks that can't be displayed in the inventory
|
||||
Inventory testInventory = Bukkit.createInventory(null, 9);
|
||||
@ -204,12 +206,12 @@ public class Levelling {
|
||||
continue;
|
||||
if (mainConfig.getFileConfiguration().getInt("Materials." + materialName + ".Points") <= 0)
|
||||
continue;
|
||||
|
||||
|
||||
Materials materials = Materials.fromString(materialName);
|
||||
ItemStack is = materials.parseItem();
|
||||
is.setAmount(testIslandMaterials.get(materialName));
|
||||
is.setAmount(Math.min(testIslandMaterials.get(materialName), 64));
|
||||
is.setType(MaterialUtil.correctMaterial(is.getType()));
|
||||
|
||||
|
||||
if (is == null || is.getItemMeta() == null) continue;
|
||||
testInventory.clear();
|
||||
testInventory.setItem(0, is);
|
||||
@ -270,27 +272,30 @@ public class Levelling {
|
||||
if (materials != null) {
|
||||
int materialAmount = islandMaterials.get(material);
|
||||
|
||||
if (mainConfig.getFileConfiguration()
|
||||
.getString("Materials." + material + ".Points") != null) {
|
||||
int pointsRequired = mainConfig.getFileConfiguration()
|
||||
.getInt("Materials." + material + ".Points");
|
||||
if (mainConfig.getFileConfiguration().getString("Materials." + material + ".Points") != null) {
|
||||
int pointsMultiplier = mainConfig.getFileConfiguration().getInt("Materials." + material + ".Points");
|
||||
|
||||
if (pointsRequired != 0) {
|
||||
if (settingsConfig.getFileConfiguration().getBoolean("Island.Levelling.IncludeEmptyPointsInList") || pointsMultiplier != 0) {
|
||||
inventorySlot++;
|
||||
|
||||
int pointsEarned = materialAmount * pointsRequired;
|
||||
int pointsEarned = materialAmount * pointsMultiplier;
|
||||
|
||||
ItemStack is = materials.parseItem();
|
||||
is.setAmount(materialAmount);
|
||||
is.setType(MaterialUtil.correctMaterial(is.getType()));
|
||||
|
||||
System.out.println(MaterialUtil.correctMaterial(is.getType()).name() + " | " + material);
|
||||
|
||||
List<String> lore = configLoad.getStringList("Menu.Levelling.Item.Material.Lore");
|
||||
lore.replaceAll(x -> x.replace("%blocks", NumberUtil.formatNumberByDecimal(materialAmount)));
|
||||
|
||||
nInv.addItem(nInv.createItem(is, configLoad
|
||||
.getString("Menu.Levelling.Item.Material.Displayname")
|
||||
.replace("%points", NumberUtil.formatNumberByDecimal(pointsEarned))
|
||||
.replace("%material",
|
||||
WordUtils.capitalize(material.toLowerCase().replace("_", " ")
|
||||
.replace("item", "").replace("block", ""))),
|
||||
null, null, null, null), inventorySlot);
|
||||
.getString("Menu.Levelling.Item.Material.Displayname")
|
||||
.replace("%points", NumberUtil.formatNumberByDecimal(pointsEarned))
|
||||
.replace("%material",
|
||||
WordUtils.capitalize(material.toLowerCase().replace("_", " ")
|
||||
.replace("item", "").replace("block", ""))),
|
||||
lore, null, null, null), inventorySlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.goodandevil.skyblock.levelling.LevellingMaterial;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -56,7 +57,7 @@ public class Levelling implements Listener {
|
||||
|
||||
PlayerData playerData = skyblock.getPlayerDataManager().getPlayerData(player);
|
||||
|
||||
List<me.goodandevil.skyblock.levelling.Material> levellingMaterials = levellingManager.getMaterials();
|
||||
List<LevellingMaterial> levellingMaterials = levellingManager.getMaterials();
|
||||
|
||||
// Filter out materials that won't be displayed in the GUI properly
|
||||
Inventory testInventory = Bukkit.createInventory(null, 9);
|
||||
@ -121,7 +122,7 @@ public class Levelling implements Listener {
|
||||
if (levellingMaterials.size() > index) {
|
||||
inventorySlot++;
|
||||
|
||||
me.goodandevil.skyblock.levelling.Material material = levellingMaterials.get(index);
|
||||
LevellingMaterial material = levellingMaterials.get(index);
|
||||
nInv.addItem(
|
||||
nInv.createItem(
|
||||
new ItemStack(MaterialUtil.correctMaterial(material.getItemStack().getType()), 1,
|
||||
@ -311,7 +312,7 @@ public class Levelling implements Listener {
|
||||
}
|
||||
|
||||
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
|
||||
for (me.goodandevil.skyblock.levelling.Material materialList : levellingManager.getMaterials()) {
|
||||
for (LevellingMaterial materialList : levellingManager.getMaterials()) {
|
||||
Materials materials = materialList.getMaterials();
|
||||
|
||||
if (event.getCurrentItem().getType() == MaterialUtil.correctMaterial(materials.parseMaterial())
|
||||
|
@ -23,6 +23,8 @@ public class MaterialUtil {
|
||||
material = Material.TRIPWIRE_HOOK;
|
||||
} else if (material == Material.FLOWER_POT) {
|
||||
material = Materials.LEGACY_FLOWER_POT_ITEM.getPostMaterial();
|
||||
} else if (material.name().startsWith("POTTED_")) {
|
||||
material = Material.FLOWER_POT;
|
||||
} else if (material == Materials.LEGACY_IRON_DOOR_BLOCK.getPostMaterial()) {
|
||||
material = Material.IRON_DOOR;
|
||||
} else if (material == Material.CAULDRON) {
|
||||
|
@ -162,6 +162,8 @@ Island:
|
||||
# time cycle or be fixed.
|
||||
Cycle: false
|
||||
Levelling:
|
||||
# Include Points: 0 in the '/is level' GUI
|
||||
IncludeEmptyPointsInList: true
|
||||
# Island Level Points divided by value
|
||||
Division: 100
|
||||
Cooldown:
|
||||
|
@ -1842,6 +1842,8 @@ Menu:
|
||||
Displayname: "&c&oNothing to see here..."
|
||||
Material:
|
||||
Displayname: "&7%material &8(&e+%points Points&8)"
|
||||
Lore:
|
||||
- "&8(&e%blocks Blocks&8)"
|
||||
Settings:
|
||||
Categories:
|
||||
Title: "&8Settings - Categories"
|
||||
|
Loading…
Reference in New Issue
Block a user