Skip to content

Commit

Permalink
improvement: add config for projectiles/items movement blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-EmPee committed May 30, 2024
1 parent 7fc42e2 commit 5d9e961
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class PluginConfig extends ResourceConfig {

public PluginConfig(MysticalBarriers plugin) {
super(plugin, "configs/config.yml", plugin.isDevelop(), 1);
super(plugin, "configs/config.yml", plugin.isDevelop(), 2);

Messenger.setPrefix(getPrefix());
}
Expand All @@ -22,6 +22,22 @@ public boolean blockChorusTp() {
return getConfig().getBoolean("block-chorus-teleportation");
}

public boolean blockProjectiles() {
return getConfig().getBoolean("block-movement.projectiles.enabled");
}

public boolean blockProjectilesOnlyFromPlayers() {
return getConfig().getBoolean("block-movement.projectiles.only-from-player");
}

public boolean blockItems() {
return getConfig().getBoolean("block-movement.items.enabled");
}

public boolean blockItemsOnlyFromPlayers() {
return getConfig().getBoolean("block-movement.items.only-from-player");
}

public String getPrefix() {
return getConfig().getString("messages.prefix");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package core.handlers;

import core.configs.client.resources.PluginConfig;
import io.github.empee.lightwire.annotations.LightWired;
import lombok.RequiredArgsConstructor;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -27,14 +29,25 @@ public class BarrierEntitiesActionHandler extends BukkitRunnable implements List
private final List<Entity> trackedEntities = new ArrayList<>();

private final BarriersService barriersService;
private final PluginConfig pluginConfig;

@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (!pluginConfig.blockProjectiles()) return;
if (pluginConfig.blockProjectilesOnlyFromPlayers()) {
if (!(event.getEntity().getShooter() instanceof Player)) return;
}

trackedEntities.add(event.getEntity());
}

@EventHandler
public void onItemDrop(ItemSpawnEvent event) {
if (!pluginConfig.blockItems()) return;
if (pluginConfig.blockItemsOnlyFromPlayers()) {
if (event.getEntity().getOwner() == null) return;
}

trackedEntities.add(event.getEntity());
}

Expand Down
5 changes: 5 additions & 0 deletions plugin/core/src/main/resources/configs/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

lang: "en"

messages:
Expand All @@ -11,3 +13,6 @@ block-movement:
projectiles:
enabled: true
only-from-player: false # Enabled only for projectiles shot by a player
items:
enabled: true
only-from-player: false # Enabled only for projectiles shot by a player

0 comments on commit 5d9e961

Please sign in to comment.