Skip to content

Commit

Permalink
— Added bStats (Metrics).
Browse files Browse the repository at this point in the history
— Code cleanup.
— Rewrote hooks for expansion.
— Added support for Residence.
— Added 1.21 support.
— Bumped to version 1.7.0.
  • Loading branch information
Baktus79 committed Jun 29, 2024
1 parent 5d083b8 commit d13877e
Show file tree
Hide file tree
Showing 30 changed files with 609 additions and 882 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/libs/
22 changes: 16 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'java'
id 'io.freefair.lombok' version '8.4'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group = 'no.vestlandetmc'
version = '1.6.6'
version = '1.7.0'

repositories {
mavenCentral()
Expand All @@ -14,16 +15,25 @@ repositories {
}

dependencies {
implementation 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
implementation 'com.github.GriefPrevention:GriefPrevention:16.18.4'
implementation 'com.griefdefender:api:2.1.0-SNAPSHOT'
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'com.github.GriefPrevention:GriefPrevention:16.18.4'
compileOnly 'com.griefdefender:api:2.1.0-SNAPSHOT'
implementation 'org.bstats:bstats-bukkit:3.0.2'
}

jar {
shadowJar {
relocate 'org.bstats', 'no.vestlandetmc.BanFromClaim.bstats'
archiveFileName.set('Banfromclaim.jar')
}

def targetJavaVersion = 21
jar.dependsOn shadowJar

jar {
enabled = false
}

def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
Expand Down
74 changes: 23 additions & 51 deletions src/main/java/no/vestlandetmc/BanFromClaim/BfcPlugin.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package no.vestlandetmc.BanFromClaim;

import no.vestlandetmc.BanFromClaim.commands.SafeSpot;
import no.vestlandetmc.BanFromClaim.commands.griefdefender.*;
import no.vestlandetmc.BanFromClaim.commands.griefprevention.*;
import lombok.Getter;
import no.vestlandetmc.BanFromClaim.commands.*;
import no.vestlandetmc.BanFromClaim.config.ClaimData;
import no.vestlandetmc.BanFromClaim.config.Config;
import no.vestlandetmc.BanFromClaim.config.Messages;
import no.vestlandetmc.BanFromClaim.handler.Hooks;
import no.vestlandetmc.BanFromClaim.handler.MessageHandler;
import no.vestlandetmc.BanFromClaim.hooks.HookManager;
import no.vestlandetmc.BanFromClaim.listener.CombatMode;
import no.vestlandetmc.BanFromClaim.listener.GDListener;
import no.vestlandetmc.BanFromClaim.listener.GPListener;
import no.vestlandetmc.BanFromClaim.listener.PlayerListener;
import no.vestlandetmc.BanFromClaim.listener.RegionListener;
import no.vestlandetmc.BanFromClaim.schedulers.CombatScheduler;
import no.vestlandetmc.BanFromClaim.utils.UpdateNotification;
import org.bukkit.Bukkit;
import org.bstats.bukkit.Metrics;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -26,18 +24,16 @@

public class BfcPlugin extends JavaPlugin {

private static BfcPlugin instance;
@Getter
private static BfcPlugin plugin;
@Getter
private static HookManager hookManager;

private File dataFile;
private FileConfiguration data;

public static BfcPlugin getInstance() {
return instance;
}

@Override
public void onEnable() {
instance = this;
plugin = this;

MessageHandler.sendConsole("&2 ___ ___ ___");
MessageHandler.sendConsole("&2| _ ) __/ __| &8" + getDescription().getName() + " v" + getDescription().getVersion());
Expand All @@ -46,44 +42,16 @@ public void onEnable() {
MessageHandler.sendConsole("");

Config.initialize();
hookManager = new HookManager();

if (getServer().getPluginManager().getPlugin("GriefPrevention") != null) {
MessageHandler.sendConsole("&2[" + getDescription().getPrefix() + "] &7Successfully hooked into &eGriefPrevention");
MessageHandler.sendConsole("");

Hooks.setGP();

this.getServer().getPluginManager().registerEvents(new GPListener(), this);
this.getCommand("banfromclaim").setExecutor(new BfcCommand());
this.getCommand("unbanfromclaim").setExecutor(new UnbfcCommand());
this.getCommand("banfromclaimlist").setExecutor(new BfclistCommand());
this.getCommand("banfromclaimall").setExecutor(new BfcAllCommand());

if (Config.KICKMODE) {
this.getCommand("kickfromclaim").setExecutor(new KfcCommandGP());
}

} else if (getServer().getPluginManager().getPlugin("GriefDefender") != null) {
MessageHandler.sendConsole("&2[" + getDescription().getPrefix() + "] &7Successfully hooked into &eGriefDefender");
MessageHandler.sendConsole("");
this.getServer().getPluginManager().registerEvents(new RegionListener(), this);
this.getCommand("banfromclaim").setExecutor(new BfcCommand());
this.getCommand("unbanfromclaim").setExecutor(new UnbfcCommand());
this.getCommand("banfromclaimlist").setExecutor(new BfclistCommand());
this.getCommand("banfromclaimall").setExecutor(new BfcAllCommand());

Hooks.setGD();

this.getServer().getPluginManager().registerEvents(new GDListener(), this);
this.getCommand("banfromclaim").setExecutor(new BfcCommandGD());
this.getCommand("unbanfromclaim").setExecutor(new UnbfcCommandGD());
this.getCommand("banfromclaimlist").setExecutor(new BfclistCommandGD());
this.getCommand("banfromclaimall").setExecutor(new BfcAllCommandGD());

if (Config.KICKMODE) {
this.getCommand("kickfromclaim").setExecutor(new KfcCommandGD());
}

} else {
MessageHandler.sendConsole("&2[" + getDescription().getPrefix() + "] &cNo supported claimsystem was found.");
MessageHandler.sendConsole("");
Bukkit.getPluginManager().disablePlugin(this);
return;
if (Config.KICKMODE) {
this.getCommand("kickfromclaim").setExecutor(new KfcCommand());
}

this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
Expand Down Expand Up @@ -116,14 +84,18 @@ public void onUpdateAvailable() {
MessageHandler.sendConsole("&c-----------------------");
}
}.runTaskAsynchronously(this);

final int pluginId = 22441;
final Metrics metrics = new Metrics(this, pluginId);

}

public FileConfiguration getDataFile() {
return this.data;
}

public void createDatafile() {
dataFile = new File(this.getDataFolder(), "data.dat");
final File dataFile = new File(this.getDataFolder(), "data.dat");
if (!dataFile.exists()) {
dataFile.getParentFile().mkdirs();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
package no.vestlandetmc.BanFromClaim.commands.griefprevention;
package no.vestlandetmc.BanFromClaim.commands;

import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import no.vestlandetmc.BanFromClaim.BfcPlugin;
import no.vestlandetmc.BanFromClaim.config.ClaimData;
import no.vestlandetmc.BanFromClaim.config.Messages;
import no.vestlandetmc.BanFromClaim.handler.MessageHandler;
import org.bukkit.Location;
import no.vestlandetmc.BanFromClaim.hooks.RegionHook;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class BfcAllCommand implements CommandExecutor {

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
if (!(sender instanceof Player player)) {
MessageHandler.sendConsole("&cThis command can only be used in-game.");
return true;
}

final Player player = (Player) sender;
final Location loc = player.getLocation();
final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, true, null);
final ClaimData claimData = new ClaimData();
final RegionHook region = BfcPlugin.getHookManager().getActiveRegionHook();
final String regionID = region.getRegionID(player);

if (claim == null) {
if (regionID == null) {
MessageHandler.sendMessage(player, Messages.OUTSIDE_CLAIM);
return true;
}

final String accessDenied = claim.allowGrantPermission(player);
boolean allowBan = false;

if (accessDenied == null) {
allowBan = true;
} else if (player.hasPermission("bfc.admin")) {
allowBan = true;
}
final boolean allowBan = player.hasPermission("bfc.admin") || region.isOwner(player, regionID) || region.isManager(player, regionID);

if (allowBan) {
claimData.banAll(claim.getID().toString());
claimData.banAll(regionID);

if (claimData.isAllBanned(claim.getID().toString())) {
if (claimData.isAllBanned(regionID)) {
MessageHandler.sendMessage(player, Messages.BAN_ALL);
} else {
MessageHandler.sendMessage(player, Messages.UNBAN_ALL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package no.vestlandetmc.BanFromClaim.commands.griefdefender;
package no.vestlandetmc.BanFromClaim.commands;

import com.griefdefender.api.Core;
import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.TrustTypes;
import com.griefdefender.lib.flowpowered.math.vector.Vector3i;
import no.vestlandetmc.BanFromClaim.BfcPlugin;
import no.vestlandetmc.BanFromClaim.config.ClaimData;
import no.vestlandetmc.BanFromClaim.config.Config;
import no.vestlandetmc.BanFromClaim.config.Messages;
import no.vestlandetmc.BanFromClaim.handler.MessageHandler;
import no.vestlandetmc.BanFromClaim.hooks.RegionHook;
import no.vestlandetmc.BanFromClaim.utils.LocationFinder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -19,41 +15,31 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class BfcCommandGD implements CommandExecutor {
public class BfcCommand implements CommandExecutor {

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
MessageHandler.sendConsole("&cThis command can only be used in-game.");
return true;
}

final Location loc = player.getLocation();
final Vector3i vector = Vector3i.from(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
final Core gd = GriefDefender.getCore();
final Claim claim = gd.getClaimManager(loc.getWorld().getUID()).getClaimAt(vector);
final RegionHook region = BfcPlugin.getHookManager().getActiveRegionHook();
final String regionID = region.getRegionID(player);

if (args.length == 0) {
MessageHandler.sendMessage(player, Messages.NO_ARGUMENTS);
return true;
}

if (claim.isWilderness()) {
if (regionID == null) {
MessageHandler.sendMessage(player, Messages.OUTSIDE_CLAIM);
return true;
}


@SuppressWarnings("deprecation") final OfflinePlayer bannedPlayer = Bukkit.getOfflinePlayer(args[0]);
final boolean isManager = claim.getUserTrusts(TrustTypes.MANAGER).contains(player.getUniqueId());
final boolean isOwner = claim.getOwnerUniqueId().equals(player.getUniqueId());
boolean allowBan = false;

if (isOwner || isManager) {
allowBan = true;
} else if (player.hasPermission("bfc.admin")) {
allowBan = true;
}
final OfflinePlayer bannedPlayer = Bukkit.getOfflinePlayer(args[0]);
boolean allowBan = player.hasPermission("bfc.admin") || region.isOwner(player, regionID) || region.isManager(player, regionID);

if (!bannedPlayer.isOnline()) {
if (!bannedPlayer.hasPlayedBefore()) {
Expand All @@ -62,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else if (bannedPlayer == player) {
MessageHandler.sendMessage(player, Messages.BAN_SELF);
return true;
} else if (bannedPlayer.getName().equals(claim.getOwnerName())) {
} else if (region.isOwner(bannedPlayer, regionID)) {
MessageHandler.sendMessage(player, Messages.BAN_OWNER);
return true;
}
Expand All @@ -77,29 +63,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
MessageHandler.sendMessage(player, Messages.NO_ACCESS);
return true;
} else {
final String claimOwner = claim.getOwnerName();
final int sizeRadius = Math.max(claim.getLength(), claim.getWidth());

final Location greaterCorner = new Location(
Bukkit.getWorld(claim.getWorldUniqueId()),
claim.getGreaterBoundaryCorner().getX(),
64D,
claim.getGreaterBoundaryCorner().getZ());

final Location lesserCorner = new Location(
Bukkit.getWorld(claim.getWorldUniqueId()),
claim.getLesserBoundaryCorner().getX(),
64D,
claim.getLesserBoundaryCorner().getZ());

if (setClaimData(player, claim.getUniqueId().toString(), bannedPlayer.getUniqueId().toString(), true)) {
final String claimOwner = region.getClaimOwnerName(regionID);

final int sizeRadius = region.sizeRadius(regionID);
final Location greaterCorner = region.getGreaterBoundaryCorner(regionID);
final Location lesserCorner = region.getLesserBoundaryCorner(regionID);

if (setClaimData(regionID, bannedPlayer.getUniqueId().toString(), true)) {
if (bannedPlayer.isOnline()) {
final Location bannedLoc = bannedPlayer.getPlayer().getLocation();
final Vector3i bannedVec = Vector3i.from(bannedLoc.getBlockX(), bannedLoc.getBlockY(), bannedLoc.getBlockZ());
if (claim.contains(bannedVec)) {
final LocationFinder lf = new LocationFinder(greaterCorner, lesserCorner, claim.getWorldUniqueId(), sizeRadius);
if (region.isInsideRegion(bannedPlayer.getPlayer(), regionID)) {
final Location bannedLoc = bannedPlayer.getPlayer().getLocation();
final LocationFinder lf = new LocationFinder(greaterCorner, lesserCorner, bannedLoc.getWorld().getUID(), sizeRadius);

Bukkit.getScheduler().runTaskAsynchronously(BfcPlugin.getInstance(), () -> lf.IterateCircumferences(randomCircumferenceRadiusLoc -> {
Bukkit.getScheduler().runTaskAsynchronously(BfcPlugin.getPlugin(), () -> lf.IterateCircumferences(randomCircumferenceRadiusLoc -> {
if (randomCircumferenceRadiusLoc == null) {
if (Config.SAFE_LOCATION == null) {
bannedPlayer.getPlayer().teleport(bannedLoc.getWorld().getSpawnLocation());
Expand All @@ -121,15 +97,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else {
MessageHandler.sendMessage(player, Messages.ALREADY_BANNED);
}

}
return true;
}

private boolean setClaimData(Player player, String claimID, String bannedUUID, boolean add) {
private boolean setClaimData(String claimID, String bannedUUID, boolean add) {
final ClaimData claimData = new ClaimData();

return claimData.setClaimData(player, claimID, bannedUUID, add);
return claimData.setClaimData(claimID, bannedUUID, add);
}

}
Loading

0 comments on commit d13877e

Please sign in to comment.