mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-23 18:45:17 +01:00
Adds a details gui for the island.
This commit is contained in:
parent
66b098ec73
commit
3c1cdaafab
@ -21,11 +21,14 @@ import org.bukkit.World;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Multiset;
|
||||
|
||||
import world.bentobox.bentobox.api.events.addon.AddonBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.addon.AddonEvent;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -34,6 +37,7 @@ import world.bentobox.level.events.IslandLevelCalculatedEvent;
|
||||
import world.bentobox.level.events.IslandPreLevelEvent;
|
||||
import world.bentobox.level.objects.LevelsData;
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
import world.bentobox.level.panels.DetailsGUITab;
|
||||
|
||||
public class LevelsManager {
|
||||
private static final String INTOPTEN = "intopten";
|
||||
@ -118,11 +122,17 @@ public class LevelsManager {
|
||||
addon.getPipeliner().addIsland(island).thenAccept(r -> {
|
||||
// Results are irrelevant because the island is unowned or deleted, or IslandLevelCalcEvent is cancelled
|
||||
if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) {
|
||||
addon.logWarning("Island calcs stopped due to event cancelation");
|
||||
result.complete(null);
|
||||
}
|
||||
// Save result
|
||||
setIslandLevel(island.getWorld(), island.getOwner(), r.getLevel());
|
||||
addon.logWarning("Saving results");
|
||||
setIslandResults(island.getWorld(), island.getOwner(), r.getLevel(), r.getUwCount(), r.getMdCount());
|
||||
// Save top ten
|
||||
addon.logWarning("Saving top ten");
|
||||
addon.getManager().saveTopTen(island.getWorld());
|
||||
// Save the island scan details
|
||||
addon.logWarning("Saved");
|
||||
result.complete(r);
|
||||
});
|
||||
return result;
|
||||
@ -211,7 +221,18 @@ public class LevelsManager {
|
||||
}
|
||||
|
||||
// Add yourself
|
||||
panel.item(49, getHead(0, this.getIslandLevel(world, user.getUniqueId()), user.getUniqueId(), user, world));
|
||||
PanelItem head = getHead(0, this.getIslandLevel(world, user.getUniqueId()), user.getUniqueId(), user, world);
|
||||
head.setClickHandler((p, u, ch, s) -> {
|
||||
new TabbedPanelBuilder()
|
||||
.user(user)
|
||||
.world(world)
|
||||
.tab(1, new DetailsGUITab(addon, world, user))
|
||||
.startingSlot(1)
|
||||
.size(54)
|
||||
.build().openPanel();
|
||||
return true;
|
||||
});
|
||||
panel.item(49, head);
|
||||
panel.build();
|
||||
}
|
||||
|
||||
@ -426,6 +447,28 @@ public class LevelsManager {
|
||||
addToTopTen(world, targetPlayer, levelsCache.get(targetPlayer).getLevel(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the island level for the owner of the island that targetPlayer is a member
|
||||
* @param world - world
|
||||
* @param owner
|
||||
* @param level
|
||||
* @param uwCount
|
||||
* @param mdCount
|
||||
*/
|
||||
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);
|
||||
levelsCache.put(owner, ld);
|
||||
handler.saveObjectAsync(ld);
|
||||
// Update TopTen
|
||||
addToTopTen(world, owner, ld.getLevel(world));
|
||||
}
|
||||
|
||||
private Long updateLevel(UUID uuid, World world) {
|
||||
if (handler.objectExists(uuid.toString())) {
|
||||
@Nullable
|
||||
@ -437,6 +480,17 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -473,9 +473,9 @@ public class IslandLevelCalculator {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Collection<String> sortedReport(int total, Multiset<Material> MaterialCount) {
|
||||
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
|
||||
Collection<String> r = new ArrayList<>();
|
||||
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(MaterialCount).entrySet();
|
||||
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialCount).entrySet();
|
||||
for (Entry<Material> en : entriesSortedByCount) {
|
||||
Material type = en.getElement();
|
||||
|
||||
@ -491,6 +491,7 @@ public class IslandLevelCalculator {
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
private void tidyUp() {
|
||||
// Finalize calculations
|
||||
results.rawBlockCount.addAndGet((long)(results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));
|
||||
|
@ -89,5 +89,17 @@ public class Results {
|
||||
+ underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap
|
||||
+ ", pointsToNextLevel=" + pointsToNextLevel + ", initialLevel=" + initialLevel + "]";
|
||||
}
|
||||
/**
|
||||
* @return the mdCount
|
||||
*/
|
||||
public Multiset<Material> getMdCount() {
|
||||
return mdCount;
|
||||
}
|
||||
/**
|
||||
* @return the uwCount
|
||||
*/
|
||||
public Multiset<Material> getUwCount() {
|
||||
return uwCount;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
package world.bentobox.level.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
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;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
@ -35,6 +39,12 @@ public class LevelsData implements DataObject {
|
||||
@Expose
|
||||
private Map<String, Long> pointsToNextLevel = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
@Expose
|
||||
private Map<String, Map<Material, Integer>> uwCount = new HashMap<>();
|
||||
|
||||
@Expose
|
||||
private Map<String, Map<Material, Integer>> mdCount = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Create a level entry for target player
|
||||
* @param targetPlayer - target player
|
||||
@ -169,5 +179,32 @@ public class LevelsData implements DataObject {
|
||||
return pointsToNextLevel.getOrDefault(world.getName().toLowerCase(Locale.ENGLISH), 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)));
|
||||
if (this.uwCount == null) {
|
||||
System.out.println("Null");
|
||||
this.uwCount = new HashMap<>();
|
||||
}
|
||||
this.uwCount.put(name, 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)));
|
||||
if (this.mdCount == null) {
|
||||
System.out.println("Null");
|
||||
this.mdCount = new HashMap<>();
|
||||
}
|
||||
this.mdCount.put(name, count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
66
src/main/java/world/bentobox/level/panels/DetailsGUITab.java
Normal file
66
src/main/java/world/bentobox/level/panels/DetailsGUITab.java
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.level.panels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
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.level.Level;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class DetailsGUITab implements Tab, ClickHandler {
|
||||
|
||||
private final Level addon;
|
||||
private final World world;
|
||||
private final User user;
|
||||
|
||||
public DetailsGUITab(Level addon, World world, User user) {
|
||||
this.addon = addon;
|
||||
this.world = world;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
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