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
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ version = "2.4.4"

repositories {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://maven.enginehub.org/repo/")

maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
compileOnly(libs.placeholderapi)
compileOnly(libs.worldguard)

paperweight.paperDevBundle("${libs.versions.minecraft.get()}+")
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
minecraft = "26.1.2"
placeholderapi = "2.11.6"
worldguard = "7.0.16"
run-paper = "3.0.2"
paperweight = "2.0.0-beta.21"

Expand All @@ -10,3 +11,4 @@ run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-paper" }

[libraries]
placeholderapi = { module = "me.clip:placeholderapi", version.ref = "placeholderapi" }
worldguard = { module = "com.sk89q.worldguard:worldguard-bukkit", version.ref = "worldguard" }
37 changes: 34 additions & 3 deletions src/main/java/com/catadmirer/infuseSMP/Infuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.catadmirer.infuseSMP.extraeffects.*;
import com.catadmirer.infuseSMP.managers.*;
import com.catadmirer.infuseSMP.placeholders.InfusePlaceholders;
import com.catadmirer.infuseSMP.worldguard.WorldGuardAPI;
import com.catadmirer.infuseSMP.worldguard.handlers.OceanEnabledHandler;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand All @@ -18,6 +20,10 @@
import java.net.http.HttpResponse.BodyHandlers;
import java.util.List;
import java.util.stream.Stream;

import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.session.SessionManager;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -46,6 +52,7 @@ public class Infuse extends JavaPlugin implements Listener {
private final GlobalLoop loop;
private final RecipeManager recipeManager;
private final ParticleManager particleManager;
private String latestVersion;

public static Infuse getInstance() {
return instance;
Expand All @@ -58,6 +65,13 @@ public Infuse() {
this.loop = new GlobalLoop(this);
this.recipeManager = new RecipeManager(this);
this.particleManager = new ParticleManager(this);

Bukkit.getScheduler().runTaskAsynchronously(this, () -> this.latestVersion = getLatestVersion());
}

@Override
public void onLoad() {
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) new WorldGuardAPI().init();
}

public void onEnable() {
Expand Down Expand Up @@ -109,6 +123,23 @@ public void onEnable() {
LOGGER.warn("PlaceholderAPI is not installed, so custom placeholders won't work.");
}

// Registering the WorldGuard custom handler for 1/3 of the custom flags
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && WorldGuardAPI.isLoaded()) {
final SessionManager session = WorldGuard.getInstance().getPlatform().getSessionManager();

try {
session.registerHandler(OceanEnabledHandler.getFactory(), null);
} catch (Exception ex) {
LOGGER.warn("There has been a issue with registering a WorldGuard handler. Custom Flag 'Ocean_Enable' may not work.");
}

LOGGER.info("WorldGuard hook Enabled!");
WorldGuardAPI.setEnabled(true);
} else {
WorldGuardAPI.setEnabled(false);
LOGGER.warn("WorldGuard hook has failed to enable, Please look for warnings/errors that could of causes this.");
}

// Logging the success message
LOGGER.info("Infuse Plugin has been enabled!");
}
Expand Down Expand Up @@ -242,9 +273,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {

if (dropHead) {
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
playerHead.editMeta(SkullMeta.class, meta -> {
meta.setOwningPlayer(player);
});
playerHead.editMeta(SkullMeta.class, meta -> meta.setOwningPlayer(player));
player.getWorld().dropItem(player.getLocation(), playerHead);
}
}
Expand Down Expand Up @@ -312,6 +341,8 @@ private void onJoin(PlayerJoinEvent event) {
msg.applyPlaceholder("control_mode", controlMode);
player.sendMessage(msg.toComponent());

if (this.latestVersion == null || this.latestVersion.equals(getPluginMeta().getVersion())) return;

// Checking for updates but only notifying the player if they are op.
// TODO: Only run this on startup and save the result for when players join.
// try {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/catadmirer/infuseSMP/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static enum MessageType {
DISCORD_BROADCAST(List.of("player", "item", "x", "y", "z", "dimension"), "%player% is cooking up the %item% at %x%, %y%, %z% in %dimension% @everyone"),
EFFECT_FINISHED(List.of("item"), "%item% has been brewed!"),

REGION_SPARK_USE_DISABLED(List.of(), "The current region that you are currently inside of has sparks disabled."),

REGULAR_BROADCAST(List.of("item", "x", "y", "z", "dimension"), "🧪 A %item%<reset> has been crafted at <#90D5FF><b>%x%, %y%, %z%... %dimension%"),

SLOT_EMPTY(List.of("slot"), "<red>You don't have any effect equipped in slot %slot%."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.catadmirer.infuseSMP.managers.DataManager;

import java.util.UUID;

import com.catadmirer.infuseSMP.worldguard.WorldGuardAPI;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -33,6 +35,12 @@ public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
InfuseEffect lEffect = dataManager.getEffect(player.getUniqueId(), "1");
InfuseEffect rEffect = dataManager.getEffect(player.getUniqueId(), "2");

// If WorldGuardAPI is enabled, this will check if they can use it in the current region they are in.
if (!(WorldGuardAPI.isFlagEnabled(player, WorldGuardAPI.getUseSparksFlag()))) {
player.sendMessage(new Message(Message.MessageType.REGION_SPARK_USE_DISABLED).toComponent());
return;
}

// Activating the left effect's spark if the player was sneaking and the effect wasn't on cooldown.
if (lEffect != null && !player.isSneaking() && !CooldownManager.isOnCooldown(playerUUID, lEffect.getKey())) {
event.setCancelled(true);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/catadmirer/infuseSMP/effects/Feather.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.catadmirer.infuseSMP.events.TenHitEvent;
import com.catadmirer.infuseSMP.managers.CooldownManager;
import com.catadmirer.infuseSMP.managers.ParticleManager;
import com.catadmirer.infuseSMP.worldguard.WorldGuardAPI;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
Expand Down Expand Up @@ -111,12 +112,12 @@ public void FeatherLand(PlayerMoveEvent event) {
Location loc = player.getLocation();
World world = player.getWorld();

for (Entity entity : player.getNearbyEntities(radius, radius, radius)) {

// TODO: figure out some stuff for stuff like this.
for (Entity entity : WorldGuardAPI.getAllEntitiesWhereFlagIsAllowed(player, radius, WorldGuardAPI.getUseSparksFlag())) {
if (!(entity instanceof LivingEntity target)) continue;
if (target instanceof Player targetPlayer && plugin.getDataManager().isTrusted(player, targetPlayer)) continue;

int damage = 8;
final int damage = 8;
target.damage(damage);
Vector knockback = new Vector(0, 1, 0);
target.setVelocity(target.getVelocity().add(knockback));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/catadmirer/infuseSMP/managers/Drop.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Drop(Infuse plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPickup(EntityPickupItemEvent event) {
ItemStack item = event.getItem().getItemStack();
InfuseEffect effect = InfuseEffect.fromItem(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.catadmirer.infuseSMP.worldguard;

import com.catadmirer.infuseSMP.Infuse;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

public class WorldGuardAPI {

private static Boolean loaded;
private static Boolean enabled;

private static StateFlag USE_SPARKS;
private static StateFlag SPARK_PASSTHROUGH;
private static StateFlag OCEAN_ENABLED;

public void init() {
USE_SPARKS = new StateFlag("region-use_sparks", true);
SPARK_PASSTHROUGH = new StateFlag("region-spark_passthrough", true);
OCEAN_ENABLED = new StateFlag("region-ocean_enabled", true);

try {
WorldGuard.getInstance().getFlagRegistry().registerAll(List.of(USE_SPARKS, SPARK_PASSTHROUGH, OCEAN_ENABLED));
} catch (FlagConflictException ex) {
Infuse.LOGGER.warn("A flag has conflicted with another plugin! Disabling worldguard hook...");
loaded = false;
return;
}

loaded = true;
Infuse.LOGGER.info("Successfully loaded custom WorldGuard flags.");
}

public static boolean isLoaded() {
return loaded;
}

public static boolean isEnabled() {
return enabled;
}

public static void setEnabled(boolean status) {
enabled = status;
}

public static StateFlag getUseSparksFlag() {
return USE_SPARKS;
}

public static StateFlag getSparkPassThroughFlag() {
return SPARK_PASSTHROUGH;
}

public static StateFlag getOceanEnabledFlag() {
return OCEAN_ENABLED;
}

public static boolean isFlagEnabled(Entity entity, StateFlag flag) {
if (!enabled) return true;

final RegionQuery set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
if (entity instanceof Player) {
return set.getApplicableRegions(BukkitAdapter.adapt(entity.getLocation())).queryState(WorldGuardPlugin.inst().wrapPlayer((Player) entity), flag) != StateFlag.State.DENY;
} else {
return set.queryState(BukkitAdapter.adapt(entity.getLocation()), null, flag) != StateFlag.State.DENY;
}
}

public static List<Entity> getAllEntitiesWhereFlagIsAllowed(Player player, double radius, StateFlag flag) {
return new ArrayList<>(player.getNearbyEntities(radius, radius, radius).stream().filter(entity -> isFlagEnabled(entity, flag)).toList());
}

public static List<Player> getAllPlayersWhereFlagIsAllowed(Player player, double radius, StateFlag flag) {
final List<Player> players = new ArrayList<>();

player.getNearbyEntities(radius, radius, radius).stream().filter(plr -> plr instanceof Player && isFlagEnabled(plr, flag)).toList()
.forEach(target -> players.add((Player) target));

return players;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.catadmirer.infuseSMP.worldguard.handlers;

import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;

public class OceanEnabledHandler extends Handler {

private static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<OceanEnabledHandler> {
@Override
public OceanEnabledHandler create(Session session) {
return new OceanEnabledHandler(session);
}
}

public OceanEnabledHandler(Session session) {
super(session);
}

public static Factory getFactory() {
return FACTORY;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ discord_broadcast: "%player% is cooking up the %item% at %x%, %y%, %z% in %dimen
effect_finished: "%item% has been brewed!"
regular_broadcast: "🧪 A %item%<reset> has been crafted at <#90D5FF><b>%x%, %y%, %z%... %dimension%"

# This is for if you have WorldGuard installed.
region_spark_use_disabled: "The current region that you are currently inside of has sparks disabled."

# %slot% = Number 1/2 (Which slot they're using)

slot_empty: "<red>You don't have any effect equipped in slot %slot%."
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '$version'
main: com.catadmirer.infuseSMP.Infuse
api-version: '1.21.4'
authors: [CatAdmirer, TurboJax]
softdepend: [PlaceholderAPI]
softdepend: [PlaceholderAPI, WorldGuard]
commands:
infuse:
description: Base command for Infuse
Expand Down