forked from BananaPuncher714/Cartographer2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
295 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']}" | ||
) | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
.../java/io/github/bananapuncher714/cartographer/module/griefdefender/ClaimBorderShader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...ava/io/github/bananapuncher714/cartographer/module/griefdefender/GriefDefenderModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
Cartographer2_Modules/GriefDefender/src/main/resources/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
Cartographer2_Modules/GriefDefender/src/main/resources/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
9 changes: 9 additions & 0 deletions
9
Cartographer2_Modules/GriefDefender/src/main/resources/module.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters