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
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ version = '2.0-SNAPSHOT'
repositories {
mavenCentral()
maven { url = "https://repo.papermc.io/repository/maven-public" }
maven { url = "https://repo.mattstudios.me/artifactory/public/" }
Comment thread
garrettsummerfi3ld marked this conversation as resolved.
maven { url = "https://maven.enginehub.org/repo/" }
}

dependencies {
compileOnly group: 'com.sk89q.worldguard', name: 'worldguard-bukkit', version: '7.0.9'
compileOnly group: 'io.papermc.paper', name: 'paper-api', version: '1.20.2-R0.1-SNAPSHOT'
implementation group: 'dev.triumphteam', name: 'triumph-gui', version: '3.1.7'
compileOnly group: 'net.luckperms', name: 'api', version: '5.4'
implementation group: 'dev.triumphteam', name: 'triumph-gui', version: '3.1.7'
}

def targetJavaVersion = 17
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/tv/galaxe/smp/Core.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package tv.galaxe.smp;

import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import java.util.HashSet;
import net.luckperms.api.LuckPerms;
import org.bukkit.command.Command;
Expand All @@ -17,6 +22,7 @@
public class Core extends JavaPlugin implements Listener {
public static Plugin plugin;
public static LuckPerms lp;
public static StateFlag INVIS_ITEM_FRAME;
public static HashSet<String> validPronouns = new HashSet<String>();

@Override
Expand Down Expand Up @@ -46,6 +52,24 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
getServer().getPluginManager().registerEvents(new StaffKill(), this);
}

@Override
public void onLoad() {
// WorldGuard
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
try {
StateFlag flag = new StateFlag("cmd-invis-item-frame", true);
registry.register(flag);
INVIS_ITEM_FRAME = flag;
} catch (FlagConflictException e) {
Flag<?> existing = registry.get("cmd-invis-item-frame");
if (existing instanceof StateFlag) {
INVIS_ITEM_FRAME = (StateFlag) existing;
} else {
// We just eat the error and fail silently, but this *REALLY* shouldn't happen
}
}
}

@Override
public void onDisable() {
getServer().getConsoleSender().sendMessage("GalaxeSMP Plugin Disabled");
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/tv/galaxe/smp/cmd/InvisibleItemFrame.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package tv.galaxe.smp.cmd;

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.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.GlowItemFrame;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import tv.galaxe.smp.Core;

public final class InvisibleItemFrame implements CommandExecutor {
private static final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) { // Only allow players to run command
Expand All @@ -21,6 +30,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("You must be looking at an item frame!");
return false;
}

// Check if player has region permission to change item frame visibility
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(lookingAt.getLocation()));
if (!set.testState(WorldGuardPlugin.inst().wrapPlayer(player), Core.INVIS_ITEM_FRAME) && !WorldGuard
.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
sender.sendMessage("You do not have permission to do that here!");
return false;
}

// Change item frame visibility
switch (lookingAt.getType()) {
case ITEM_FRAME :
ItemFrame itemFrame = (ItemFrame) lookingAt;
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 @@ -4,7 +4,7 @@ authors: [ garrettsummerfi3ld, josefbaltz ]
version: '${version}'
main: tv.galaxe.smp.Core
prefix: GalaxeSMP
depend: [ LuckPerms ]
depend: [ LuckPerms, WorldGuard ]
description: Custom GalaxeSMP Plugin
website: https://github.com/GalaxeTV/GalaxeSMP-Plugin
commands:
Expand Down