Skip to content

Commit

Permalink
Feat: Log block removal on defence break + integration control
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullians committed Dec 26, 2024
1 parent 99f28b7 commit 2e98295
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public enum Settings {
DEFAULT_LANGUAGE("language.default-language"),
BLACKLISTED_PHRASES("language.blacklisted-phrases"),

ITEM_JOIN_INTEGRATION("integration.itemjoin"),
COREPROTECT_INTEGRATION("integration.coreprotect"),
VAULT_INTEGRATION("integration.vault"),
PLACEHOLDERAPI_INTEGRATION("integration.placeholderapi"),
JUKEBOX_INTEGRATION("integration.jukebox"),

HUB_WORLD_NAME("hub.world-name"),
HUB_LOCATION("hub.hub-location"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.skullian.skyfactions.common.defence.hologram.DefenceTextHologram;
import net.skullian.skyfactions.common.defence.struct.DefenceData;
import net.skullian.skyfactions.common.defence.struct.DefenceStruct;
import net.skullian.skyfactions.common.user.SkyUser;
import net.skullian.skyfactions.common.util.SkyLocation;

import java.util.ArrayList;
Expand Down Expand Up @@ -34,12 +35,13 @@ public Defence(DefenceData defenceData, DefenceStruct defenceStruct) {
this.struct = defenceStruct;
}

public abstract CompletableFuture<Void> remove();
public abstract CompletableFuture<Void> remove(SkyUser skyUser);

public void onShoot() {
this.data.setAMMO(this.data.getAMMO() - 1);
updatePDC();
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public void damage(Optional<Integer> amount) {
this.data.setDURABILITY(Math.max(this.data.getDURABILITY() - amount.orElseGet(this::getExplosionDamage), 0));
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ language:
integration:
itemjoin: true # On island deletion a player's inventory and enderchest are wiped. We can hook into ItemJoin and NOT wipe items from ItemJoin.
coreprotect: true # On obelisk relocation and defence removal, we can hook into CoreProtect to log interactions.
vault: true # Used in the NPC integration
placeholderapi: true
vault: true # Used in the NPC integration (for actions).
placeholderapi: true # Hook into PlaceholderAPI and parse placeholders.
jukebox: true # Hook into the Jukebox plugin, to stop playing music when a raid begins.

# SkyFactions Hub Config
hub:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import net.skullian.skyfactions.common.defence.struct.DefenceEntityStruct;
import net.skullian.skyfactions.common.defence.struct.DefenceStruct;
import net.skullian.skyfactions.common.faction.Faction;
import net.skullian.skyfactions.common.user.SkyUser;
import net.skullian.skyfactions.common.util.SLogger;
import net.skullian.skyfactions.common.util.SkyLocation;
import net.skullian.skyfactions.paper.PaperSharedConstants;
import net.skullian.skyfactions.paper.SkyFactionsReborn;
import net.skullian.skyfactions.paper.api.adapter.SpigotAdapter;
import net.skullian.skyfactions.paper.defence.hologram.SpigotDefenceTextHologram;
import net.skullian.skyfactions.paper.hooks.CoreProtectHook;
import net.skullian.skyfactions.paper.util.DependencyHandler;
import org.bukkit.*;
import org.bukkit.block.Block;
Expand All @@ -43,11 +45,14 @@ public SpigotDefence(DefenceData defenceData, DefenceStruct defenceStruct) {
}

@Override
public CompletableFuture<Void> remove() {
public CompletableFuture<Void> remove(SkyUser skyUser) {
return CompletableFuture.runAsync(() -> {
Block block = SpigotAdapter.adapt(getDefenceLocation()).getBlock();
PersistentDataContainer container = new CustomBlockData(block, SkyFactionsReborn.getInstance());

Player player = SpigotAdapter.adapt(skyUser).getPlayer();
if (player != null) CoreProtectHook.onDefenceBreak(player, block);

container.remove(PaperSharedConstants.DEFENCE_DATA_KEY);
block.setType(Material.AIR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import net.coreprotect.CoreProtectAPI;
import net.skullian.skyfactions.common.util.SLogger;
import org.bukkit.Bukkit;
import org.bukkit.Location;

Check warning on line 7 in paper/src/main/java/net/skullian/skyfactions/paper/hooks/CoreProtectHook.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import org.bukkit.Location;`
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

public class CoreProtectHook {

Expand All @@ -28,7 +32,10 @@ public static boolean isEnabled() {
return coreProtectAPI != null && coreProtectAPI.isEnabled();
}

public static void onDefenceBreak() {
public static void onDefenceBreak(@NotNull Player player, @NotNull Block block) {
if (!isEnabled()) return;

// Tells CoreProtect that the block was removed.
coreProtectAPI.logRemoval(player.getName(), block.getState());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.skullian.skyfactions.paper.util;

import net.skullian.skyfactions.common.config.types.Settings;
import net.skullian.skyfactions.common.util.SLogger;
import net.skullian.skyfactions.paper.SkyFactionsReborn;
import net.skullian.skyfactions.paper.hooks.ItemJoinHook;
Expand All @@ -14,13 +15,13 @@ public class DependencyHandler {
public static ArrayList<String> enabledDeps = new ArrayList<>();

public static void init() {
if (isPluginEnabled("PlaceholderAPI")) {
if (isPluginEnabled("PlaceholderAPI") && Settings.PLACEHOLDERAPI_INTEGRATION.getBoolean()) {
SLogger.setup("Found {} installed on the server - Registering expansion.", false, "<#05eb2f>PlaceholderAPI<#4294ed>");
new PlaceholderAPIHook(SkyFactionsReborn.getInstance()).register();
enabledDeps.add("PlaceholderAPI");
} else alert("PlaceholderAPI");

if (isPluginEnabled("JukeBox")) {
if (isPluginEnabled("JukeBox") && Settings.JUKEBOX_INTEGRATION.getBoolean()) {
SLogger.setup("Found {} installed on the server.", false, "<#05eb2f>JukeBox<#4294ed>");
enabledDeps.add("JukeBox");
} else alert("JukeBox");
Expand All @@ -45,13 +46,13 @@ public static void init() {
enabledDeps.add("FancyNPCs");
} else alert("FancyNPCs");

if (isPluginEnabled("Vault")) {
if (isPluginEnabled("Vault") && Settings.VAULT_INTEGRATION.getBoolean()) {
SLogger.setup("Found {} installed on the server.", false, "<#05eb2f>Vault<#4294ed>");
VaultAPIHook.init();
enabledDeps.add("Vault");
} else alert("Vault");

if (isPluginEnabled("ItemJoin")) {
if (isPluginEnabled("ItemJoin") && Settings.ITEM_JOIN_INTEGRATION.getBoolean()) {
SLogger.setup("Found {} installed on the server.", false, "<#05eb2f>ItemJoin<#4294ed>");
enabledDeps.add("ItemJoin");
ItemJoinHook.init();
Expand All @@ -67,7 +68,7 @@ public static void init() {
enabledDeps.add("Oraxen");
}

if (isPluginEnabled("CoreProtect")) {
if (isPluginEnabled("CoreProtect") && Settings.COREPROTECT_INTEGRATION.getBoolean()) {
SLogger.setup("Found {} installed on the server.", false, "<#05eb2f>CoreProtect<#4294ed>");
CoreProtectHook.init();
enabledDeps.add("CoreProtect");
Expand Down

0 comments on commit 2e98295

Please sign in to comment.