Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Dominion Protection module #278

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions dough-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@
<version>1.0.580</version>
<scope>provided</scope>
</dependency>

<!-- Dominion -->
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>DominionAPI</artifactId>
<version>4.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
14 changes: 14 additions & 0 deletions dough-protection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@
</exclusion>
</exclusions>
</dependency>

<!-- Dominion -->
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>DominionAPI</artifactId>
<version>4.2</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.bakedlibs.dough.protection.modules.*;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
Expand All @@ -18,24 +19,6 @@
import io.github.bakedlibs.dough.common.DoughLogger;
import io.github.bakedlibs.dough.protection.loggers.CoreProtectLogger;
import io.github.bakedlibs.dough.protection.loggers.LogBlockLogger;
import io.github.bakedlibs.dough.protection.modules.BentoBoxProtectionModule;
import io.github.bakedlibs.dough.protection.modules.BlockLockerProtectionModule;
import io.github.bakedlibs.dough.protection.modules.BoltProtectionModule;
import io.github.bakedlibs.dough.protection.modules.ChestProtectProtectionModule;
import io.github.bakedlibs.dough.protection.modules.FactionsUUIDProtectionModule;
import io.github.bakedlibs.dough.protection.modules.FunnyGuildsProtectionModule;
import io.github.bakedlibs.dough.protection.modules.GriefPreventionProtectionModule;
import io.github.bakedlibs.dough.protection.modules.HuskTownsProtectionModule;
import io.github.bakedlibs.dough.protection.modules.HuskClaimsProtectionModule;
import io.github.bakedlibs.dough.protection.modules.LWCProtectionModule;
import io.github.bakedlibs.dough.protection.modules.LandsProtectionModule;
import io.github.bakedlibs.dough.protection.modules.LocketteProtectionModule;
import io.github.bakedlibs.dough.protection.modules.PlotSquaredProtectionModule;
import io.github.bakedlibs.dough.protection.modules.PreciousStonesProtectionModule;
import io.github.bakedlibs.dough.protection.modules.RedProtectProtectionModule;
import io.github.bakedlibs.dough.protection.modules.ShopChestProtectionModule;
import io.github.bakedlibs.dough.protection.modules.TownyProtectionModule;
import io.github.bakedlibs.dough.protection.modules.WorldGuardProtectionModule;

/**
* This Class provides a nifty API for plugins to query popular protection plugins.
Expand Down Expand Up @@ -97,6 +80,7 @@ private void loadModuleImplementations(Plugin plugin) {
registerModule(pm, "ShopChest", shopChest -> new ShopChestProtectionModule(shopChest));
registerModule(pm, "HuskClaims", huskClaims -> new HuskClaimsProtectionModule(huskClaims));
registerModule(pm, "Bolt", bolt -> new BoltProtectionModule(bolt));
registerModule(pm, "Dominion", dominion -> new DominionProtectionModule(dominion));

/*
* The following Plugins work by utilising one of the above listed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package io.github.bakedlibs.dough.protection.modules;

import cn.lunadeer.dominion.api.DominionAPI;
import cn.lunadeer.dominion.api.dtos.DominionDTO;
import cn.lunadeer.dominion.api.dtos.flag.EnvFlag;
import cn.lunadeer.dominion.api.dtos.flag.Flag;
import cn.lunadeer.dominion.api.dtos.flag.Flags;
import cn.lunadeer.dominion.api.dtos.flag.PriFlag;
import io.github.bakedlibs.dough.protection.Interaction;
import io.github.bakedlibs.dough.protection.ProtectionModule;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;

public class DominionProtectionModule implements ProtectionModule {

private final Plugin plugin;
private DominionAPI api;

public DominionProtectionModule(Plugin plugin) {
this.plugin = plugin;
}

/**
* Use this method to load instances of your API or other utilites you need
*/
@Override
public void load() {
try {
api = DominionAPI.getInstance();
} catch (Exception e) {
plugin.getLogger().warning("Failed to load Dominion API. Disabling Dominion Protection Module.");
}
}

/**
* This returns the {@link Plugin} for this {@link ProtectionModule}.
*
* @return The associated {@link Plugin}
*/
@Override
public Plugin getPlugin() {
return plugin;
}

/**
* This method implements the functionality of this module.
* Use it to allow or deny an Action based on the rules of your Protection {@link Plugin}
*
* @param p The Player that is being queried, can be offline
* @param l The {@link Location} of the event that is happening
* @param action The {@link Interaction} that is taking place.
* @return Whether the action was allowed by your {@link Plugin}
*/
@Override
public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) {
if (!p.isOnline()) {
return false;
}
Player player = p.getPlayer();
if (player == null) {
return true;
}
Flag flag = getDominionFlagFromInteraction(action);
if (flag == null) {
return true;
}
DominionDTO dominion = api.getDominion(l);
if (dominion == null) {
return true;
}
if (flag instanceof PriFlag) {
PriFlag preFlag = (PriFlag) flag;
return api.checkPrivilegeFlag(dominion, preFlag, player);
} else {
EnvFlag envFlag = (EnvFlag) flag;
return api.checkEnvironmentFlag(dominion, envFlag);
}
}

private @Nullable Flag getDominionFlagFromInteraction(@Nonnull Interaction action) {
switch (action) {
case BREAK_BLOCK:
return Flags.BREAK_BLOCK;
case PLACE_BLOCK:
return Flags.PLACE;
case INTERACT_BLOCK:
return Flags.CONTAINER;
case ATTACK_PLAYER:
return Flags.PLAYER_DAMAGE;
default:
return null;
}
}
}