Skip to content

Commit

Permalink
Merge pull request #134 from Awoo-industries/grief-prevention-overrides
Browse files Browse the repository at this point in the history
Grief prevention overrides
  • Loading branch information
BeepSterr authored Jun 11, 2024
2 parents 6e7d4b1 + 632d8ca commit 1d49b12
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dev_server/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Tue Jun 11 01:34:57 CEST 2024
#Tue Jun 11 02:30:47 CEST 2024
accepts-transfers=false
allow-flight=false
allow-nether=false
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,11 @@
<version>0.99.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.GriefPrevention</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.18.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
99 changes: 96 additions & 3 deletions src/main/java/dev/beeps/plugins/BetterConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.beeps.plugins;

import dev.beeps.plugins.Depends.GriefPreventionApi;
import dev.beeps.plugins.Depends.Towny;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.ClaimPermission;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -63,7 +66,7 @@ public BetterConfig(BetterKeepInventory _plugin, FileConfiguration _config){
migrateTo1p4();
break;
case 3:
migrateToExpandedEco();
migrateToExpandedEcoAndGriefPrevention();
break;

}
Expand Down Expand Up @@ -246,7 +249,7 @@ public void migrateTo1p4(){

}

public void migrateToExpandedEco(){
public void migrateToExpandedEcoAndGriefPrevention(){

plugin.log(Level.INFO, "ConfigMigrator", "Migrating to config format 4");
File file = new File(plugin.getDataFolder() + File.separator + "config.yml");
Expand All @@ -262,6 +265,21 @@ public void migrateToExpandedEco(){
config.set("eco.mode", "SIMPLE"); // new Eco Modes (SIMPLE & PERCENTAGE)
config.set("eco.pay_to_killer", false); // new Eco Pay killer (PvP Only)

// Grief Prevention Overrides

config.set("overrides.grief_prevention.enabled", false);

String[] default_overrides = {"NONE"};
String[] own_claim = {"ALL"};

config.set("overrides.grief_prevention.claims.own", own_claim);
config.set("overrides.grief_prevention.claims.admin", default_overrides);
config.set("overrides.grief_prevention.claims.edit", default_overrides);
config.set("overrides.grief_prevention.claims.build", default_overrides);
config.set("overrides.grief_prevention.claims.inventory", default_overrides);
config.set("overrides.grief_prevention.claims.access", default_overrides);
config.set("overrides.grief_prevention.claims.any", default_overrides);

plugin.saveConfig();
plugin.log(Level.INFO, "ConfigMigrator", "Saved new config");
plugin.log(Level.INFO, "ConfigMigrator", "Completed migration to format 4");
Expand Down Expand Up @@ -356,21 +374,44 @@ public List<String> getDisabledModesInWorld(String world){
List<String> anylist = this.config.getStringList("overrides.worlds.all");
return Stream.concat(worldlist.stream(), anylist.stream()).toList();
}

public List<String> getDisabledModesInWorldByDamageType(String world, String damageType){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.worlds." + world);
List<String> worldlist = this.config.getStringList("overrides.worlds." + world + ".damage_types." + damageType);
List<String> anylist = this.config.getStringList("overrides.worlds.all.damage_types." + damageType);
return Stream.concat(worldlist.stream(), anylist.stream()).toList();
}

public List<String> getDisabledModesInTown(String town_name){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.towny.towns." + town_name);
return this.config.getStringList("overrides.towny.towns." + town_name);
}

public List<String> getDisabledModesInNation(String nation_name){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.towny.nations." + nation_name);
return this.config.getStringList("overrides.towny.nations." + nation_name);
}

public List<String> getDisabledModesInGPClaim(ClaimPermission perm){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.grief_prevention.claims." + perm.toString().toLowerCase());
return this.config.getStringList("overrides.grief_prevention.claims." + perm.toString().toLowerCase());
}

public List<String> getDisabledModesInOwnGPClaim(){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.grief_prevention.claims.own");
return this.config.getStringList("overrides.grief_prevention.claims.own");
}

public List<String> getDisabledModesInAnyGPClaim(){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.grief_prevention.claims.any");
return this.config.getStringList("overrides.grief_prevention.claims.any");
}

public List<String> getDisabledModesinAdminGPClaim(){
plugin.log(Level.FINE, "GetOverrideForMode->GetPath:" + "overrides.grief_prevention.claims.admin");
return this.config.getStringList("overrides.grief_prevention.claims.admin");
}

public boolean GetOverrideForMode(String mode, Player ply){

plugin.log(Level.FINE, ply, "GetOverrideForMode->Mode:" + mode);
Expand Down Expand Up @@ -455,7 +496,59 @@ public boolean GetOverrideForMode(String mode, Player ply){

}

plugin.log(Level.FINE, ply, "GetOverrideForMode->None");
// TODO Implement overrides for Grief Prevention!
if(config.getBoolean("overrides.grief_prevention.enabled") && plugin.checkDependency("GriefPrevention")){

plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention");

GriefPreventionApi gpApi = new GriefPreventionApi(ply);
Claim playerInClaim = gpApi.GetClaimAtPlayerPos(ply);

if(playerInClaim != null){

plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:OwnedBy:" + playerInClaim.getOwnerName());

if(getDisabledModesInGPClaim(ClaimPermission.Edit).contains(mode) && playerInClaim.hasExplicitPermission(ply, ClaimPermission.Edit) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Edit");
return true;
}
if(getDisabledModesInGPClaim(ClaimPermission.Build).contains(mode) && playerInClaim.hasExplicitPermission(ply, ClaimPermission.Build) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Build");
return true;
}
if(getDisabledModesInGPClaim(ClaimPermission.Inventory).contains(mode) && playerInClaim.hasExplicitPermission(ply, ClaimPermission.Inventory) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Inventory");
return true;
}
if(getDisabledModesInGPClaim(ClaimPermission.Access).contains(mode) && playerInClaim.hasExplicitPermission(ply, ClaimPermission.Access) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Access");
return true;
}
if(getDisabledModesInGPClaim(ClaimPermission.Manage).contains(mode) && playerInClaim.hasExplicitPermission(ply, ClaimPermission.Manage) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Manage");
return true;
}

if(getDisabledModesInOwnGPClaim().contains(mode) && playerInClaim.ownerID != null && playerInClaim.ownerID.equals(ply.getUniqueId()) ){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Owned");
return true;
}

if(getDisabledModesinAdminGPClaim().contains(mode) && playerInClaim.isAdminClaim()){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Admin");
return true;
}

if(getDisabledModesInAnyGPClaim().contains(mode)){
plugin.log(Level.FINE, ply, "GetOverrideForMode->GriefPrevention->Claim:Any");
return true;
}
}

}


plugin.log(Level.FINE, ply, "GetOverrideForMode->Finished (No Override Triggered)");
return false;

}
Expand Down
61 changes: 56 additions & 5 deletions src/main/java/dev/beeps/plugins/Commands/CmdMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

import java.util.*;

public class CmdMain implements CommandExecutor {

Expand All @@ -35,6 +35,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
case "info":
return sendPluginInfo(sender);

case "test":
return sendTestMessage(sender, command, label, args);

default:
sender.sendMessage(ChatColor.RED + "Invalid subcommand");

Expand All @@ -55,6 +58,10 @@ private boolean sendHelp(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.BLUE + "/bki info");
sender.sendMessage(ChatColor.AQUA + "Gets the current settings for BetterKeepInventory");

sender.sendMessage(ChatColor.GRAY + "");
sender.sendMessage(ChatColor.BLUE + "/bki test");
sender.sendMessage(ChatColor.AQUA + "Tests your location for overrides");

sender.sendMessage(ChatColor.GRAY + "");
sender.sendMessage(ChatColor.BLUE + "/bki reload");
sender.sendMessage(ChatColor.AQUA + "Reloads the plugin");
Expand Down Expand Up @@ -144,8 +151,7 @@ private boolean sendPluginInfo(CommandSender sender){

private boolean reload(CommandSender sender, Command command, String label, String[] args){

if (sender instanceof Player) {
Player ply = (Player) sender;
if (sender instanceof Player ply) {
if(!ply.hasPermission("betterkeepinventory.reload")){
sender.sendMessage(ChatColor.RED + "Missing permission.");
return true;
Expand All @@ -159,5 +165,50 @@ private boolean reload(CommandSender sender, Command command, String label, Stri
return true;
}

private boolean sendTestMessage(CommandSender sender, Command command, String label, String[] args){

if (sender instanceof Player ply) {
if(!ply.hasPermission("betterkeepinventory.test")){
sender.sendMessage(ChatColor.RED + "Missing permission.");
return true;
}

if(plugin.config.GetOverrideForMode("ALL", ply)){
ply.sendMessage(ChatColor.GREEN + "✔" + ChatColor.GRAY + " All modes are overridden.");
}else{

Map<String, Boolean> typeMap = new HashMap<String, Boolean>();
typeMap.put("ALL", plugin.config.GetOverrideForMode("ALL", ply));
typeMap.put("ITEMS", plugin.config.GetOverrideForMode("ITEMS", ply));
typeMap.put("ARMOR", plugin.config.GetOverrideForMode("ARMOR", ply));
typeMap.put("HOTBAR", plugin.config.GetOverrideForMode("HOTBAR", ply));
typeMap.put("INVENTORY", plugin.config.GetOverrideForMode("INVENTORY", ply));
typeMap.put("EXP", plugin.config.GetOverrideForMode("EXP", ply));
typeMap.put("HUNGER", plugin.config.GetOverrideForMode("HUNGER", ply));
typeMap.put("POTIONS", plugin.config.GetOverrideForMode("POTIONS", ply));
typeMap.put("ECO", plugin.config.GetOverrideForMode("ECO", ply));

StringBuilder mainResponse = new StringBuilder();
for(Map.Entry<String, Boolean> entry : typeMap.entrySet()){
mainResponse.append(entry.getValue() ? ChatColor.GREEN + "✔" : ChatColor.RED + "✖").append(entry.getKey()).append(ChatColor.GRAY).append(" | ");
}

ply.sendMessage(mainResponse.toString());
}

ply.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "Location tested only. Gamemode, Gamerule and Permission Bypasses were not checked.");

return true;

}

if(sender instanceof ConsoleCommandSender){
sender.sendMessage("This command can only be run by a player.");
return true;
}

return false;
}


}
30 changes: 30 additions & 0 deletions src/main/java/dev/beeps/plugins/Depends/GriefPreventionApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.beeps.plugins.Depends;

import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.ClaimPermission;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.entity.Player;

public class GriefPreventionApi {

private final GriefPrevention _api;

public GriefPreventionApi(Player ply){
_api = GriefPrevention.instance;
}

public Claim GetClaimAtPlayerPos(Player ply){
return _api.dataStore.getClaimAt(ply.getLocation(), false, null);
}

public boolean PlayerHasClaimPermission(Player ply, ClaimPermission permission) {
Claim claim = GetClaimAtPlayerPos(ply);
if(claim == null){
return false;
}

return claim.hasExplicitPermission(ply.getUniqueId(), permission);

}

}
19 changes: 19 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,23 @@ overrides:
- ITEMS
- HUNGER

grief_prevention:

enabled: false
claims:
own: # Claims owned by the user
- ALL
admin: # Admin claims
- NONE
edit: # Claims where the user has "edit" permission
- NONE
build: # Claims where the user has "build" permission
- NONE
inventory: # Claims where the user has "inventory" permission
- NONE
access: # Claims where the user has "access" permission
- NONE
manage: # Claims where the user has "manage" permission
- NONE
any: # Any claim
- NONE
8 changes: 6 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ prefix: BetterKeepInventory
authors: [ BeepSterr ]
website: beeps.dev

softdepend: [Vault,Towny,Essentials]
softdepend: [Vault,Towny,Essentials,GriefPrevention]

# AutoPlug support
# AutoPlug
spigot-id: 93081

permissions:

betterkeepinventory.test:
description: Test overrides at your location
default: false

betterkeepinventory.bypass:
description: Group node for bypassing all plugin functionality (revert to vanilla keepInventory)
default: false
Expand Down

0 comments on commit 1d49b12

Please sign in to comment.