feat(check gui): dynamic gui
This commit is contained in:
parent
d0488bae84
commit
8a53b2f188
6 changed files with 65 additions and 6 deletions
|
@ -9,13 +9,19 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import xyz.ineanto.nicko.NickoBukkit;
|
import xyz.ineanto.nicko.NickoBukkit;
|
||||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||||
|
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||||
|
import xyz.ineanto.nicko.gui.PlayerCheckGUIData;
|
||||||
import xyz.ineanto.nicko.i18n.I18N;
|
import xyz.ineanto.nicko.i18n.I18N;
|
||||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||||
import xyz.ineanto.nicko.storage.name.PlayerNameStore;
|
import xyz.ineanto.nicko.storage.name.PlayerNameStore;
|
||||||
|
import xyz.xenondevs.invui.window.Window;
|
||||||
|
import xyz.xenondevs.invui.window.WindowManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -61,5 +67,16 @@ public class PlayerJoinListener implements Listener {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 20L);
|
}, 20L);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") final ArrayList<UUID> viewers = (ArrayList<UUID>) PlayerCheckGUIData.VIEWERS.clone();
|
||||||
|
viewers.forEach(uuid -> {
|
||||||
|
final Player windowWatcher = Bukkit.getPlayer(uuid);
|
||||||
|
final Window openWindow = WindowManager.getInstance().getOpenWindow(windowWatcher);
|
||||||
|
if (openWindow != null) {
|
||||||
|
final PlayerCheckGUI gui = new PlayerCheckGUI(windowWatcher, Bukkit.getOnlinePlayers());
|
||||||
|
openWindow.close();
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
package xyz.ineanto.nicko.event;
|
package xyz.ineanto.nicko.event;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import xyz.ineanto.nicko.NickoBukkit;
|
import xyz.ineanto.nicko.NickoBukkit;
|
||||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||||
|
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||||
|
import xyz.ineanto.nicko.gui.PlayerCheckGUIData;
|
||||||
|
import xyz.xenondevs.invui.window.Window;
|
||||||
|
import xyz.xenondevs.invui.window.WindowManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerQuitListener implements Listener {
|
public class PlayerQuitListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -15,5 +25,20 @@ public class PlayerQuitListener implements Listener {
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
NickoBukkit.getInstance().getLogger().warning("Failed to save data for " + player.getName());
|
NickoBukkit.getInstance().getLogger().warning("Failed to save data for " + player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a dirty way to do it but could be worse tbh
|
||||||
|
@SuppressWarnings("unchecked") final ArrayList<UUID> viewers = (ArrayList<UUID>) PlayerCheckGUIData.VIEWERS.clone();
|
||||||
|
viewers.forEach(uuid -> {
|
||||||
|
final Player windowWatcher = Bukkit.getPlayer(uuid);
|
||||||
|
final Window openWindow = WindowManager.getInstance().getOpenWindow(windowWatcher);
|
||||||
|
if (openWindow != null) {
|
||||||
|
final List<? extends Player> playersWithoutOffline = Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.filter(online -> online.getUniqueId() != player.getUniqueId()).collect(Collectors.toList());
|
||||||
|
final PlayerCheckGUI gui = new PlayerCheckGUI(windowWatcher, playersWithoutOffline);
|
||||||
|
openWindow.close();
|
||||||
|
gui.open();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,9 @@ import xyz.xenondevs.invui.gui.structure.Markers;
|
||||||
import xyz.xenondevs.invui.item.Item;
|
import xyz.xenondevs.invui.item.Item;
|
||||||
import xyz.xenondevs.invui.window.Window;
|
import xyz.xenondevs.invui.window.Window;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerCheckGUI {
|
public class PlayerCheckGUI {
|
||||||
|
@ -23,13 +25,15 @@ public class PlayerCheckGUI {
|
||||||
private final Gui gui;
|
private final Gui gui;
|
||||||
private final String title;
|
private final String title;
|
||||||
|
|
||||||
public PlayerCheckGUI(Player player) {
|
public PlayerCheckGUI(Player player, Collection<? extends Player> players) {
|
||||||
final I18N i18n = new I18N(player);
|
final I18N i18n = new I18N(player);
|
||||||
this.title = i18n.translatePrefixless(I18NDict.GUI.Titles.CHECK);
|
this.title = i18n.translatePrefixless(I18NDict.GUI.Titles.CHECK);
|
||||||
|
|
||||||
final List<Item> items = Bukkit.getOnlinePlayers().stream()
|
final List<Item> items = players.stream()
|
||||||
.map(Entity::getUniqueId)
|
.map(Entity::getUniqueId)
|
||||||
.map(uuid -> new PlayerInformationItem(i18n, Bukkit.getPlayer(uuid)))
|
.map(Bukkit::getPlayer)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(mappedPlayer -> new PlayerInformationItem(i18n, mappedPlayer))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
final AdminGUI parent = new AdminGUI(player);
|
final AdminGUI parent = new AdminGUI(player);
|
||||||
|
@ -56,6 +60,9 @@ public class PlayerCheckGUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open() {
|
public void open() {
|
||||||
Window.single().setGui(gui).setTitle(title).open(player);
|
final Window.Builder.Normal.Single window = Window.single().setGui(gui).setTitle(title);
|
||||||
|
window.addOpenHandler(() -> PlayerCheckGUIData.VIEWERS.add(player.getUniqueId()));
|
||||||
|
window.addCloseHandler(() -> PlayerCheckGUIData.VIEWERS.remove(player.getUniqueId()));
|
||||||
|
window.open(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package xyz.ineanto.nicko.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerCheckGUIData {
|
||||||
|
public static final ArrayList<UUID> VIEWERS = new ArrayList<>();
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package xyz.ineanto.nicko.gui.items.admin;
|
package xyz.ineanto.nicko.gui.items.admin;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||||
|
@ -22,7 +23,7 @@ public class ManagePlayerItem {
|
||||||
final ItemBuilder builder = new ItemBuilder(Material.WRITABLE_BOOK);
|
final ItemBuilder builder = new ItemBuilder(Material.WRITABLE_BOOK);
|
||||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.MANAGE_PLAYER);
|
return i18n.translateItem(builder, I18NDict.GUI.Admin.MANAGE_PLAYER);
|
||||||
}, click -> {
|
}, click -> {
|
||||||
new PlayerCheckGUI(player).open();
|
new PlayerCheckGUI(player, Bukkit.getOnlinePlayers()).open();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package xyz.ineanto.nicko.gui.items.admin.check;
|
package xyz.ineanto.nicko.gui.items.admin.check;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
@ -72,7 +73,7 @@ public class PlayerInformationItem extends AsyncItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {
|
public void onCancel() {
|
||||||
new PlayerCheckGUI(player).open();
|
new PlayerCheckGUI(player, Bukkit.getOnlinePlayers()).open();
|
||||||
}
|
}
|
||||||
}).open();
|
}).open();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue