Skip to content

Commit

Permalink
Replace #408
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Nov 29, 2023
1 parent fea8e03 commit a0dcf36
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

public abstract class AbstractInventory<T extends NegativityHolder> {

public static final List<AbstractInventory<?>> INVENTORIES = new ArrayList<>();
private static final List<AbstractInventory<?>> INVENTORIES = new ArrayList<>();
public static List<AbstractInventory<?>> getInventories() {
return INVENTORIES;
}

private final NegativityInventory type;
private final Class<T> holderExample;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public InventoryManager() {
new WarnProcessorManagerInventory();
new SeeWarnInventory();
new SeeProofInventory();
AbstractInventory.INVENTORIES.forEach(AbstractInventory::load);
AbstractInventory.getInventories().forEach(AbstractInventory::load);
}

@SuppressWarnings({ "rawtypes" })
Expand All @@ -81,7 +81,7 @@ public void onInventoryClick(InventoryClickEvent e) {
if(!(holder instanceof NegativityHolder))
return;
NegativityHolder nh = ((NegativityHolder) holder).getBasicHolder();
for(AbstractInventory inv : AbstractInventory.INVENTORIES) {
for(AbstractInventory inv : AbstractInventory.getInventories()) {
if(inv.isInstance(nh)) {
e.setCancelled(true);
Player p = e.getPlayer();
Expand All @@ -97,7 +97,7 @@ public void onInventoryClick(InventoryClickEvent e) {
}

public static Optional<AbstractInventory<?>> getInventory(NegativityInventory type) {
for(AbstractInventory<?> inv : AbstractInventory.INVENTORIES)
for(AbstractInventory<?> inv : AbstractInventory.getInventories())
if(inv.getType().equals(type))
return Optional.of(inv);
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import com.elikill58.negativity.api.entity.Player;
import com.elikill58.negativity.api.events.EventListener;
import com.elikill58.negativity.api.events.Listeners;
import com.elikill58.negativity.api.events.inventory.InventoryCloseEvent;
import com.elikill58.negativity.api.events.player.LoginEvent;
import com.elikill58.negativity.api.events.player.PlayerChatEvent;
import com.elikill58.negativity.api.events.player.LoginEvent.Result;
import com.elikill58.negativity.api.inventory.InventoryManager;
import com.elikill58.negativity.api.inventory.InventoryType;
import com.elikill58.negativity.api.inventory.AbstractInventory.NegativityInventory;
import com.elikill58.negativity.api.events.player.PlayerConnectEvent;
import com.elikill58.negativity.api.events.player.PlayerLeaveEvent;
import com.elikill58.negativity.api.events.player.PlayerTeleportEvent;
import com.elikill58.negativity.common.commands.ReportCommand;
import com.elikill58.negativity.common.inventories.hook.players.GlobalPlayerInventory;
import com.elikill58.negativity.universal.Adapter;
import com.elikill58.negativity.universal.Messages;
import com.elikill58.negativity.universal.SanctionnerType;
Expand Down Expand Up @@ -136,11 +141,24 @@ public void onTeleport(PlayerTeleportEvent e) {

@EventListener
public void onLeft(PlayerLeaveEvent e) {
WebhookManager.getWebhooks().forEach(w -> w.clean(e.getPlayer()));
Player p = e.getPlayer();
WebhookManager.getWebhooks().forEach(w -> w.clean(p));
GlobalPlayerInventory.PLAYER_SEE_PLAYER_INV.remove(p.getUniqueId());
}

@EventListener
public void onMessage(PlayerChatEvent e) {
Stats.updateMessage(NegativityPlayer.getNegativityPlayer(e.getPlayer()), e.getMessage());
}

@EventListener
public void onInventoryClose(InventoryCloseEvent e) {
Player p = e.getPlayer();
if(e.getInventory().getType().equals(InventoryType.PLAYER)) {
Player cible = GlobalPlayerInventory.PLAYER_SEE_PLAYER_INV.get(p.getUniqueId());
if(cible == null)
return;
InventoryManager.open(NegativityInventory.GLOBAL_PLAYER, p, cible);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.colors.ChatColor;
Expand All @@ -30,6 +32,8 @@

public class GlobalPlayerInventory extends AbstractInventory<CheckMenuHolder> {

public static final HashMap<UUID, Player> PLAYER_SEE_PLAYER_INV = new HashMap<>();

public GlobalPlayerInventory() {
super(NegativityInventory.GLOBAL_PLAYER, CheckMenuHolder.class);
}
Expand Down Expand Up @@ -150,6 +154,7 @@ public void manageInventory(InventoryClickEvent e, Material m, Player p, CheckMe
p.closeInventory();
} else if(m.equals(Materials.SPIDER_EYE)){
p.openInventory(cible.getInventory());
PLAYER_SEE_PLAYER_INV.put(p.getUniqueId(), cible);
} else if(m.equals(Materials.TNT)) {
InventoryManager.open(NegativityInventory.ACTIVED_CHEAT, p, cible);
} else if(m.equals(Materials.PACKED_ICE)) {
Expand Down

0 comments on commit a0dcf36

Please sign in to comment.