mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-27 12:38:21 +01:00
Added details tab
This commit is contained in:
parent
3c1cdaafab
commit
ee5217519a
@ -38,6 +38,7 @@ import world.bentobox.level.events.IslandPreLevelEvent;
|
||||
import world.bentobox.level.objects.LevelsData;
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
import world.bentobox.level.panels.DetailsGUITab;
|
||||
import world.bentobox.level.panels.DetailsGUITab.DetailsType;
|
||||
|
||||
public class LevelsManager {
|
||||
private static final String INTOPTEN = "intopten";
|
||||
@ -226,7 +227,10 @@ public class LevelsManager {
|
||||
new TabbedPanelBuilder()
|
||||
.user(user)
|
||||
.world(world)
|
||||
.tab(1, new DetailsGUITab(addon, world, user))
|
||||
.tab(1, new DetailsGUITab(addon, world, user, DetailsType.ALL_BLOCKS))
|
||||
.tab(2, new DetailsGUITab(addon, world, user, DetailsType.ABOVE_SEA_LEVEL_BLOCKS))
|
||||
.tab(3, new DetailsGUITab(addon, world, user, DetailsType.UNDERWATER_BLOCKS))
|
||||
.tab(4, new DetailsGUITab(addon, world, user, DetailsType.SPAWNERS))
|
||||
.startingSlot(1)
|
||||
.size(54)
|
||||
.build().openPanel();
|
||||
@ -458,11 +462,9 @@ public class LevelsManager {
|
||||
private void setIslandResults(World world, @Nullable UUID owner, long level, Multiset<Material> uwCount,
|
||||
Multiset<Material> mdCount) {
|
||||
LevelsData ld = levelsCache.computeIfAbsent(owner, LevelsData::new);
|
||||
String worldName = world.getName();
|
||||
System.out.println("saved world name");
|
||||
ld.setLevel(world, level);
|
||||
ld.setUwCount(worldName, uwCount);
|
||||
ld.setMdCount(worldName, mdCount);
|
||||
ld.setUwCount(world, uwCount);
|
||||
ld.setMdCount(world, mdCount);
|
||||
levelsCache.put(owner, ld);
|
||||
handler.saveObjectAsync(ld);
|
||||
// Update TopTen
|
||||
@ -480,17 +482,4 @@ public class LevelsManager {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the island breakdown of blocks
|
||||
* @param world - world
|
||||
* @param user - user
|
||||
* @return report
|
||||
*/
|
||||
public List<PanelItem> getIslandReport(World world, UUID owner) {
|
||||
LevelsData ld = getLevelsData(owner);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package world.bentobox.level.objects;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -9,7 +10,6 @@ import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
@ -182,28 +182,44 @@ public class LevelsData implements DataObject {
|
||||
/**
|
||||
* @param uwCount the uwCount to set
|
||||
*/
|
||||
public void setUwCount(String name, Multiset<Material> uwCount) {
|
||||
Map<Material, Integer> count = new HashMap<>();
|
||||
uwCount.forEach(m -> count.put(m, uwCount.count(m)));
|
||||
public void setUwCount(World world, Multiset<Material> uwCount) {
|
||||
if (this.uwCount == null) {
|
||||
System.out.println("Null");
|
||||
this.uwCount = new HashMap<>();
|
||||
}
|
||||
this.uwCount.put(name, count);
|
||||
Map<Material, Integer> count = new HashMap<>();
|
||||
uwCount.forEach(m -> count.put(m, uwCount.count(m)));
|
||||
|
||||
this.uwCount.put(world.getName(), count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mdCount the mdCount to set
|
||||
*/
|
||||
public void setMdCount(String name, Multiset<Material> mdCount) {
|
||||
Map<Material, Integer> count = new HashMap<>();
|
||||
mdCount.forEach(m -> count.put(m, mdCount.count(m)));
|
||||
public void setMdCount(World world, Multiset<Material> mdCount) {
|
||||
if (this.mdCount == null) {
|
||||
System.out.println("Null");
|
||||
this.mdCount = new HashMap<>();
|
||||
}
|
||||
this.mdCount.put(name, count);
|
||||
Map<Material, Integer> count = new HashMap<>();
|
||||
mdCount.forEach(m -> count.put(m, mdCount.count(m)));
|
||||
|
||||
this.mdCount.put(world.getName(), count);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underwater block count for world
|
||||
* @return the uwCount
|
||||
*/
|
||||
public Map<Material, Integer> getUwCount(World world) {
|
||||
return uwCount.getOrDefault(world.getName(), Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the over-water block count for world
|
||||
* @return the mdCount
|
||||
*/
|
||||
public Map<Material, Integer> getMdCount(World world) {
|
||||
return mdCount.getOrDefault(world.getName(), Collections.emptyMap());
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,20 +5,28 @@ package world.bentobox.level.panels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Enums;
|
||||
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.panels.Tab;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.level.Level;
|
||||
import world.bentobox.level.objects.LevelsData;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -26,14 +34,161 @@ import world.bentobox.level.Level;
|
||||
*/
|
||||
public class DetailsGUITab implements Tab, ClickHandler {
|
||||
|
||||
private final Level addon;
|
||||
private final World world;
|
||||
private final User user;
|
||||
public enum DetailsType {
|
||||
ABOVE_SEA_LEVEL_BLOCKS,
|
||||
ALL_BLOCKS,
|
||||
SPAWNERS,
|
||||
UNDERWATER_BLOCKS
|
||||
}
|
||||
|
||||
public DetailsGUITab(Level addon, World world, User user) {
|
||||
private static final Map<Material, Material> M2I;
|
||||
static {
|
||||
Map<Material, Material> m2i = new HashMap<>();
|
||||
m2i.put(Material.WATER, Material.WATER_BUCKET);
|
||||
m2i.put(Material.LAVA, Material.LAVA_BUCKET);
|
||||
m2i.put(Material.AIR, Material.BLACK_STAINED_GLASS_PANE);
|
||||
m2i.put(Material.VOID_AIR, Material.BLACK_STAINED_GLASS_PANE);
|
||||
m2i.put(Material.CAVE_AIR, Material.BLACK_STAINED_GLASS_PANE);
|
||||
m2i.put(Material.WALL_TORCH, Material.TORCH);
|
||||
m2i.put(Material.REDSTONE_WALL_TORCH, Material.REDSTONE_TORCH);
|
||||
m2i.put(Material.TALL_SEAGRASS, Material.SEAGRASS);
|
||||
m2i.put(Material.PISTON_HEAD, Material.PISTON);
|
||||
m2i.put(Material.MOVING_PISTON, Material.PISTON);
|
||||
m2i.put(Material.REDSTONE_WIRE, Material.REDSTONE);
|
||||
m2i.put(Material.NETHER_PORTAL, Material.MAGENTA_STAINED_GLASS_PANE);
|
||||
m2i.put(Material.END_PORTAL, Material.BLACK_STAINED_GLASS_PANE);
|
||||
m2i.put(Material.ATTACHED_MELON_STEM, Material.MELON_SEEDS);
|
||||
m2i.put(Material.ATTACHED_PUMPKIN_STEM, Material.PUMPKIN_SEEDS);
|
||||
m2i.put(Material.MELON_STEM, Material.MELON_SEEDS);
|
||||
m2i.put(Material.PUMPKIN_STEM, Material.PUMPKIN_SEEDS);
|
||||
m2i.put(Material.COCOA, Material.COCOA_BEANS);
|
||||
m2i.put(Material.TRIPWIRE, Material.STRING);
|
||||
m2i.put(Material.CARROTS, Material.CARROT);
|
||||
m2i.put(Material.POTATOES, Material.POTATO);
|
||||
m2i.put(Material.BEETROOTS, Material.BEETROOT);
|
||||
m2i.put(Material.END_GATEWAY, Material.BEDROCK);
|
||||
m2i.put(Material.FROSTED_ICE, Material.ICE);
|
||||
m2i.put(Material.KELP_PLANT, Material.KELP);
|
||||
m2i.put(Material.BUBBLE_COLUMN, Material.WATER_BUCKET);
|
||||
m2i.put(Material.SWEET_BERRY_BUSH, Material.SWEET_BERRIES);
|
||||
m2i.put(Material.BAMBOO_SAPLING, Material.BAMBOO);
|
||||
// 1.16.1
|
||||
if (Enums.getIfPresent(Material.class, "WEEPING_VINES_PLANT").isPresent()) {
|
||||
m2i.put(Material.WEEPING_VINES_PLANT, Material.WEEPING_VINES);
|
||||
m2i.put(Material.TWISTING_VINES_PLANT, Material.TWISTING_VINES);
|
||||
m2i.put(Material.SOUL_WALL_TORCH, Material.SOUL_TORCH);
|
||||
}
|
||||
|
||||
|
||||
M2I = Collections.unmodifiableMap(m2i);
|
||||
}
|
||||
private final Level addon;
|
||||
private final @Nullable Island island;
|
||||
private List<PanelItem> items;
|
||||
private DetailsType type;
|
||||
private final User user;
|
||||
private final World world;
|
||||
|
||||
public DetailsGUITab(Level addon, World world, User user, DetailsType type) {
|
||||
this.addon = addon;
|
||||
this.world = world;
|
||||
this.user = user;
|
||||
this.island = addon.getIslands().getIsland(world, user);
|
||||
this.type = type;
|
||||
// Generate report
|
||||
generateReport(type);
|
||||
}
|
||||
|
||||
private void createItem(Material m, Integer count) {
|
||||
if (count == null || count <= 0) return;
|
||||
// Convert walls
|
||||
m = Enums.getIfPresent(Material.class, m.name().replace("WALL_", "")).or(m);
|
||||
// Tags
|
||||
if (Tag.FIRE.isTagged(m)) {
|
||||
items.add(new PanelItemBuilder()
|
||||
.icon(Material.CAMPFIRE)
|
||||
.name(Util.prettifyText(m.name()) + " x " + count)
|
||||
.build());
|
||||
return;
|
||||
}
|
||||
if (Tag.FLOWER_POTS.isTagged(m)) {
|
||||
m = Enums.getIfPresent(Material.class, m.name().replace("POTTED_", "")).or(m);
|
||||
}
|
||||
items.add(new PanelItemBuilder()
|
||||
.icon(M2I.getOrDefault(m, m))
|
||||
.name(Util.prettifyText(m.name()) + " x " + count)
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
private void generateReport(DetailsType type) {
|
||||
items = new ArrayList<>();
|
||||
LevelsData ld = addon.getManager().getLevelsData(island.getOwner());
|
||||
// Get the items from the report
|
||||
Map<Material, Integer> sumTotal = new HashMap<>();
|
||||
sumTotal.putAll(ld.getMdCount(world));
|
||||
sumTotal.putAll(ld.getUwCount(world));
|
||||
switch(type) {
|
||||
case ABOVE_SEA_LEVEL_BLOCKS:
|
||||
ld.getMdCount(world).forEach(this::createItem);
|
||||
break;
|
||||
case SPAWNERS:
|
||||
sumTotal.entrySet().stream().filter(m -> m.getKey().equals(Material.SPAWNER)).forEach(e -> createItem(e.getKey(), e.getValue()));
|
||||
break;
|
||||
case UNDERWATER_BLOCKS:
|
||||
ld.getUwCount(world).forEach(this::createItem);
|
||||
break;
|
||||
default:
|
||||
sumTotal.forEach(this::createItem);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PanelItem getIcon() {
|
||||
switch(type) {
|
||||
case ABOVE_SEA_LEVEL_BLOCKS:
|
||||
return new PanelItemBuilder().icon(Material.GRASS_BLOCK).name("Above Sea Level Blocks").build();
|
||||
case SPAWNERS:
|
||||
return new PanelItemBuilder().icon(Material.SPAWNER).name("Spawners").build();
|
||||
case UNDERWATER_BLOCKS:
|
||||
return new PanelItemBuilder().icon(Material.WATER_BUCKET).name("Underwater Blocks").build();
|
||||
default:
|
||||
return new PanelItemBuilder().icon(Material.GRASS_BLOCK).name("All Blocks").build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String name = "&c No island!";
|
||||
if (island.getOwner() != null) {
|
||||
name = island.getName() != null ? island.getName() : addon.getPlayers().getName(island.getOwner()) + "'s island";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<@Nullable PanelItem> getPanelItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
switch(type) {
|
||||
case ABOVE_SEA_LEVEL_BLOCKS:
|
||||
return "";
|
||||
case ALL_BLOCKS:
|
||||
return "";
|
||||
case SPAWNERS:
|
||||
return "";
|
||||
case UNDERWATER_BLOCKS:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,26 +196,4 @@ public class DetailsGUITab implements Tab, ClickHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PanelItem getIcon() {
|
||||
// TODO Auto-generated method stub
|
||||
return new PanelItemBuilder().icon(Material.GRASS_BLOCK).name("Blocks").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Island Details";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<@Nullable PanelItem> getPanelItems() {
|
||||
// Get the items from the report
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user