Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added blocked-block-drops and allowed-block-drops #279

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public void onLoad()
flagRegistry.register(Flags.CHUNK_UNLOAD);
flagRegistry.register(Flags.ITEM_DURABILITY);
flagRegistry.register(Flags.JOIN_LOCATION);
flagRegistry.register(Flags.ALLOWED_BLOCK_DROPS);
flagRegistry.register(Flags.BLOCKED_BLOCK_DROPS);
}
catch (Exception e)
{
Expand Down Expand Up @@ -201,9 +203,7 @@ private void setupMetrics()
Map<Flag<?>, Boolean> valueMap = WorldGuardExtraFlagsPlugin.FLAGS.stream().collect(Collectors.toMap(v -> v, v -> false));

WorldGuard.getInstance().getPlatform().getRegionContainer().getLoaded().forEach(m ->
{
m.getRegions().values().forEach(r -> r.getFlags().keySet().forEach(f -> valueMap.computeIfPresent(f, (k, v) -> true)));
});
m.getRegions().values().forEach(r -> r.getFlags().keySet().forEach(f -> valueMap.computeIfPresent(f, (k, v) -> true))));

return valueMap.entrySet().stream().collect(Collectors.toMap(v -> v.getKey().getName(), v -> v.getValue() ? 1 : 0));
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.block.EntityBlockFormEvent;

import com.sk89q.worldguard.protection.flags.StateFlag.State;

import lombok.RequiredArgsConstructor;
import net.goldtreeservers.worldguardextraflags.flags.Flags;

import java.util.Set;

@RequiredArgsConstructor
public class BlockListener implements Listener
{
Expand Down Expand Up @@ -54,4 +57,19 @@ public void onEntityBlockFormEvent(EntityBlockFormEvent event)
}
}
}

@EventHandler(ignoreCancelled = true)
public void onBlockDropItem(BlockDropItemEvent event) {
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(event.getPlayer());
Location location = BukkitAdapter.adapt(event.getBlock().getLocation());
if (this.sessionManager.hasBypass(localPlayer, (World) location.getExtent())) {
return;
}

Set<Material> allowedDrops = regionContainer.createQuery().queryValue(location, localPlayer, Flags.ALLOWED_BLOCK_DROPS);
if (!event.getItems().removeIf(item -> allowedDrops != null && !allowedDrops.contains(item.getItemStack().getType()))) {
Set<Material> blockedDrops = regionContainer.createQuery().queryValue(location, localPlayer, Flags.BLOCKED_BLOCK_DROPS);
event.getItems().removeIf(item -> blockedDrops != null && blockedDrops.contains(item.getItemStack().getType()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import org.bukkit.potion.PotionEffectType;

import com.sk89q.worldguard.protection.flags.BooleanFlag;
import com.sk89q.worldguard.protection.flags.CommandStringFlag;
import com.sk89q.worldguard.protection.flags.DoubleFlag;
import com.sk89q.worldguard.protection.flags.LocationFlag;
import com.sk89q.worldguard.protection.flags.SetFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StringFlag;

import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;

public final class Flags
{
Expand Down Expand Up @@ -61,4 +59,7 @@ public final class Flags
public final static StateFlag ITEM_DURABILITY = new StateFlag("item-durability", true);

public final static LocationFlag JOIN_LOCATION = new LocationFlag("join-location");

public final static SetFlag<Material> ALLOWED_BLOCK_DROPS = new SetFlag<>("allowed-block-drops", new MaterialFlag(null));
public final static SetFlag<Material> BLOCKED_BLOCK_DROPS = new SetFlag<>("blocked-block-drops", new MaterialFlag(null));
}