Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Overdue protocolize 2.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi committed Nov 8, 2021
1 parent 58e32a6 commit 4103496
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 191 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ All messages support the placeholders in the table below. The API can be used to
|`%vanished%`|Whether the player is vanished or not|
|`%servername%`|The name of the server the player is connected to|
|`%servermotd%`|The MOTD of the server the player is connected to|
|`%traffic_downstream_input%`|Traffic received from downstream|
|`%traffic_downstream_output%`|Traffic sent downstream|
|`%traffic_upstream_input%`|Traffic received upstream|
|`%traffic_upstream_output%`|Traffic sent upstream|
|`%traffic_downstream_input_last_minute%`|Traffic received from downstream in the last minute|
|`%traffic_downstream_output_last_minute%`|Traffic sent downstream in the last minute|
|`%traffic_upstream_input_last_minute%`|Traffic received upstream in the last minute|
|`%traffic_upstream_output_last_minute%`|Traffic sent upstream in the last minute|
|`%luckperms_friendlyname%`|The friendly name of the player as set in LP _(LP required)_|
|`%luckperms_prefix%`|The prefix of the player _(LP required)_|
|`%luckperms_suffix%`|The suffix of the player _(LP required)_|
Expand Down
20 changes: 9 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'com.github.johnrengelman.shadow' version '7.1.0'
}

group 'com.danifoldi'
version '1.2.7'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
version '2.0.0'
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

repositories {
mavenCentral()
maven { url 'https://jitpack.io/' }
google()
maven { url 'https://papermc.io/repo/repository/maven-public/' }
maven { url 'https://jitpack.io/' }
maven { url 'https://mvn.exceptionflug.de/repository/exceptionflug-public/' }
}

dependencies {
compileOnly 'io.github.waterfallmc:waterfall-api:1.17-R0.1-SNAPSHOT'
compileOnly 'de.exceptionflug:protocolize-api:1.7.0-SNAPSHOT'
compileOnly 'de.exceptionflug:protocolize-items:1.7.0-SNAPSHOT'
compileOnly 'de.exceptionflug:protocolize-inventory:1.7.0-SNAPSHOT'
compileOnly 'de.exceptionflug:protocolize-world:1.7.0-SNAPSHOT'
compileOnly 'dev.simplix:protocolize-api:2.0.0'

compileOnly 'net.luckperms:api:5.3'
compileOnly 'com.github.LeonMangler:PremiumVanishAPI:2.6.3'
Expand All @@ -31,8 +29,8 @@ dependencies {

compileOnly 'org.jetbrains:annotations:21.0.1'
implementation 'javax.inject:javax.inject:1'
implementation 'com.google.dagger:dagger:2.37'
annotationProcessor 'com.google.dagger:dagger-compiler:2.37'
implementation 'com.google.dagger:dagger:2.40'
annotationProcessor 'com.google.dagger:dagger-compiler:2.40'
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.danifoldi.bungeegui.util.Pair;
import com.danifoldi.bungeegui.util.SoundUtil;
import com.danifoldi.bungeegui.util.StringUtil;
import de.exceptionflug.protocolize.world.SoundCategory;
import dev.simplix.protocolize.api.SoundCategory;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
Expand Down
40 changes: 31 additions & 9 deletions src/main/java/com/danifoldi/bungeegui/gui/GuiItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.danifoldi.bungeegui.util.Message;
import com.danifoldi.bungeegui.util.Pair;
import com.danifoldi.bungeegui.util.StringUtil;
import de.exceptionflug.protocolize.items.ItemStack;
import de.exceptionflug.protocolize.items.ItemType;
import dev.simplix.protocolize.api.item.ItemStack;
import dev.simplix.protocolize.data.ItemType;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.querz.nbt.tag.ByteTag;
import net.querz.nbt.tag.CompoundTag;
Expand Down Expand Up @@ -83,20 +83,42 @@ public boolean isEnchanted() {

public @NotNull ItemStack toItemStack(ProxiedPlayer placeholderTarget, String player, String target) {
final @NotNull ItemStack item = new ItemStack(this.getType());
item.setAmount((byte)this.getAmount());
item.setDisplayName(Message.toComponent(placeholderTarget, this.getName(), Pair.of("player", player), Pair.of("target", target)));
item.setLoreComponents(this.getLore().stream().map(l -> Message.toComponent(placeholderTarget, l, Pair.of("player", player), Pair.of("target", target))).collect(Collectors.toList()));
item
.amount((byte)this.getAmount())
.displayName(Message.toComponent(placeholderTarget, this.getName(), Pair.of("player", player), Pair.of("target", target)))
.lore(this.getLore().stream().map(l -> Message.toComponent(placeholderTarget, l, Pair.of("player", player), Pair.of("target", target))).collect(Collectors.toList()), false);

if (item.isPlayerSkull()) {
if (item.itemType().equals(ItemType.PLAYER_HEAD)) {
final Pair<String, String> data = StringUtil.get(this.getData());
if (data.getFirst().equalsIgnoreCase("owner")) {
item.setSkullOwner(Message.replace(data.getSecond(), Pair.of("player", player), Pair.of("target", target)));
final @NotNull CompoundTag tag = item.nbtData();
tag.put("SkullOwner", new StringTag(Message.replace(data.getSecond(), Pair.of("player", player), Pair.of("target", target))));
item.nbtData(tag);
} else if (data.getFirst().equalsIgnoreCase("texture")) {
item.setSkullTexture(Message.replace(data.getSecond(), Pair.of("player", player), Pair.of("target", target)));
final @NotNull CompoundTag tag = item.nbtData();
@Nullable CompoundTag skullOwnerTag = tag.getCompoundTag("SkullOwner");
@Nullable CompoundTag propertiesTag = tag.getCompoundTag("Properties");
final @NotNull ListTag<@NotNull CompoundTag> texturesTag = new ListTag<>(CompoundTag.class);
final @NotNull CompoundTag textureTag = new CompoundTag();

if (skullOwnerTag == null) {
skullOwnerTag = new CompoundTag();
}
if (propertiesTag == null) {
propertiesTag = new CompoundTag();
}

texturesTag.add(textureTag);
propertiesTag.put("textures", texturesTag);
skullOwnerTag.put("Properties", propertiesTag);
skullOwnerTag.put("Name", new StringTag(Message.replace(data.getSecond(), Pair.of("player", player), Pair.of("target", target))));

tag.put("SkullOwner", skullOwnerTag);
item.nbtData(tag);
}
}

final @NotNull CompoundTag tag = (CompoundTag)item.getNBTTag();
final @NotNull CompoundTag tag = item.nbtData();

if (this.isEnchanted()) {
final @NotNull ListTag<CompoundTag> enchantments = new ListTag<>(CompoundTag.class);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/danifoldi/bungeegui/gui/GuiSound.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.danifoldi.bungeegui.gui;

import com.danifoldi.bungeegui.util.SoundUtil;
import de.exceptionflug.protocolize.world.SoundCategory;
import dev.simplix.protocolize.api.SoundCategory;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
65 changes: 6 additions & 59 deletions src/main/java/com/danifoldi/bungeegui/main/BungeeGuiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import com.danifoldi.bungeegui.gui.GuiGrid;
import com.danifoldi.bungeegui.util.SoundUtil;
import de.exceptionflug.protocolize.inventory.Inventory;
import de.exceptionflug.protocolize.inventory.InventoryModule;
import de.exceptionflug.protocolize.inventory.InventoryType;
import de.exceptionflug.protocolize.inventory.event.InventoryClickEvent;
import de.exceptionflug.protocolize.inventory.event.InventoryCloseEvent;
import de.exceptionflug.protocolize.items.InventoryManager;
import de.exceptionflug.protocolize.items.PlayerInventory;
import de.exceptionflug.protocolize.items.event.PlayerInteractEvent;
import dev.simplix.protocolize.api.inventory.Inventory;
import dev.simplix.protocolize.api.inventory.InventoryClick;
import dev.simplix.protocolize.api.inventory.InventoryClose;
import dev.simplix.protocolize.data.inventory.InventoryType;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
Expand Down Expand Up @@ -38,63 +34,14 @@ public void onServerSwitch(final @NotNull ServerSwitchEvent event) {
guiHandler.actions(event.getPlayer());
}

@EventHandler
@SuppressWarnings("unused")
public void onItemClick(final @NotNull PlayerInteractEvent event) {
/*public void onItemClick(final @NotNull PlayerInteractEvent event) {
if (guiHandler.getOpenGui(event.getPlayer().getUniqueId()) != null) {
return;
}
PlayerInventory inventory = InventoryManager.getInventory(event.getPlayer().getUniqueId());
guiHandler.interact(event.getPlayer(), inventory.getHeldItem());
}

@EventHandler
@SuppressWarnings("unused")
public void onInventoryClick(final @NotNull InventoryClickEvent event) {
final @NotNull ProxiedPlayer player = event.getPlayer();

final @Nullable GuiGrid openGui = guiHandler.getOpenGui(event.getPlayer().getUniqueId());
if (openGui == null) {
return;
}

final @NotNull Inventory inventory = event.getInventory();
final int slot = event.getSlot();

if (inventory.getType().equals(InventoryType.PLAYER)) {
return;
}
if (slot == -999) {
return;
}

if (inventory.getItem(slot) == null) {
return;
}

if (openGui.getItems().get(slot).getClickSound() != null) {
if (SoundUtil.isValidSound(openGui.getItems().get(slot).getClickSound().getSoundName())) {
logger.warning("Sound " + openGui.getItems().get(slot).getClickSound().getSoundName() + " is probably invalid");
}
openGui.getItems().get(slot).getClickSound().playFor(player);
}

if (openGui.getItems().get(slot).getCommands().isEmpty()) {
return;
}

final @NotNull String target = guiHandler.getGuiTarget(player.getUniqueId());

guiHandler.runCommand(player,openGui, slot, target);
guiHandler.close(player, true);
}

@EventHandler
@SuppressWarnings("unused")
public void onInventoryClose(final @NotNull InventoryCloseEvent event) {
guiHandler.close(event.getPlayer(), false);
}
}*/

@EventHandler
@SuppressWarnings("unused")
Expand Down
68 changes: 53 additions & 15 deletions src/main/java/com/danifoldi/bungeegui/main/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.core.EnumGetMethod;
import dagger.Module;
import de.exceptionflug.protocolize.inventory.Inventory;
import de.exceptionflug.protocolize.inventory.InventoryModule;
import de.exceptionflug.protocolize.items.InventoryManager;
import de.exceptionflug.protocolize.items.ItemStack;
import de.exceptionflug.protocolize.items.ItemType;
import de.exceptionflug.protocolize.items.PlayerInventory;
import de.exceptionflug.protocolize.world.SoundCategory;
import dev.simplix.protocolize.api.Protocolize;
import dev.simplix.protocolize.api.SoundCategory;
import dev.simplix.protocolize.api.inventory.Inventory;
import dev.simplix.protocolize.data.ItemType;
import dev.simplix.protocolize.data.inventory.InventoryType;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.PluginManager;
Expand Down Expand Up @@ -207,18 +205,18 @@ void removeGui(final @NotNull String name) {
}

void actions(final @NotNull ProxiedPlayer player) {
PlayerInventory inventory = InventoryManager.getInventory(player.getUniqueId());
/*PlayerInventory inventory = InventoryManager.getInventory(player.getUniqueId());
guiActions
.stream()
.filter(a -> a.getServer().equalsIgnoreCase(player.getServer().getInfo().getName()))
.forEach(a -> inventory.setItem(a.getSlot(), a.getGuiItem().toItemStack(player, player.getName(), "")));
inventory.update();
inventory.update();*/
}

void interact(final @NotNull ProxiedPlayer player, final int slot) {
Optional<GuiAction> action = guiActions
/*Optional<GuiAction> action = guiActions
.stream()
.filter(a -> a.getServer().equalsIgnoreCase(player.getServer().getInfo().getName()))
.filter(a -> a.getSlot() == slot)
Expand All @@ -229,15 +227,15 @@ void interact(final @NotNull ProxiedPlayer player, final int slot) {
guiAction.getGuiItem().getClickSound().playFor(player);
}
open(guiAction.getGui(), player, null);
});
});*/
}

void open(final @NotNull String name, final @NotNull ProxiedPlayer player, final @Nullable String target) {
logger.info("Opening gui " + name + " for player " + player.getName() + " (target: " + target + ")");

final ProxiedPlayer placeholderTarget = menus.get(name).isRequireOnlineTarget() && menus.get(name).isPlaceholdersTarget() && ProxyServer.getInstance().getPlayer(target) != null ? ProxyServer.getInstance().getPlayer(target) : player;
final GuiGrid gui = menus.get(name);
final Inventory inventory = new Inventory(SlotUtil.getInventoryType(gui.getGuiSize()), Message.toComponent(placeholderTarget, gui.getTitle(), Pair.of("player", player.getName()), Pair.of("target", target)));
final Inventory inventory = new Inventory(SlotUtil.getInventoryType(gui.getGuiSize())).title(Message.toComponent(placeholderTarget, gui.getTitle(), Pair.of("player", player.getName()), Pair.of("target", target)));

if (gui.getOpenSound() != null) {
if (SoundUtil.isValidSound(gui.getOpenSound().getSoundName())) {
Expand All @@ -256,10 +254,50 @@ void open(final @NotNull String name, final @NotNull ProxiedPlayer player, final
continue;
}

inventory.setItem(guiItem.getKey(), guiItem.getValue().toItemStack(placeholderTarget, player.getName(), target));
inventory.item(guiItem.getKey(), guiItem.getValue().toItemStack(placeholderTarget, player.getName(), target));
}

InventoryModule.sendInventory(player, inventory);
inventory.onClick(event -> {
//final @NotNull ProxiedPlayer player = event.player().handle();

final @Nullable GuiGrid openGui = getOpenGui(player.getUniqueId());
if (openGui == null) {
return;
}

//final @NotNull Inventory inventory = event.inventory();
final int slot = event.slot();

if (inventory.type().equals(InventoryType.PLAYER)) {
return;
}
if (slot == -999) {
return;
}

if (inventory.item(slot) == null) {
return;
}

if (openGui.getItems().get(slot).getClickSound() != null) {
if (SoundUtil.isValidSound(openGui.getItems().get(slot).getClickSound().getSoundName())) {
logger.warning("Sound " + openGui.getItems().get(slot).getClickSound().getSoundName() + " is probably invalid");
}
openGui.getItems().get(slot).getClickSound().playFor(player);
}

if (openGui.getItems().get(slot).getCommands().isEmpty()) {
return;
}

//final @NotNull String target = guiHandler.getGuiTarget(player.getUniqueId());

runCommand(player,openGui, slot, target);
close(player, true);
});
inventory.onClose(event -> close(event.player().handle(), false));

Protocolize.playerProvider().player(player.getUniqueId()).openInventory(inventory);
openGuis.put(player.getUniqueId(), Pair.of(name, target));
}

Expand Down Expand Up @@ -319,7 +357,7 @@ void close(final @NotNull ProxiedPlayer player, final boolean didClick) {
logger.info("Removing gui from cache for " + player.getName());

openGuis.remove(player.getUniqueId());
InventoryModule.closeAllInventories(player);
Protocolize.playerProvider().player(player.getUniqueId()).closeInventory();
}

@Nullable GuiGrid getOpenGui(final @NotNull UUID uuid) {
Expand Down
Loading

0 comments on commit 4103496

Please sign in to comment.