mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Moved Guide History to Player Profiles
This commit is contained in:
parent
45a688e148
commit
07827ecc53
@ -5,8 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -246,7 +245,12 @@ public final class SlimefunGuide {
|
||||
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled")) return;
|
||||
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE")) return;
|
||||
|
||||
Object last = getLastEntry(p, false);
|
||||
Object last = null;
|
||||
|
||||
Optional<PlayerProfile> profile = PlayerProfile.find(p);
|
||||
if (profile.isPresent()) {
|
||||
last = getLastEntry(profile.get(), false);
|
||||
}
|
||||
|
||||
if (last == null)
|
||||
openMainMenuAsync(p, true, book, 1);
|
||||
@ -264,7 +268,7 @@ public final class SlimefunGuide {
|
||||
if (p == null) return;
|
||||
|
||||
if (survival) {
|
||||
clearHistory(p.getUniqueId());
|
||||
profile.getGuideHistory().clear();
|
||||
}
|
||||
|
||||
if (book) {
|
||||
@ -729,18 +733,19 @@ public final class SlimefunGuide {
|
||||
}
|
||||
|
||||
if (survival) {
|
||||
addToHistory(p, category);
|
||||
PlayerProfile.get(p, profile -> profile.getGuideHistory().add(category));
|
||||
}
|
||||
}
|
||||
|
||||
public static void openSearch(Player player, String searchTerm, boolean cheat, boolean addToHistory) {
|
||||
public static void openSearch(Player player, String input, boolean cheat, boolean addToHistory) {
|
||||
PlayerProfile.get(player, profile -> {
|
||||
final ChestMenu menu = new ChestMenu("Slimefun Guide Search");
|
||||
|
||||
menu.setEmptySlotsClickable(false);
|
||||
fillInv(menu, cheat);
|
||||
addBackButton(menu, 1, player, false, cheat);
|
||||
addBackButton(menu, 1, profile, false, cheat);
|
||||
|
||||
searchTerm = searchTerm.toLowerCase();
|
||||
String searchTerm = input.toLowerCase();
|
||||
|
||||
int index = 9;
|
||||
// Find items and add them
|
||||
@ -768,10 +773,11 @@ public final class SlimefunGuide {
|
||||
}
|
||||
|
||||
if (addToHistory) {
|
||||
addToHistory(player, searchTerm);
|
||||
profile.getGuideHistory().add(searchTerm);
|
||||
}
|
||||
|
||||
menu.open(player);
|
||||
});
|
||||
}
|
||||
|
||||
private static void fillInv(ChestMenu menu, boolean cheat) {
|
||||
@ -800,8 +806,8 @@ public final class SlimefunGuide {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addBackButton(ChestMenu menu, int slot, Player player, boolean book, boolean cheat) {
|
||||
List<Object> playerHistory = getHistory().getOrDefault(player.getUniqueId(), new LinkedList<>());
|
||||
private static void addBackButton(ChestMenu menu, int slot, PlayerProfile profile, boolean book, boolean cheat) {
|
||||
List<Object> playerHistory = profile.getGuideHistory();
|
||||
if (playerHistory != null && playerHistory.size() > 1) {
|
||||
|
||||
menu.addItem(slot, new CustomItem(new ItemStack(Material.ENCHANTED_BOOK),
|
||||
@ -813,7 +819,7 @@ public final class SlimefunGuide {
|
||||
menu.addMenuClickHandler(0, (pl, s, is, action) -> {
|
||||
if (action.isShiftClicked()) openMainMenuAsync(pl, true, false, 1);
|
||||
else {
|
||||
Object last = getLastEntry(pl, true);
|
||||
Object last = getLastEntry(profile, true);
|
||||
handleHistory(pl, last, book, cheat);
|
||||
}
|
||||
return false;
|
||||
@ -829,23 +835,14 @@ public final class SlimefunGuide {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addToHistory(Player p, Object obj) {
|
||||
LinkedList<Object> list = getHistory().computeIfAbsent(p.getUniqueId(), k -> new LinkedList<>());
|
||||
list.add(obj);
|
||||
}
|
||||
private static Object getLastEntry(PlayerProfile profile, boolean remove) {
|
||||
LinkedList<Object> history = profile.getGuideHistory();
|
||||
|
||||
private static Object getLastEntry(Player p, boolean remove) {
|
||||
LinkedList<Object> history = getHistory().get(p.getUniqueId());
|
||||
|
||||
if (remove && history != null && !history.isEmpty()) {
|
||||
if (remove && !history.isEmpty()) {
|
||||
history.removeLast();
|
||||
}
|
||||
|
||||
if (history != null && history.isEmpty()) {
|
||||
getHistory().remove(p.getUniqueId());
|
||||
}
|
||||
|
||||
return history == null || history.isEmpty() ? null: history.getLast();
|
||||
return history.isEmpty() ? null: history.getLast();
|
||||
}
|
||||
|
||||
private static void displayItem(Player p, final ItemStack item, boolean addToHistory, final boolean book, final int page) {
|
||||
@ -914,18 +911,22 @@ public final class SlimefunGuide {
|
||||
}
|
||||
}
|
||||
|
||||
if (addToHistory) addToHistory(p, sfItem != null ? sfItem: item);
|
||||
PlayerProfile profile = PlayerProfile.get(p);
|
||||
|
||||
addBackButton(menu, 0, p, book, false);
|
||||
addBackButton(menu, 0, profile, book, false);
|
||||
|
||||
LinkedList<Object> history = getHistory().get(p.getUniqueId());
|
||||
LinkedList<Object> history = profile.getGuideHistory();
|
||||
|
||||
if (addToHistory) {
|
||||
history.add(sfItem != null ? sfItem: item);
|
||||
}
|
||||
|
||||
if (history != null && history.size() > 1) {
|
||||
menu.addItem(0, new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), "&7\u21E6 Back", "", "&rLeft Click: &7Go back to previous Page", "&rShift + left Click: &7Go back to Main Menu"));
|
||||
menu.addMenuClickHandler(0, (pl, slot, itemstack, action) -> {
|
||||
if (action.isShiftClicked()) openMainMenuAsync(p, true, book, 1);
|
||||
else {
|
||||
Object last = getLastEntry(pl, true);
|
||||
Object last = getLastEntry(profile, true);
|
||||
handleHistory(pl, last, book, false);
|
||||
}
|
||||
return false;
|
||||
@ -1118,12 +1119,4 @@ public final class SlimefunGuide {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<UUID, LinkedList<Object>> getHistory() {
|
||||
return SlimefunPlugin.getUtilities().guideHistory;
|
||||
}
|
||||
|
||||
private static void clearHistory(UUID uuid) {
|
||||
getHistory().remove(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunGuide;
|
||||
|
||||
public interface GuideHandler {
|
||||
|
||||
@ -25,7 +24,7 @@ public interface GuideHandler {
|
||||
this.getRunnable(book).run(p);
|
||||
|
||||
if (survival && this.trackHistory()) {
|
||||
SlimefunGuide.addToHistory(p, this);
|
||||
PlayerProfile.get(p, profile -> profile.getGuideHistory().add(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -40,6 +41,8 @@ public final class PlayerProfile {
|
||||
|
||||
private final Set<Research> researches = new HashSet<>();
|
||||
private final Map<Integer, BackpackInventory> backpacks = new HashMap<>();
|
||||
private final LinkedList<Object> guideHistory = new LinkedList<>();
|
||||
|
||||
private final HashedArmorpiece[] armor = {
|
||||
new HashedArmorpiece(),
|
||||
new HashedArmorpiece(),
|
||||
@ -212,6 +215,10 @@ public final class PlayerProfile {
|
||||
return Bukkit.getPlayer(getUUID());
|
||||
}
|
||||
|
||||
public LinkedList<Object> getGuideHistory() {
|
||||
return guideHistory;
|
||||
}
|
||||
|
||||
public static PlayerProfile fromUUID(UUID uuid) {
|
||||
PlayerProfile profile = SlimefunPlugin.getUtilities().profiles.get(uuid);
|
||||
|
||||
@ -274,6 +281,10 @@ public final class PlayerProfile {
|
||||
return SlimefunPlugin.getUtilities().profiles.containsKey(uuid);
|
||||
}
|
||||
|
||||
public static Optional<PlayerProfile> find(OfflinePlayer p) {
|
||||
return Optional.ofNullable(SlimefunPlugin.getUtilities().profiles.get(p.getUniqueId()));
|
||||
}
|
||||
|
||||
public static Iterator<PlayerProfile> iterator() {
|
||||
return SlimefunPlugin.getUtilities().profiles.values().iterator();
|
||||
}
|
||||
|
@ -13,10 +13,9 @@ public class PlayerQuitListener implements Listener {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
SlimefunPlugin.getUtilities().guideHistory.remove(e.getPlayer().getUniqueId());
|
||||
|
||||
if (PlayerProfile.isLoaded(e.getPlayer().getUniqueId())) {
|
||||
PlayerProfile.get(e.getPlayer()).markForDeletion();
|
||||
}
|
||||
|
@ -125,8 +125,6 @@ public final class Utilities {
|
||||
public final Map<String, String> contributorHeads = new HashMap<>();
|
||||
public final List<Contributor> contributors = new ArrayList<>();
|
||||
|
||||
public final Map<UUID, LinkedList<Object>> guideHistory = new HashMap<>();
|
||||
|
||||
public final List<CargoTransportEvent> cargoTransportEvents = new ArrayList<>();
|
||||
|
||||
public ItemStack[] oreWasherOutputs;
|
||||
|
Loading…
Reference in New Issue
Block a user