Skip to content
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
6 changes: 3 additions & 3 deletions Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>Spigot</artifactId>

<build>
<finalName>WorldGuardExtraFlags</finalName>
<finalName>WorldGuardExtraFlags-v${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -59,7 +59,7 @@
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>CodeMC</id>
Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<version>5.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ 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);
flagRegistry.register(Flags.ALLOW_BLOCK_PLACE);
flagRegistry.register(Flags.DENY_BLOCK_PLACE);
flagRegistry.register(Flags.ALLOW_BLOCK_BREAK);
flagRegistry.register(Flags.DENY_BLOCK_BREAK);
}
catch (Exception e)
{
Expand Down Expand Up @@ -201,9 +207,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 @@ -5,20 +5,28 @@
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.session.SessionManager;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
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 +62,75 @@ 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()));
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockPlaceEvent(PlaceBlockEvent event) {
Event.Result originalResult = event.getResult();
Object cause = event.getCause().getRootCause();
if (cause instanceof Player player) {
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(player);
for (Block block : event.getBlocks()) {
Material type = block.getType();
if (type.isAir()) {
type = event.getEffectiveMaterial();
}

Location location = BukkitAdapter.adapt(block.getLocation());

Set<Material> state = regionContainer.createQuery().queryValue(location, localPlayer, Flags.ALLOW_BLOCK_PLACE);
if (state != null && state.contains(type)) {
event.setResult(Event.Result.ALLOW);
} else {
Set<Material> state2 = regionContainer.createQuery().queryValue(location, localPlayer, Flags.DENY_BLOCK_PLACE);
if (state2 != null && state2.contains(type)) {
event.setResult(Event.Result.DENY);
} else {
event.setResult(originalResult);
}
return;
}
}
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreakEvent(BreakBlockEvent event) {
Event.Result originalResult = event.getResult();
Object cause = event.getCause().getRootCause();

if (cause instanceof Player player) {
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(player);
for (Block block : event.getBlocks()) {
Location location = BukkitAdapter.adapt(block.getLocation());

Set<Material> state = regionContainer.createQuery().queryValue(location, localPlayer, Flags.ALLOW_BLOCK_BREAK);
if (state != null && state.contains(block.getType())) {
event.setResult(Event.Result.ALLOW);
} else {
Set<Material> state2 = regionContainer.createQuery().queryValue(location, localPlayer, Flags.DENY_BLOCK_BREAK);
if (state2 != null && state2.contains(block.getType())) {
event.setResult(Event.Result.DENY);
} else {
event.setResult(originalResult);
}
return;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.session.SessionManager;
import net.goldtreeservers.worldguardextraflags.flags.helpers.ForcedStateFlag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand All @@ -16,12 +14,9 @@
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.world.PortalCreateEvent;

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

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

@RequiredArgsConstructor
Expand Down Expand Up @@ -71,36 +66,26 @@ public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
}

ForcedStateFlag.ForcedState state = this.regionContainer.createQuery().queryValue(localPlayer.getLocation(), localPlayer, Flags.GLIDE);
switch(state)
{
case ALLOW:
break;
case DENY:
{
if (!event.isGliding())
{
return;
}

event.setCancelled(true);
switch (state) {
case DENY -> {
if (!event.isGliding()) {
return;
}

//Prevent the player from being allowed to glide by spamming space
player.teleport(player.getLocation());
event.setCancelled(true);

break;
}
case FORCE:
{
if (event.isGliding())
{
return;
}
//Prevent the player from being allowed to glide by spamming space
player.teleport(player.getLocation());

event.setCancelled(true);
}
case FORCE -> {
if (event.isGliding()) {
return;
}

break;
}
}
event.setCancelled(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.session.SessionManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPotionEffectEvent;

import com.sk89q.worldguard.session.Session;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GiveEffectsFlagHandler;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
Expand All @@ -17,7 +16,6 @@
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.sk89q.worldguard.protection.flags.StateFlag.State;

import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import net.goldtreeservers.worldguardextraflags.flags.Flags;

public class WorldEditFlagHandler extends AbstractDelegateExtent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@
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
{
public final static LocationFlag TELEPORT_ON_ENTRY = new LocationFlag("teleport-on-entry");
public final static LocationFlag TELEPORT_ON_EXIT = new LocationFlag("teleport-on-exit");

public final static SetFlag<String> COMMAND_ON_ENTRY = new CustomSetFlag("command-on-entry", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> COMMAND_ON_EXIT = new CustomSetFlag("command-on-exit", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> COMMAND_ON_ENTRY = new CustomSetFlag<>("command-on-entry", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> COMMAND_ON_EXIT = new CustomSetFlag<>("command-on-exit", new CommandStringCaseSensitiveFlag(null));

public final static SetFlag<String> CONSOLE_COMMAND_ON_ENTRY = new CustomSetFlag("console-command-on-entry", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> CONSOLE_COMMAND_ON_EXIT = new CustomSetFlag("console-command-on-exit", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> CONSOLE_COMMAND_ON_ENTRY = new CustomSetFlag<>("console-command-on-entry", new CommandStringCaseSensitiveFlag(null));
public final static SetFlag<String> CONSOLE_COMMAND_ON_EXIT = new CustomSetFlag<>("console-command-on-exit", new CommandStringCaseSensitiveFlag(null));

public final static DoubleFlag WALK_SPEED = new DoubleFlag("walk-speed");
public final static DoubleFlag FLY_SPEED = new DoubleFlag("fly-speed");
Expand All @@ -36,19 +34,19 @@ public final class Flags
public final static StringFlag CHAT_PREFIX = new StringFlag("chat-prefix");
public final static StringFlag CHAT_SUFFIX = new StringFlag("chat-suffix");

public final static SetFlag<PotionEffectType> BLOCKED_EFFECTS = new SetFlag("blocked-effects", new PotionEffectTypeFlag(null));
public final static SetFlag<PotionEffectType> BLOCKED_EFFECTS = new SetFlag<>("blocked-effects", new PotionEffectTypeFlag(null));

public final static StateFlag GODMODE = new StateFlag("godmode", false);

public final static LocationFlag RESPAWN_LOCATION = new LocationFlag("respawn-location");

public final static StateFlag WORLDEDIT = new StateFlag("worldedit", true);

public final static SetFlag<PotionEffect> GIVE_EFFECTS = new SetFlag("give-effects", new PotionEffectFlag(null));
public final static SetFlag<PotionEffect> GIVE_EFFECTS = new SetFlag<>("give-effects", new PotionEffectFlag(null));

public final static StateFlag FLY = new StateFlag("fly", false);

public final static SetFlag<SoundData> PLAY_SOUNDS = new SetFlag("play-sounds", new SoundDataFlag(null));
public final static SetFlag<SoundData> PLAY_SOUNDS = new SetFlag<>("play-sounds", new SoundDataFlag(null));

public final static StateFlag FROSTWALKER = new StateFlag("frostwalker", true);

Expand All @@ -61,4 +59,12 @@ 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));

public final static SetFlag<Material> ALLOW_BLOCK_PLACE = new SetFlag<>("allow-block-place", new BlockMaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_PLACE = new SetFlag<>("deny-block-place", new BlockMaterialFlag(null));
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<>("allow-block-break", new BlockMaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<>("deny-block-break", new BlockMaterialFlag(null));
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class ForcedStateFlag extends Flag<ForcedState>
{
public static enum ForcedState
public enum ForcedState
{
ALLOW,
DENY,
Expand Down Expand Up @@ -97,18 +97,13 @@ else if (input.equalsIgnoreCase("none"))
public ForcedState unmarshal(Object o)
{
String str = o.toString();

switch(str)
{
case "ALLOW":
return ForcedState.ALLOW;
case "FORCE":
return ForcedState.FORCE;
case "DENY":
return ForcedState.DENY;
default:
return null;
}

return switch (str) {
case "ALLOW" -> ForcedState.ALLOW;
case "FORCE" -> ForcedState.FORCE;
case "DENY" -> ForcedState.DENY;
default -> null;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PotionEffectFlag(String name)
@Override
public Object marshal(PotionEffect o)
{
return o.getType().getKey().toString() + " " + o.getAmplifier() + " " + o.hasParticles();
return o.getType().getKey() + " " + o.getAmplifier() + " " + o.hasParticles();
}

@Override
Expand Down
Loading