[Idea]: Folia support for OpenInv #196

Closed
reabuc wants to merge 137 commits from master into master
52 changed files with 2364 additions and 373 deletions
Showing only changes of commit 4336b454b7 - Show all commits

View File

@@ -336,10 +336,6 @@ public class AnySilentContainer implements IAnySilentContainer {
try { try {
this.playerInteractManagerGamemode.setAccessible(true); this.playerInteractManagerGamemode.setAccessible(true);
this.playerInteractManagerGamemode.set(player.d, gameMode); this.playerInteractManagerGamemode.set(player.d, gameMode);
// TODO: may need additional calls to update abilities to prevent container sound + animation
// gameMode.a(player.getAbilities());
// player.updateAbilities();
// should be the fix if it doesn't work as-is
} catch (IllegalArgumentException | IllegalAccessException e) { } catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -35,10 +35,12 @@ import com.lishid.openinv.util.ConfigUpdater;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import com.lishid.openinv.util.LanguageManager; import com.lishid.openinv.util.LanguageManager;
import com.lishid.openinv.util.Permissions; import com.lishid.openinv.util.Permissions;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -88,7 +90,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
// Check if inventory is stored, and if it is, remove it and eject all viewers // Check if inventory is stored, and if it is, remove it and eject all viewers
if (OpenInv.this.inventories.containsKey(key)) { if (OpenInv.this.inventories.containsKey(key)) {
Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory(); Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory();
List<HumanEntity> viewers = inv.getViewers(); List<HumanEntity> viewers = new ArrayList<>(inv.getViewers());
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) { for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
entity.closeInventory(); entity.closeInventory();
} }
@@ -97,7 +99,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
// Check if ender chest is stored, and if it is, remove it and eject all viewers // Check if ender chest is stored, and if it is, remove it and eject all viewers
if (OpenInv.this.enderChests.containsKey(key)) { if (OpenInv.this.enderChests.containsKey(key)) {
Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory(); Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory();
List<HumanEntity> viewers = inv.getViewers(); List<HumanEntity> viewers = new ArrayList<>(inv.getViewers());
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) { for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
entity.closeInventory(); entity.closeInventory();
} }
@@ -126,29 +128,23 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
} }
if (this.inventories.containsKey(key)) { if (this.inventories.containsKey(key)) {
Iterator<HumanEntity> iterator = this.inventories.get(key).getBukkitInventory().getViewers().iterator(); kickCrossWorldViewers(player, this.inventories.get(key));
//noinspection WhileLoopReplaceableByForEach
while (iterator.hasNext()) {
HumanEntity human = iterator.next();
// If player has permission or is in the same world, allow continued access
// Just in case, also allow null worlds.
if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld().equals(player.getWorld())) {
continue;
}
human.closeInventory();
}
} }
if (this.enderChests.containsKey(key)) { if (this.enderChests.containsKey(key)) {
Iterator<HumanEntity> iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator(); kickCrossWorldViewers(player, this.enderChests.get(key));
//noinspection WhileLoopReplaceableByForEach }
while (iterator.hasNext()) { }
HumanEntity human = iterator.next();
if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld().equals(player.getWorld())) { private void kickCrossWorldViewers(Player player, ISpecialInventory inventory) {
continue; List<HumanEntity> viewers = new ArrayList<>(inventory.getBukkitInventory().getViewers());
} for (HumanEntity human : viewers) {
human.closeInventory(); // If player has permission or is in the same world, allow continued access
// Just in case, also allow null worlds.
if (Permissions.CROSSWORLD.hasPermission(human) || Objects.equals(human.getWorld(), player.getWorld())) {
continue;
} }
human.closeInventory();
} }
} }
@@ -326,7 +322,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
return this.languageManager.getValue(key, getLocale(sender), replacements); return this.languageManager.getValue(key, getLocale(sender), replacements);
} }
private @Nullable String getLocale(@NotNull CommandSender sender) { private @NotNull String getLocale(@NotNull CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
return ((Player) sender).getLocale(); return ((Player) sender).getLocale();
} else { } else {