[Idea]: Folia support for OpenInv #196
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal;
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Barrel;
|
import org.bukkit.block.Barrel;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@@ -148,13 +147,20 @@ public interface IAnySilentContainer {
|
|||||||
* @return true if the type is a supported container
|
* @return true if the type is a supported container
|
||||||
*/
|
*/
|
||||||
default boolean isAnySilentContainer(@NotNull Block block) {
|
default boolean isAnySilentContainer(@NotNull Block block) {
|
||||||
if (block.getType() == Material.ENDER_CHEST) {
|
return isAnySilentContainer(block.getState());
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
BlockState state = block.getState();
|
/**
|
||||||
return state instanceof org.bukkit.block.Chest
|
* Check if the given {@link BlockState} is a container which can be unblocked or silenced.
|
||||||
|| state instanceof org.bukkit.block.ShulkerBox
|
*
|
||||||
|| state instanceof org.bukkit.block.Barrel;
|
* @param blockState the potential container
|
||||||
|
* @return true if the type is a supported container
|
||||||
|
*/
|
||||||
|
default boolean isAnySilentContainer(@NotNull BlockState blockState) {
|
||||||
|
return blockState instanceof org.bukkit.block.EnderChest
|
||||||
|
|| blockState instanceof org.bukkit.block.Chest
|
||||||
|
|| blockState instanceof org.bukkit.block.ShulkerBox
|
||||||
|
|| blockState instanceof org.bukkit.block.Barrel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.InventoryView;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -231,21 +231,10 @@ public class AnySilentContainer implements IAnySilentContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
||||||
if (this.serverPlayerGameModeGameType == null) {
|
if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryView view = bukkitPlayer.getOpenInventory();
|
|
||||||
switch (view.getType()) {
|
|
||||||
case CHEST:
|
|
||||||
case ENDER_CHEST:
|
|
||||||
case SHULKER_BOX:
|
|
||||||
case BARREL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
||||||
|
|
||||||
// Force game mode change without informing plugins or players.
|
// Force game mode change without informing plugins or players.
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.InventoryView;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -231,21 +231,10 @@ public class AnySilentContainer implements IAnySilentContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
||||||
if (this.serverPlayerGameModeGameType == null) {
|
if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryView view = bukkitPlayer.getOpenInventory();
|
|
||||||
switch (view.getType()) {
|
|
||||||
case CHEST:
|
|
||||||
case ENDER_CHEST:
|
|
||||||
case SHULKER_BOX:
|
|
||||||
case BARREL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
||||||
|
|
||||||
// Force game mode change without informing plugins or players.
|
// Force game mode change without informing plugins or players.
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.InventoryView;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -227,21 +227,10 @@ public class AnySilentContainer implements IAnySilentContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
|
||||||
if (this.serverPlayerGameModeGameType == null) {
|
if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryView view = bukkitPlayer.getOpenInventory();
|
|
||||||
switch (view.getType()) {
|
|
||||||
case CHEST:
|
|
||||||
case ENDER_CHEST:
|
|
||||||
case SHULKER_BOX:
|
|
||||||
case BARREL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
|
||||||
|
|
||||||
// Force game mode change without informing plugins or players.
|
// Force game mode change without informing plugins or players.
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2022 lishid. All rights reserved.
|
* Copyright (C) 2011-2023 lishid. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -53,7 +54,9 @@ record InventoryListener(OpenInv plugin) implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugin.getSilentContainerStatus(player)) {
|
if (this.plugin.getSilentContainerStatus(player)
|
||||||
|
&& event.getInventory().getHolder() instanceof Container container
|
||||||
|
&& this.plugin.getAnySilentContainer().isAnySilentContainer(container)) {
|
||||||
this.plugin.getAnySilentContainer().deactivateContainer(player);
|
this.plugin.getAnySilentContainer().deactivateContainer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user