Skip to content

Commit

Permalink
0.10
Browse files Browse the repository at this point in the history
Removed custom Flag
Main reasons:
① The registration timing required by each plugin is difficult to control. Some require the onLoad stage, while others require the plugin to be enabled
② Some plugins require GUI item configuration, making compatibility with multiple plugins difficult
  • Loading branch information
Xiao-MoMi committed Apr 20, 2024
1 parent 8533cf5 commit 36cf483
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 362 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,13 @@ dependencies {

### API Guide
```java
// create a lib instance on plugin load
var lib = AntiGriefLib.builder(this)
// Create a lib instance on plugin enable
var lib = AntiGriefLib.builder(JavaPlugin)
.silentLogs(true)
.ignoreOP(true)
.placeFlag(
Flag.builder("custom-place")
.defaultValue(false)
.displayName("Custom place")
.description(List.of("My custom place flag"))
.displayItem(new ItemStack(Material.STONE))
.build()
)
.addCompatibility(new MyCustomAntiGriefImpl())
.build();

// init the lib after all the compatible plugins enabled
lib.init();

// use the api to check permissions
if (!lib.canPlace(player, location)) {
player.sendMessage(Component.text("You can't place it here!"));
Expand Down
12 changes: 0 additions & 12 deletions common/src/main/java/net/momirealms/antigrieflib/CustomFlag.java

This file was deleted.

80 changes: 0 additions & 80 deletions common/src/main/java/net/momirealms/antigrieflib/Flag.java

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion = 0.9
projectVersion = 0.10
projectGroup=net.momirealms

#systemProp.socks.proxyHost=127.0.0.1
Expand Down
7 changes: 4 additions & 3 deletions project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
maven("https://repo.william278.net/releases/") // HuskTowns, HuskClaims
maven("https://repo.bg-software.com/repository/api/") // SuperiorSkyBlock
maven("https://repo.glaremasters.me/repository/towny/") // Towny
maven("https://repo.craftaro.com/repository/minecraft-plugins/") // FabledSkyBlock, UltimateClaims
maven("https://repo.songoda.com/repository/minecraft-plugins/") // FabledSkyBlock, UltimateClaims
maven("https://ci.ender.zone/plugin/repository/everything/") // FactionsUUID
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // RedProtect
maven("https://eldonexus.de/repository/maven-releases/") // Landlord
Expand All @@ -23,7 +23,7 @@ dependencies {

compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") // Paper
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9") // WorldGuard
compileOnly("com.github.angeschossen:LandsAPI:6.44.10") // Lands
compileOnly("com.github.angeschossen:LandsAPI:7.0.2") // Lands
compileOnly("com.iridium:IridiumSkyblock:4.0.8") // IridiumSkyBlock
compileOnly("world.bentobox:bentobox:2.1.0-SNAPSHOT") // BentoBox
compileOnly("com.griefdefender:api:2.1.0-SNAPSHOT") // GriefDefender
Expand All @@ -38,14 +38,15 @@ dependencies {
compileOnly("com.massivecraft:Factions:1.6.9.5-U0.6.33") // FactionsUUID
compileOnly("dev.espi:protectionstones:2.10.2") // ProtectionStones
compileOnly("biz.princeps:landlord-core:4.364") // Landlord
compileOnly("ovh.uskyblock:uSkyBlock-Core:3.0.0") // uSkyBlock
// compileOnly("ovh.uskyblock:uSkyBlock-Core:3.0.0") // uSkyBlock (Removed because it's repo is down)
compileOnly("com.github.UlrichBR:UClansV7-API:7.4.0-r1") // UltimateClans

compileOnly(files("libs/Residence-pruned.jar")) // Residence
compileOnly(files("libs/KingdomsX-pruned.jar")) // KingdomsX
compileOnly(files("libs/CrashClaim-pruned.jar")) // CrashClaim
compileOnly(files("libs/XClaim.jar")) // XClaim
compileOnly(files("libs/SuperiorSkyblock2-2023.3.jar")) // SuperiorSkyBlock2 - Plugin
compileOnly(files("libs/uSkyBlock-3.0.0.jar")) // uSkyBlock

compileOnly("io.github.fabiozumbi12.RedProtect:RedProtect-Core:8.1.1") { exclude(group = "*") } // RedProtect
compileOnly("io.github.fabiozumbi12.RedProtect:RedProtect-Spigot:8.1.1") { exclude(group = "*") } // RedProtect
Expand Down
Binary file added project/libs/uSkyBlock-3.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class AntiGriefLib {

private final JavaPlugin plugin;
private final Set<AntiGriefPlugin> plugins;
private Flag customPlaceFlag;
private Flag customBreakFlag;
private Flag customInteractFlag;
private boolean ignoreOP;
private boolean silentLogs;

Expand All @@ -29,15 +26,9 @@ private AntiGriefLib(JavaPlugin plugin) {
this.plugin = plugin;
}

/**
* It's recommended to call this method after all the plugins are enabled
*/
public void init() {
private void init() {
for (AntiGriefPlugin antiGriefPlugin : plugins) {
antiGriefPlugin.init();
if (antiGriefPlugin instanceof CustomFlag customFlag) {
customFlag.registerOnEnable(customPlaceFlag, customBreakFlag, customInteractFlag);
}
logHook(antiGriefPlugin.getAntiGriefPluginName());
}
}
Expand Down Expand Up @@ -128,6 +119,9 @@ public boolean canInteractEntity(Player player, Entity entity) {
* @return has perm or not
*/
public boolean canDamage(Player player, Entity entity) {
if (entity instanceof Player another && !another.getWorld().getPVP()) {
return false;
}
if (ignoreOP && player.isOp()) return true;
for (AntiGriefPlugin antiGriefPlugin : plugins) {
if (!antiGriefPlugin.canDamage(player, entity)) {
Expand Down Expand Up @@ -156,32 +150,13 @@ public Builder silentLogs(boolean silent) {
return this;
}

public Builder placeFlag(Flag flag) {
lib.customPlaceFlag = flag;
return this;
}

public Builder breakFlag(Flag flag) {
lib.customBreakFlag = flag;
return this;
}

public Builder interactFlag(Flag flag) {
lib.customInteractFlag = flag;
return this;
}

public Builder addCompatibility(AntiGriefPlugin antiGriefPlugin) {
lib.registerNewCompatibility(antiGriefPlugin);
return this;
}

public AntiGriefLib build() {
for (AntiGriefPlugin antiGriefPlugin : lib.plugins) {
if (antiGriefPlugin instanceof CustomFlag customFlag) {
customFlag.registerOnLoad(lib.customPlaceFlag, lib.customBreakFlag, lib.customInteractFlag);
}
}
lib.init();
return lib;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ public boolean canInteract(Player player, Location location) {

@Override
public boolean canInteractEntity(Player player, Entity entity) {
// I am not sure if I should use Flags.HURT_xxx or Flags.CONTAINER
return entityOperation(player, entity);
return BentoBox.getInstance()
.getIslands()
.getIslandAt(entity.getLocation())
.map(island -> island.isAllowed(User.getInstance(player), Flags.CONTAINER))
.orElse(true);
}

@Override
public boolean canDamage(Player player, Entity entity) {
return entityOperation(player, entity) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return entityOperation(player, entity);
}

private boolean entityOperation(final Player player, final Entity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public boolean canInteractEntity(Player player, Entity entity) {

@Override
public boolean canDamage(Player player, Entity entity) {
return api.getPermissionHelper().hasPermission(player.getUniqueId(), entity.getLocation(), PermissionRoute.ENTITIES) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return api.getPermissionHelper().hasPermission(player.getUniqueId(), entity.getLocation(), PermissionRoute.ENTITIES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean canInteractEntity(Player player, Entity entity) {

@Override
public boolean canDamage(Player player, Entity entity) {
return isIslandMember(player, entity.getLocation()) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return isIslandMember(player, entity.getLocation());
}

private boolean isIslandMember(Player player, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public boolean canInteract(Player player, Location location) {
@Override
public boolean canInteractEntity(Player player, Entity entity) {
if (!plugin.worldUtil().isEnabled(entity.getWorld())) return true;
return FactionsEntityListener.canDamage(player, entity, false);
return FactionsBlockListener.playerCanBuildDestroyBlock(player, entity.getLocation(), PermissibleActions.CONTAINER, false);
}

@Override
public boolean canDamage(Player player, Entity entity) {
if (!plugin.worldUtil().isEnabled(entity.getWorld())) return !(entity instanceof Player) || entity.getWorld().getPVP();
return FactionsEntityListener.canDamage(player, entity, false) && (!(entity instanceof Player) || entity.getWorld().getPVP());
if (!plugin.worldUtil().isEnabled(entity.getWorld())) return true;
return FactionsEntityListener.canDamage(player, entity, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public boolean canInteractEntity(Player player, Entity entity) {
public boolean canDamage(Player player, Entity entity) {
return Optional.ofNullable(GriefDefender.getCore().getUser(player.getUniqueId()))
.map(user -> user.canHurtEntity(player.getInventory().getItemInMainHand(), entity))
.orElse(false) && (!(entity instanceof Player) || entity.getWorld().getPVP());
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean canInteractEntity(Player player, Entity entity) {

@Override
public boolean canDamage(Player player, Entity entity) {
return checkPermission(player, entity.getLocation(), ClaimPermission.Inventory) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return checkPermission(player, entity.getLocation(), ClaimPermission.Inventory);
}

private boolean checkPermission(Player player, Location location, ClaimPermission permission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public boolean canInteractEntity(Player player, Entity entity) {

@Override
public boolean canDamage(Player player, Entity entity) {
return api.isOperationAllowed(api.getOnlineUser(player), OperationType.PLAYER_DAMAGE_ENTITY, api.getPosition(entity.getLocation())) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return api.isOperationAllowed(api.getOnlineUser(player), OperationType.PLAYER_DAMAGE_ENTITY, api.getPosition(entity.getLocation()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean canInteractEntity(Player player, Entity entity) {

@Override
public boolean canDamage(Player player, Entity entity) {
return isTownMember(player, entity.getLocation()) && (!(entity instanceof Player) || entity.getWorld().getPVP());
return isTownMember(player, entity.getLocation());
}

public boolean isTownMember(Player player, Location location) {
Expand Down
Loading

0 comments on commit 36cf483

Please sign in to comment.