resolve issues with 2e67425d8131a2b1eb7ff752335bccf371801b8b

This commit is contained in:
Jesse Boyd
2019-07-18 20:12:23 +10:00
parent 1bc35eb59a
commit 6e13b44f84
35 changed files with 430 additions and 315 deletions

View File

@ -318,13 +318,14 @@ public class BukkitWorld extends AbstractWorld {
@Override
public boolean equals(Object other) {
if (worldRef.get() == null) {
World ref = worldRef.get();
if (ref == null) {
return false;
} else if (other == null) {
return false;
} else if ((other instanceof BukkitWorld)) {
World otherWorld = ((BukkitWorld) other).worldRef.get();
return otherWorld != null && otherWorld.equals(getWorld());
return ref.equals(otherWorld);
} else if (other instanceof com.sk89q.worldedit.world.World) {
return ((com.sk89q.worldedit.world.World) other).getName().equals(getName());
} else {

View File

@ -21,6 +21,7 @@
package com.sk89q.worldedit.bukkit;
import com.bekvon.bukkit.residence.commands.command;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
@ -36,12 +37,15 @@ import org.bukkit.event.player.PlayerCommandSendEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.inject.MapBackedValueStore;
import java.util.Iterator;
import java.util.Optional;
import java.util.function.Predicate;
/**
* Handles all events thrown in relation to a Player
@ -71,16 +75,22 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context ->
Optional.of(plugin.wrapCommandSender(event.getPlayer())));
InjectedValueStore store = null;
CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
event.getCommands().removeIf(name ->
// remove if in the manager and not satisfied
commandManager.getCommand(name)
.filter(command -> !command.getCondition().satisfied(store))
.isPresent()
);
Iterator<String> iter = event.getCommands().iterator();
while (iter.hasNext()) {
String name = iter.next();
Optional<Command> optional = commandManager.getCommand(name);
if (optional.isPresent()) {
if (store == null) {
store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(plugin.wrapCommandSender(event.getPlayer())));
}
if (!optional.get().getCondition().satisfied(store)) {
iter.remove();
}
}
}
}
/**