Skip to content

Commit

Permalink
Set grief prevention as soft dependency again
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Apr 6, 2021
1 parent 31ae2ea commit 29cdcca
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 189 deletions.
36 changes: 36 additions & 0 deletions src/me/aleksilassila/islands/GPWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.aleksilassila.islands;

import me.ryanhamshire.GriefPrevention.ClaimsMode;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit;
import org.bukkit.World;

import java.util.concurrent.ConcurrentHashMap;

public class GPWrapper {
public static boolean enabled = false;
public static GriefPrevention gp;

private static Islands islands;

public static void initialise() {
islands = Islands.instance;
enabled = islands.getConfig().getBoolean("enableIslandProtection", true);
if (!enabled) return;
if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) {
islands.getLogger().severe("No GriefPrevention found. Island protection disabled.");
enabled = false;
} else {
gp = (GriefPrevention) Bukkit.getPluginManager().getPlugin("GriefPrevention");
}

if (enabled && islands.getConfig().getBoolean("overrideGriefPreventionWorlds")) {
ConcurrentHashMap<World, ClaimsMode> modes = gp.config_claims_worldModes;

modes.put(Islands.islandsWorld, ClaimsMode.SurvivalRequiringClaims);

if (Islands.wildernessWorld != null)
modes.put(Islands.wildernessWorld, ClaimsMode.Survival);
}
}
}
42 changes: 15 additions & 27 deletions src/me/aleksilassila/islands/Islands.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class Islands extends JavaPlugin {
public static World islandsSourceWorld;
public static World wildernessWorld;

public static GriefPrevention gp;
public static boolean gpEnabled = true;

private FileConfiguration biomesCache;
private File biomesCacheFile;

Expand All @@ -57,14 +54,6 @@ public class Islands extends JavaPlugin {
public void onEnable() {
instance = this;

gpEnabled = getConfig().getBoolean("enableIslandProtection", true);
if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) {
getLogger().severe("No GriefPrevention found. Island protection disabled.");
gpEnabled = false;
} else {
gp = (GriefPrevention) Bukkit.getPluginManager().getPlugin("GriefPrevention");
}

if (!setupEconomy()) {
getLogger().severe("No Vault or economy plugin found. Economy disabled.");
}
Expand Down Expand Up @@ -107,17 +96,6 @@ public void onEnable() {
wildernessWorld = getWilderness();
}

if (gpEnabled && getConfig().getBoolean("overrideGriefPreventionWorlds")) {
ConcurrentHashMap<World, ClaimsMode> modes = gp.config_claims_worldModes;

modes.put(islandsWorld, gpEnabled ? ClaimsMode.SurvivalRequiringClaims : ClaimsMode.Survival);

if (wildernessWorld != null)
modes.put(wildernessWorld, ClaimsMode.Survival);
}

new ConfigMigrator();

// ISLANDS
Messages.init();

Expand All @@ -126,19 +104,29 @@ public void onEnable() {

definedIslandSizes = setupSizes();

new IslandCommands();

new Listeners();

int pluginId = 8974;
new Metrics(this, pluginId);

getLogger().info("Islands enabled!");

Bukkit.getScheduler().scheduleSyncDelayedTask(this, this::initialise);

// Save island configuration every 5 minutes
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, IslandsConfig::updateEntries, 20 * 60 * 5, 20 * 60 * 5);
}

// This will be ran when all the plugins are loaded.
public void initialise() {
getLogger().info("Initialising commands and configuration");
GPWrapper.initialise();

// Init islands config
IslandsConfig.getConfig();

new IslandCommands();
new Listeners();
}

@Override
public void onDisable() {
IslandsConfig.updateEntries();
Expand Down Expand Up @@ -192,7 +180,7 @@ && getConfig().getStringList("excludeShapes").contains(biome.name())) {
island.size = islandSize;
island.height = height;
island.biome = biome;
if (gpEnabled)
if (GPWrapper.enabled)
island.resizeClaim(islandSize);
island.shouldUpdate = true;

Expand Down
26 changes: 13 additions & 13 deletions src/me/aleksilassila/islands/IslandsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public Entry(String islandId) {

this.claimId = fc.getLong(islandId + ".claimId", -1);

if (this.claimId == -1 && Islands.gpEnabled) {
if (this.claimId == -1 && GPWrapper.enabled) {
deleteClaims();
this.claimId = createClaims(xIndex, zIndex, size, uuid);
this.shouldUpdate = true;
Expand All @@ -386,7 +386,7 @@ public Entry(int xIndex, int zIndex, int size, int height, UUID uuid, String nam
this.biome = biome;
this.homeId = getNewHomeId(uuid);

this.claimId = Islands.gpEnabled ? createClaims(xIndex, zIndex, size, uuid) : -1;
this.claimId = GPWrapper.enabled ? createClaims(xIndex, zIndex, size, uuid) : -1;

int[][] ic = getIslandCorner(xIndex, zIndex, size);
this.spawnPosition = new int[] {
Expand All @@ -403,7 +403,7 @@ public Entry(int xIndex, int zIndex, int size, int height, UUID uuid, String nam

public void delete() {
getConfig().set(islandId, null);
if (Islands.gpEnabled)
if (GPWrapper.enabled)
deleteClaims();
entries.remove(islandId);

Expand Down Expand Up @@ -469,7 +469,7 @@ public void nameIsland(String name) {
public void giveIsland(OfflinePlayer player) {
this.uuid = player.getUniqueId();
this.homeId = getNewHomeId(player.getUniqueId());
if (Islands.gpEnabled) {
if (GPWrapper.enabled) {
deleteClaims();
this.claimId = createClaims(xIndex, zIndex, size, player.getUniqueId());
}
Expand All @@ -480,7 +480,7 @@ public void giveIsland(OfflinePlayer player) {
public void giveToServer() {
this.uuid = null;
this.homeId = -1;
if (Islands.gpEnabled) {
if (GPWrapper.enabled) {
deleteClaims();
this.claimId = createClaims(xIndex, zIndex, size, null);
}
Expand All @@ -498,20 +498,20 @@ public void setSpawnIsland() {
public void resizeClaim(int islandSize) {
int[][] ic = getIslandCorner(xIndex, zIndex, islandSize);

Claim c = Islands.gp.dataStore.getClaimAt(new Location(
Claim c = GPWrapper.gp.dataStore.getClaimAt(new Location(
Islands.islandsWorld,
spawnPosition[0],
50,
spawnPosition[1]), true, false, null);
Islands.gp.dataStore.resizeClaim(c,
GPWrapper.gp.dataStore.resizeClaim(c,
ic[0][0], ic[1][0],
0, 255,
ic[0][1], ic[1][1], Bukkit.getPlayer(uuid));
}

private static long createClaims(int xIndex, int zIndex, int size, UUID uuid) {
int[][] ipc = getIslandPlotCorner(xIndex, zIndex);
CreateClaimResult r = Islands.gp.dataStore.createClaim(Islands.islandsWorld,
CreateClaimResult r = GPWrapper.gp.dataStore.createClaim(Islands.islandsWorld,
ipc[0][0], ipc[1][0],
0, 255,
ipc[0][1], ipc[1][1],
Expand All @@ -522,7 +522,7 @@ private static long createClaims(int xIndex, int zIndex, int size, UUID uuid) {
int[][] ic = getIslandCorner(xIndex, zIndex, size);


Claim subClaim = Islands.gp.dataStore.createClaim(Islands.islandsWorld,
Claim subClaim = GPWrapper.gp.dataStore.createClaim(Islands.islandsWorld,
ic[0][0], ic[1][0],
0, 255,
ic[0][1], ic[1][1],
Expand Down Expand Up @@ -550,20 +550,20 @@ private static long createClaims(int xIndex, int zIndex, int size, UUID uuid) {
private static void addClaimManager(Claim claim, String uuid) {
if (!claim.managers.contains(uuid)) {
claim.managers.add(uuid);
Islands.gp.dataStore.saveClaim(claim);
GPWrapper.gp.dataStore.saveClaim(claim);
}
}

private void deleteClaims() {
Claim c = Islands.gp.dataStore.getClaim(this.claimId);
Claim c = GPWrapper.gp.dataStore.getClaim(this.claimId);

if (c == null) {
int[][] ic = getIslandCorner(xIndex, zIndex, size);
c = Islands.gp.dataStore.getClaimAt(new Location(Islands.islandsWorld, ic[0][0], 50, ic[0][1]), true, true, null);
c = GPWrapper.gp.dataStore.getClaimAt(new Location(Islands.islandsWorld, ic[0][0], 50, ic[0][1]), true, true, null);
}

if (c != null) {
Islands.gp.dataStore.deleteClaim(c);
GPWrapper.gp.dataStore.deleteClaim(c);
}
this.claimId = -1;
}
Expand Down
49 changes: 0 additions & 49 deletions src/me/aleksilassila/islands/utils/ConfigMigrator.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ error.NOT_ON_ISLAND=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cYou have to be on
error.NO_LOCATIONS_FOR_BIOME=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cNo available locations for specified biome.
error.ISLAND_NOT_FOUND=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7c404 - Island not found.
error.HOME_NOT_FOUND=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7c404 - Home not found :(
error.NOT_TRUSTED=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cYou need owner's permission to interact here.
error.INVALID_ISLAND_SIZE=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cIsland size exceeds limits.
error.NO_WORLDEDIT=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cNo WorldEdit found.
error.ERROR=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cAn internal error occurred. Contact staff.
Expand All @@ -28,8 +27,6 @@ error.PRIVATE_ISLAND=\u00a77[\u00a74\u00a7lError\u00a77] \u00a7cYou can't check
success.DELETED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aIsland deleted successfully. It will be overwritten when someone creates a new island.
success.UNNAMED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aIsland unnamed and made private.
success.UNTRUSTED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aPlayer untrusted!
success.TRUSTED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aPlayer trusted!
success.SPAWN_POINT_CHANGED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aIsland spawn point changed.
success.OWNER_REMOVED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aIsland owner removed.
success.SPAWN_ISLAND_CHANGED=\u00a77[\u00a72\u00a7lIslands\u00a77] \u00a7aGlobal spawn island changed.
Expand All @@ -54,9 +51,6 @@ info.CLEAR_CONFIRM=\u00a7cThis command will completely erase and delete the curr
info.ON_SURFACE=\u00a77You can only use this command on surface.
info.IN_OVERWORLD=\u00a77You can only use this command in overworld.
info.VERSION_INFO=\u00a77Islands {0}
info.TRUSTED_INFO=\u00a77[\u00a72\u00a7lIslands\u00a77] You have trusted {0} player(s).
info.TRUSTED_PLAYER=\u00a77 - {0}
info.TRUSTED_PLAYER_INFO=\u00a77 + {0}: {1, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
info.GENERATION_STARTED=\u00a77[\u00a72\u00a7lGeneration\u00a77] Your generation event has been started.
info.QUEUE_STATUS=\u00a77[\u00a72\u00a7lGeneration\u00a77] Your event has been added to the queue. There are {0} event(s) in queue before yours.
info.GENERATION_STATUS=\u00a77[\u00a72\u00a7lGeneration\u00a77] Your generation event is {0}% completed.
Expand All @@ -79,8 +73,6 @@ info.ISLAND_INFO_TRUSTED_PLAYER=\u00a77 + \u00a76{0}\u00a76 ({1})
info.AVAILABLE_SUBCOMMANDS=\u00a7fHere's a list of subcommands you have access to:
info.AVAILABLE_SUBCOMMAND=\u00a77 - \u00a7f\u00a7l{0}\u00a7r\u00a77: {1}

usage.TRUST=\u00a77Usage: /trust <player> (You have to be on target island)
usage.UNTRUST=\u00a77Usage: /untrust <player> (You have to be on target island)
usage.CREATE=\u00a77Usage: /island create <biome> (<SIZE>)
usage.RECREATE=\u00a77Usage: /island recreate <biome> (<SIZE>) (You have to be on target island)
usage.NAME=\u00a77Usage: /island name <name> (You have to be on target island)
Expand Down Expand Up @@ -121,46 +113,6 @@ gui.admin.PLAYER_LORE=\u00a77{0} island(s)
gui.admin.ISLAND_NAME=\u00a76\u00a7l{0}
gui.admin.ISLAND_LORE=\u00a77Island id: {0}

gui.trust.TITLE=\u00a76\u00a7lIsland Settings
gui.trust.GLOBAL_RULES_BUTTON=\u00a76\u00a7lIsland Protection
gui.trust.GLOBAL_RULES_LORE=\u00a77Configure how your island is accessible\n\u00a77to other players
gui.trust.TRUSTED_PLAYERS_BUTTON=\u00a76\u00a7lManage trusted players
gui.trust.TRUSTED_PLAYERS_LORE=\u00a77Manage trusted players\' permissions\n\u00a77and restrictions
gui.trust.global.TITLE=\u00a76\u00a7lIsland Protection
gui.trust.global.BUILDING=\u00a76\u00a7lBuild Protection
gui.trust.global.BUILDING_LORE=\u00a77Block / allow players to interact with your island\n\
\u00a77in all ways. Disable if you want to create a sandbox\n\
\u00a77island or use other protection plugin for this island.\n\n\
\u00a77Protect building: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.global.CHESTS=\u00a76\u00a7lContainer Protection
gui.trust.global.CHESTS_LORE=\u00a77Block / allow players to access chests and containers\n\
\u00a77on your island.\n\n\u00a77Protect Chests: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.global.DOORS=\u00a76\u00a7lDoor & Button Protection
gui.trust.global.DOORS_LORE=\u00a77Block / allow players to interact with doors, trapdoors, \n\
\u00a77gates, buttons, levers etc.\n\n\u00a77Lock Doors & Gates: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.global.UTILITY=\u00a76\u00a7lUtility Protection
gui.trust.global.UTILITY_LORE=\u00a77Block / allow players to use utility such as crafting tables,\n\
\u00a77enchanting tables and anvils.\n\n\u00a77Allow Utility Usage: {0, choice, 0#\u00a7cTrue|1#\u00a7aFalse}
gui.trust.players.TITLE=\u00a76\u00a7lManage Trusted Players
gui.trust.players.PLAYER=\u00a76\u00a7l{0}
gui.trust.players.PLAYER_LORE=\u00a77Manage {0}\'s permissions.\n\u00a77Shift + Click to untrust.
gui.trust.player.TITLE=\u00a76\u00a7l{0}
gui.trust.player.BUILDING=\u00a76\u00a7lAllow Building
gui.trust.player.BUILDING_LORE=\u00a77Allow / disallow any kind of interaction with this island.\n\n\
\u00a77Building enabled: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.player.CHESTS=\u00a76\u00a7lAccess Containers
gui.trust.player.CHESTS_LORE=\u00a77Allow / disallow access to chests and containers.\n\n\
\u00a77Container access: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.player.DOORS=\u00a76\u00a7lAccess Doors & Gates
gui.trust.player.DOORS_LORE=\u00a77Allow / disallow access to doors, trapdoors, \n\
\u00a77gates, buttons, levers etc.\n\n\u00a77Door access: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.trust.player.UTILITY=\u00a76\u00a7lAccess Utility
gui.trust.player.UTILITY_LORE=\u00a77Allow / Disallow access to utility such as crafting tables,\n\
\u00a77enchanting tables and anvils.\n\n\u00a77Utility access: {0, choice, 0#\u00a7cFalse|1#\u00a7aTrue}
gui.BACK=\u00a76\u00a7lBack
gui.NEXT_PAGE=\u00a76\u00a7lNext page
gui.PREVIOUS_PAGE=\u00a76\u00a7lPrevious page
Loading

0 comments on commit 29cdcca

Please sign in to comment.