Skip to content

Commit

Permalink
add module griefdefender
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdg6 committed Jan 26, 2023
1 parent 1b92960 commit 136d538
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 28 deletions.
43 changes: 43 additions & 0 deletions Cartographer2_Modules/GriefDefender/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id 'java-library'
}

repositories {
maven { url = uri('https://repo.glaremasters.me/repository/bloodshot/') }
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT'
compileOnly 'com.griefdefender:api:2.1.0-SNAPSHOT'
compileOnly project(':cartographer2_api')
}

description = 'cartographer2_modulegriefdefender'
def moduleVersion = '1.0.0'
version = moduleVersion


processResources {
filesMatching(['module.json']) {
expand version: moduleVersion
}
}

tasks.withType(Jar) {
destinationDirectory = file("$rootDir/Cartographer2/Addons")
}

jar {
archiveBaseName = 'GriefDefender-Addon'
version = moduleVersion
manifest {
attributes(
'Version': moduleVersion,
'Created-By': "Gradle ${gradle.gradleVersion}",
'Build-Jdk': "${System.properties['java.version']} " +
"(${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS': "${System.properties['os.name']} ${System.properties['os.arch']} " +
"${System.properties['os.version']}"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.github.bananapuncher714.cartographer.module.griefdefender;

import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.Tristate;
import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.TrustTypes;
import com.griefdefender.lib.flowpowered.math.vector.Vector3i;
import io.github.bananapuncher714.cartographer.core.api.WorldPixel;
import io.github.bananapuncher714.cartographer.core.api.map.WorldPixelProvider;
import io.github.bananapuncher714.cartographer.core.map.MapViewer;
import io.github.bananapuncher714.cartographer.core.map.Minimap;
import io.github.bananapuncher714.cartographer.core.renderer.PlayerSetting;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.awt.*;
import java.util.List;
import java.util.*;

public class ClaimBorderShader implements WorldPixelProvider{
protected GriefDefenderModule module;
public ClaimBorderShader(GriefDefenderModule module) { this.module = module; }

@Override
public Collection< WorldPixel > getWorldPixels(Player player, Minimap map, PlayerSetting setting) {
Set< WorldPixel > pixels = new HashSet<>();
MapViewer viewer = module.getCartographer().getPlayerManager().getViewerFor(setting.getUUID());
if (viewer.getSetting(GriefDefenderModule.GRIEFDEFENDER_CLAIMS)) {
List<Claim> claims = GriefDefender.getCore().getAllClaims();
for (Claim claim : claims) {
Optional<Color> optionalColor = module.getPublicColor();
if(claim.getUserTrusts().contains(player.getUniqueId())) {
if (claim.isUserTrusted(player.getUniqueId(), TrustTypes.ACCESSOR)) optionalColor = module.getAccessorColor();
else if (claim.isUserTrusted(player.getUniqueId(), TrustTypes.MANAGER)) optionalColor = module.getManagerColor();
else if (claim.isUserTrusted(player.getUniqueId(), TrustTypes.BUILDER)) optionalColor = module.getBuilderColor();
else if (claim.isUserTrusted(player.getUniqueId(), TrustTypes.CONTAINER)) optionalColor = module.getContainerColor();
else if (claim.isUserTrusted(player.getUniqueId(), TrustTypes.RESIDENT)) optionalColor = module.getResidentColor();
} else if (claim.getOwnerUniqueId().equals(player.getUniqueId())) {
optionalColor = module.getOwnerColor();
} else if (claim.getFlagPermissionValue(GriefDefenderModule.CARTOGRAPHER_PUBLIC_SHOW, null) == Tristate.FALSE) {
continue;
}


if (optionalColor.isPresent()) {
Color color = optionalColor.get();
Vector3i minCorner = claim.getLesserBoundaryCorner();
World world = Bukkit.getWorld(claim.getWorldUniqueId());
int pixelWidth = setting.getScale() < 1 ? 2 : 1;
// Width = x / Length = z
double thickness = Math.min(setting.getScale(), claim.getWidth()) * pixelWidth;
double thicknessHeight = Math.min( setting.getScale(), claim.getLength()) * pixelWidth;

WorldPixel north = new WorldPixel(world, minCorner.getX(), minCorner.getZ(), color);
north.setWidth(claim.getWidth());
north.setHeight(thicknessHeight);
pixels.add(north);

WorldPixel south = new WorldPixel(world, minCorner.getX(), minCorner.getZ() + claim.getLength() - thicknessHeight, color);
south.setWidth(claim.getWidth());
south.setHeight(thicknessHeight);
pixels.add(south);

WorldPixel west = new WorldPixel(world, minCorner.getX(), minCorner.getZ(), color);
west.setWidth(thickness);
west.setHeight(claim.getLength());
pixels.add(west);

WorldPixel east = new WorldPixel(world, minCorner.getX() + claim.getWidth() - thickness, minCorner.getZ(), color);
east.setWidth(thickness);
east.setHeight(claim.getLength());
pixels.add(east);
}
}
}
return pixels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package io.github.bananapuncher714.cartographer.module.griefdefender;

import com.griefdefender.api.permission.flag.Flag;
import io.github.bananapuncher714.cartographer.core.api.events.minimap.MinimapLoadEvent;
import io.github.bananapuncher714.cartographer.core.api.setting.SettingState;
import io.github.bananapuncher714.cartographer.core.api.setting.SettingStateBoolean;
import io.github.bananapuncher714.cartographer.core.map.Minimap;
import io.github.bananapuncher714.cartographer.core.map.palette.PaletteManager;
import io.github.bananapuncher714.cartographer.core.module.Module;
import io.github.bananapuncher714.cartographer.core.util.FileUtil;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.awt.*;
import java.io.File;
import java.util.Optional;

public class GriefDefenderModule extends Module implements Listener {
public static final SettingStateBoolean GRIEFDEFENDER_CLAIMS = SettingStateBoolean.of( "griefdefender_show_claims", false, true );
public static Flag CARTOGRAPHER_PUBLIC_SHOW;

protected Optional<Color> owner, none, accessor, resident, container, builder, manager;


@Override
public void onEnable() {
registerSettings();

FileUtil.saveToFile( getResource( "config.yml" ), new File( getDataFolder(), "/config.yml" ), false );
FileUtil.saveToFile( getResource( "README.md" ), new File( getDataFolder(), "/README.md" ), false );

loadConfig();

for ( Minimap minimap : getCartographer().getMapManager().getMinimaps().values() ) {
init( minimap );
}

registerListener( this );

CARTOGRAPHER_PUBLIC_SHOW = Flag.builder()
.id("cartographer:show_to_public")
.name("cartographer-public")
.permission("griefdefender.flag.cartographer.public")
.build();
}

@Override
public SettingState< ? >[] getSettingStates() {
return new SettingState< ? >[] {
GRIEFDEFENDER_CLAIMS
};
}

@EventHandler
private void onEvent( MinimapLoadEvent event ) {
init( event.getMinimap() );
}

private void init( Minimap minimap ) {
minimap.register( new ClaimBorderShader( this ) );
}

private void loadConfig() {
owner = Optional.empty();

FileConfiguration config = YamlConfiguration.loadConfiguration( new File( getDataFolder(), "config.yml" ) );
ConfigurationSection section = config.getConfigurationSection( "colors" );

if ( section == null ) {
getLogger().warning( "No 'colors' section found!" );
} else {
owner = PaletteManager.fromString(section.getString("owner", ""));
none = PaletteManager.fromString(section.getString("public", ""));
accessor = PaletteManager.fromString(section.getString("accessor", ""));
resident = PaletteManager.fromString(section.getString("resident", ""));
container = PaletteManager.fromString(section.getString("container", ""));
builder = PaletteManager.fromString(section.getString("builder", ""));
manager = PaletteManager.fromString(section.getString("manager", ""));
}
}

public Optional<Color> getOwnerColor() {
return owner;
}
public Optional<Color> getPublicColor() {
return none;
}
public Optional<Color> getAccessorColor() {
return accessor;
}
public Optional<Color> getResidentColor() {
return resident;
}
public Optional<Color> getContainerColor() {
return container;
}
public Optional<Color> getBuilderColor() {
return builder;
}
public Optional<Color> getManagerColor() {
return manager;
}
}
10 changes: 10 additions & 0 deletions Cartographer2_Modules/GriefDefender/src/main/resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GriefDefender Addon for Cartographer2
- Adds outlines for claims

### Settings
Adds 1 Cartographer2 settings:
- `griefdefender_show_claims` - Show the claim outlines

Adds 1 GriefDefender Flags:
- `cartographer-public`(Permission: `griefdefender.flag.cartographer.public`)
Used to set if claim will show to public on Cartographer maps. (Default: true)
18 changes: 18 additions & 0 deletions Cartographer2_Modules/GriefDefender/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## GriefDefender Module for Cartographer 2

# Colors for claims
colors:

# what color show to public default
# default: #a2c4c9(medium light shade of cyan)
public: "#a2c4c9"
# The color of claims that are owned by the player
# Default: #ff0000(Red)
owner: "#ff0000"
# The colors of each claim, depending on what trust are set for the player
# #e6b8af(Orange) | #6aa84f(Green) | #8e7cc3(purpler) | #274e13(dark green)
accessor: "#e6b8af"
resident: "#6aa84f"
container: "#8e7cc3"
builder: "#274e13"
manager: "#ff0000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "GriefDefender",
"main": "io.github.bananapuncher714.cartographer.module.griefdefender.GriefDefenderModule",
"description": "Adds Cartographer2 integration with GriefDefender",
"version": "${version}",
"author": "BananaPuncher714",
"website": "aaaaahhhhhhh.com",
"depend": [ "GriefDefender" ]
}
58 changes: 30 additions & 28 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,44 @@ include(':cartographer2_v1_19_r2')

// Modules

include(':cartographer2_modulelands')
include(':cartographer2_modulegriefprevention')
include(':cartographer2_moduleexperimental')
include(':cartographer2_moduleresidence')
include(':cartographer2_moduleworldviewer')
include(':cartographer2_moduletowny')
include(':cartographer2_moduleguilds')
include(':cartographer2_modulevanilla')
include(':cartographer2_modulefactionsuuid')
include(':module_lands')
include(':module_griefprevention')
include(':module_experimental')
include(':module_residence')
include(':module_worldviewer')
include(':module_towny')
include(':module_guilds')
include(':module_vanilla')
include(':module_factionsuuid')
include(':module_griefdefender')

/*
include(':cartographer2_moduleworldguard')
include(':cartographer2_moduleworldguard_v6')
include(':cartographer2_moduleworldguard_v7')
include(':cartographer2_moduleworldguard_master')
include(':cartographer2_moduleworldguard_api')
include(':module_worldguard')
include(':module_worldguard_v6')
include(':module_worldguard_v7')
include(':module_worldguard_master')
include(':module_worldguard_api')
*/

// Project Dir

project(":cartographer2_moduletowny").projectDir = file('Cartographer2_Modules/Towny')
project(":cartographer2_moduleguilds").projectDir = file('Cartographer2_Modules/Guilds')
project(":cartographer2_modulevanilla").projectDir = file('Cartographer2_Modules/Vanilla')
project(":cartographer2_modulefactionsuuid").projectDir = file('Cartographer2_Modules/FactionsUUID')
project(":cartographer2_moduleresidence").projectDir = file('Cartographer2_Modules/Residence')
project(":cartographer2_modulelands").projectDir = file('Cartographer2_Modules/Lands')
project(":cartographer2_modulegriefprevention").projectDir = file('Cartographer2_Modules/GriefPrevention')
project(":cartographer2_moduleexperimental").projectDir = file('Cartographer2_Modules/Experimental')
project(":cartographer2_moduleworldviewer").projectDir = file('Cartographer2_Modules/WorldViewer')
project(":module_towny").projectDir = file('Cartographer2_Modules/Towny')
project(":module_guilds").projectDir = file('Cartographer2_Modules/Guilds')
project(":module_vanilla").projectDir = file('Cartographer2_Modules/Vanilla')
project(":module_factionsuuid").projectDir = file('Cartographer2_Modules/FactionsUUID')
project(":module_residence").projectDir = file('Cartographer2_Modules/Residence')
project(":module_lands").projectDir = file('Cartographer2_Modules/Lands')
project(":module_griefprevention").projectDir = file('Cartographer2_Modules/GriefPrevention')
project(":module_experimental").projectDir = file('Cartographer2_Modules/Experimental')
project(":module_worldviewer").projectDir = file('Cartographer2_Modules/WorldViewer')
project(":module_griefdefender").projectDir = file('Cartographer2_Modules/GriefDefender')

/*
project(":cartographer2_moduleworldguard").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard')
project(":cartographer2_moduleworldguard_v7").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_v7')
project(":cartographer2_moduleworldguard_v6").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_v6')
project(":cartographer2_moduleworldguard_master").projectDir = file('Cartographer2_Modules/WorldGuard_Master')
project(":cartographer2_moduleworldguard_api").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_API')
project(":module_worldguard").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard')
project(":module_worldguard_v7").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_v7')
project(":module_worldguard_v6").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_v6')
project(":module_worldguard_master").projectDir = file('Cartographer2_Modules/WorldGuard_Master')
project(":module_worldguard_api").projectDir = file('Cartographer2_Modules/WorldGuard_Master/Cartographer2_ModuleWorldGuard_API')
*/

project(":cartographer2_v1_8_r3").projectDir = file('Cartographer2_NMS/v1_8_R3')
Expand Down

0 comments on commit 136d538

Please sign in to comment.