Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ build/
buildSrc/build/
buildSrc/.gradle/
run/
/*.jar
/*.jar
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/CoreConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.ivy
import org.gradle.kotlin.dsl.the

fun Project.applyCoreConfiguration() {
Expand All @@ -13,4 +15,15 @@ fun Project.applyCoreConfiguration() {
if (name in setOf("buildsystem-core")) {
the<JavaPluginExtension>().withSourcesJar()
}
}

fun RepositoryHandler.modrinthMavenWorkaround(nameOrId: String, version: String, fileName: String) {
val url = "https://api.modrinth.com/maven/maven/modrinth/$nameOrId/$version/$fileName"
val group = "maven.modrinth.workaround"
ivy(url.substringBeforeLast('/')) {
name = "Modrinth Maven Workaround for $nameOrId"
patternLayout { artifact(url.substringAfterLast('/')) }
metadataSources { artifact() }
content { includeModule(group, nameOrId) }
}
}
12 changes: 12 additions & 0 deletions buildsystem-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ repositories {
name = "PlaceholderAPI"
url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}

maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}

modrinthMavenWorkaround(
"axiom-paper-plugin",
"4.0.1-1.21.1",
"AxiomPaper-4.0.1-for-MC1.21.1.jar"
)
}

dependencies {
Expand All @@ -34,6 +45,7 @@ dependencies {
compileOnly(libs.placeholderapi)
compileOnly(libs.worldedit)
compileOnly(libs.annotations)
compileOnly(libs.axiompaper)

implementation(libs.paperlib)
implementation(libs.xseries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import de.eintosti.buildsystem.listener.SettingsInteractListener;
import de.eintosti.buildsystem.listener.SignChangeListener;
import de.eintosti.buildsystem.listener.WeatherChangeListener;
import de.eintosti.buildsystem.listener.WorldManipulateByAxiomListener;
import de.eintosti.buildsystem.listener.WorldManipulateListener;
import de.eintosti.buildsystem.navigator.ArmorStandManager;
import de.eintosti.buildsystem.navigator.inventory.ArchiveInventory;
Expand Down Expand Up @@ -377,6 +378,11 @@ private void registerExpansions() {
this.luckPermsExpansion.registerAll();
}

if (pluginManager.getPlugin("AxiomPaper") != null) {
new WorldManipulateByAxiomListener(this);
getLogger().info("Axiom build-world manipulation prevention has been enabled.");
}

boolean isWorldEdit = pluginManager.getPlugin("WorldEdit") != null
|| pluginManager.getPlugin("FastAsyncWorldEdit") != null;
if (isWorldEdit && configValues.isBlockWorldEditNonBuilder()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.eintosti.buildsystem.event;

import de.eintosti.buildsystem.event.world.BuildWorldManipulationEvent;
import de.eintosti.buildsystem.world.BuildWorld;
import de.eintosti.buildsystem.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;

/**
* Manages the dispatching of custom events related to build world manipulations.
* @since TODO
*/
public class EventDispatcher {

private final WorldManager worldManager;
/**
* @param worldManager the world manager used to retrieve build world information
*/
public EventDispatcher(WorldManager worldManager) {
this.worldManager = worldManager;
}

/**
* <p>Dispatches a build world manipulation event if the player is in a build world
* and the parent event has not been cancelled.</p>
*
* <p>This method checks if:</p>
* <ol>
* <li>The parent event is not already cancelled</li>
* <li>The player is in a valid build world</li>
* </ol>
*
* If both conditions are met, it triggers a {@link BuildWorldManipulationEvent}
* to allow further processing of the player's action.
*
* @param player the player who performed the manipulation
* @param parentEvent the original event that triggered this potential manipulation
*/
public void dispatchManipulationEventIfPlayerInBuildWorld(Player player, Cancellable parentEvent) {
if (parentEvent.isCancelled()) {
return;
}
BuildWorld world = worldManager.getBuildWorld(player.getWorld().getName());
if (world == null) {
return;
}
Bukkit.getPluginManager().callEvent(new BuildWorldManipulationEvent(parentEvent, player, world));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.eintosti.buildsystem.event.world;

import de.eintosti.buildsystem.world.BuildWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

/**
* This event reduces duplicated code.
* <p>It will be called when</p>
* <ul>
* <li>Breaking Blocks</li>
* <li>Placing Blocks</li>
* <li>Other modification related stuff</li>
* </ul>
* Cancelling this event will affect the parent-Event, which has caused the ManipulationEvent to fire.
* <p>Expect the manipulation event to be cancelled at {@link org.bukkit.event.EventPriority#LOW} if the player is not allowed to interact with the world.</p>
*
* @see de.eintosti.buildsystem.listener.WorldManipulateListener
* @since TODO
*/
public class BuildWorldManipulationEvent extends BuildWorldEvent implements Cancellable {

private final Cancellable parentEvent;
private final Player player;

public BuildWorldManipulationEvent(Cancellable parentEvent, Player player, BuildWorld buildWorld) {
super(buildWorld);
this.parentEvent = parentEvent;
this.player = player;
}

/**
* @return whether the parent event has been cancelled
*/
@Override
public boolean isCancelled() {
return parentEvent.isCancelled();
}

/**
* @param cancelled true if the parent event should be cancelled.
*/
@Override
public void setCancelled(boolean cancelled) {
parentEvent.setCancelled(cancelled);
}

/**
* @return the event which has caused the manipulation event to fire.
*/
public Cancellable getParentEvent() {
return parentEvent;
}

public Player getPlayer() {
return player;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.eintosti.buildsystem.listener;

import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import de.eintosti.buildsystem.BuildSystem;
import de.eintosti.buildsystem.event.EventDispatcher;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

/**
* Only register if axiom is available
*/
public class WorldManipulateByAxiomListener implements Listener {

private final EventDispatcher dispatcher;


/**
* @param plugin plugin to register.
*/
public WorldManipulateByAxiomListener(@NotNull BuildSystem plugin) {
this.dispatcher = new EventDispatcher(plugin.getWorldManager());
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}


@EventHandler()
public void onWorldModification(AxiomModifyWorldEvent event) {
// I don't know if it is possible. Just to be safe.
if (!event.getPlayer().getWorld().equals(event.getWorld())) {
event.setCancelled(true);
throw new IllegalStateException("Player modifies a world in which he is not present! The event got cancelled for safety reasons.");
}
dispatcher.dispatchManipulationEventIfPlayerInBuildWorld(event.getPlayer(), event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.cryptomorin.xseries.XMaterial;
import de.eintosti.buildsystem.BuildSystem;
import de.eintosti.buildsystem.event.EventDispatcher;
import de.eintosti.buildsystem.event.world.BuildWorldManipulationEvent;
import de.eintosti.buildsystem.world.BuildWorld;
import de.eintosti.buildsystem.world.Builder;
import de.eintosti.buildsystem.world.WorldManager;
Expand All @@ -43,49 +45,24 @@ public class WorldManipulateListener implements Listener {

private final BuildSystem plugin;
private final WorldManager worldManager;
private final EventDispatcher dispatcher;

public WorldManipulateListener(BuildSystem plugin) {
this.plugin = plugin;
this.worldManager = plugin.getWorldManager();
this.dispatcher = new EventDispatcher(worldManager);

plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}

Player player = event.getPlayer();
BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (buildWorld == null) {
return;
}

WorldData worldData = buildWorld.getData();
if (!manageWorldInteraction(player, event, worldData.blockBreaking().get())) {
worldData.lastEdited().set(System.currentTimeMillis());
updateStatus(worldData, player);
}
dispatcher.dispatchManipulationEventIfPlayerInBuildWorld(event.getPlayer(), event);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) {
return;
}

Player player = event.getPlayer();
BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (buildWorld == null) {
return;
}

WorldData worldData = buildWorld.getData();
if (!manageWorldInteraction(player, event, worldData.blockPlacement().get())) {
worldData.lastEdited().set(System.currentTimeMillis());
updateStatus(worldData, player);
}
dispatcher.dispatchManipulationEventIfPlayerInBuildWorld(event.getPlayer(), event);
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand All @@ -94,7 +71,6 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}
Player player = (Player) event.getDamager();

BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (buildWorld == null) {
return;
Expand Down Expand Up @@ -140,6 +116,33 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}


@EventHandler(priority = EventPriority.LOW)
public void onWorldManipulation(BuildWorldManipulationEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
BuildWorld buildWorld = event.getBuildWorld();
WorldData worldData = buildWorld.getData();

if (!manageWorldInteraction(player, event, getRelatedWorldSetting(event.getParentEvent(), worldData))) {
worldData.lastEdited().set(System.currentTimeMillis());
updateStatus(worldData, player);
}
}

private boolean getRelatedWorldSetting(Cancellable event, WorldData data) {
if (event instanceof BlockBreakEvent) {
return data.blockBreaking().get();
}
if (event instanceof BlockPlaceEvent) {
return data.blockPlacement().get();
}
return data.blockInteractions().get();
}


/**
* Not every player can always interact with the {@link BuildWorld} they are in.
* <p>
Expand Down
2 changes: 1 addition & 1 deletion buildsystem-core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: einTosti
main: de.eintosti.buildsystem.BuildSystem
description: Powerful, easy to use system for builders
website: https://buildsystem.eintosti.de
softdepend: [ LuckPerms, PlaceholderAPI, WorldEdit ]
softdepend: [ LuckPerms, PlaceholderAPI, WorldEdit, AxiomPaper ]

commands:
back:
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paperlib = "1.0.8"
luckperms = "5.4"
worldedit = "7.2.20"
placeholderapi = "2.11.6"

axiompaper = "4.0.1-1.21.1"
# Third Party
annotations = "26.0.1"
authlib = "1.5.25"
Expand All @@ -25,6 +25,7 @@ paperlib = { group = "io.papermc", name = "paperlib", version.ref = "paperlib" }
luckperms = { group = "net.luckperms", name = "api", version.ref = "luckperms" }
placeholderapi = { group = "me.clip", name = "placeholderapi", version.ref = "placeholderapi" }
worldedit = { group = "com.sk89q.worldedit", name = "worldedit-core", version.ref = "worldedit" }
axiompaper= {group = "maven.modrinth.workaround", name = "axiom-paper-plugin", version.ref="axiompaper"}

# Third Party
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand Down
Loading