commit fcdd59efe34d346913645732e21f61fdb1298194 Author: BuildTools Date: Wed Dec 25 19:20:15 2019 +1000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..744289d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/target/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/GreifPreventionQuickShopBridge.iml b/.idea/GreifPreventionQuickShopBridge.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/.idea/GreifPreventionQuickShopBridge.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e6f67ef --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..af673e7 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..81d05a6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GriefPreventionQuickShopBridge.iml b/GriefPreventionQuickShopBridge.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/GriefPreventionQuickShopBridge.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fee7f9 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# GriefPreventionQuickShopBridge + +#####A Simple Addon that intergrates GriefPrevention claims in the plugin QuickShop. + +* Only allow QuickShop shop's to be created inside of grief prevention claims by the owner of the claim. +* Prevents QuickShop shop's from being created outside of grief prevention claims. +* Deletes QuickShop shop's when a grief prevention claim is deleted/removed or expires. +* By default, allows op to create QuickShop shop's anywhere. + + + + diff --git a/lib/QuickShop-Reremake.2.4.9.jar b/lib/QuickShop-Reremake.2.4.9.jar new file mode 100644 index 0000000..5b3b649 Binary files /dev/null and b/lib/QuickShop-Reremake.2.4.9.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3644cbc --- /dev/null +++ b/pom.xml @@ -0,0 +1,151 @@ + + + 4.0.0 + + com.github.judgetread + GriefPreventionQuickShopBridge + 1.0.0 + + + + GPL v3 License + http://www.gnu.org/licenses/ + repo + + + + com.github.judgetread.GriefPreventionQuickShopBridge + Judgetread + UTF-8 + + + https://github.com/${developer}/${name}/issues + GitHub Issues + + + + https://github.com/${developer}/${project.version} + scm:git:git://github.com/${developer}/${project.version}.git + scm:git:git@github.com:${developer}/${project.version}.git + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + UTF-8 + + + + + attach-javadocs + + jar + + + false + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + + + + + true + src/main/resources + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + vault-repo + https://jitpack.io + + + jitpack.io + https://jitpack.io + + + + + + org.spigotmc + spigot-api + 1.15-R0.1-SNAPSHOT + provided + + + com.github.MilkBowl + VaultAPI + 1.7 + provided + + + org.bukkit + bukkit + + + + + org.projectlombok + lombok + 1.18.10 + provided + + + org.jetbrains + annotations + 18.0.0 + provided + + + com.github.TechFortress + GriefPrevention + 16.7.1 + + + org.bukkit + bukkit + + + + + org.maxgamer + QuickShop + Reremake 2.4.9.1 + system + ${basedir}/lib/QuickShop-Reremake.2.4.9.jar + + + \ No newline at end of file diff --git a/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/GriefPreventionQuickShopBridge.java b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/GriefPreventionQuickShopBridge.java new file mode 100644 index 0000000..69037aa --- /dev/null +++ b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/GriefPreventionQuickShopBridge.java @@ -0,0 +1,145 @@ +package com.github.judgetread.GriefPreventionQuickShopBridge; + +import com.github.judgetread.GriefPreventionQuickShopBridge.listeners.GriefPreventionListener; +import com.github.judgetread.GriefPreventionQuickShopBridge.listeners.QuickShopListener; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.experimental.FieldDefaults; +import lombok.experimental.NonFinal; +import org.bukkit.Bukkit; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.time.Duration; +import java.time.Instant; + +@Getter(AccessLevel.PUBLIC) +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) +public class GriefPreventionQuickShopBridge extends JavaPlugin { + + /** + * The active instance of GriefPreventionQuickShopBridge + */ + private static GriefPreventionQuickShopBridge instance; + + /** + * The plugin GriefPrevention(null if not present) + */ + @Getter(AccessLevel.PUBLIC) + @Nullable + @NonFinal + private Plugin griefPrevention; + + /** + * The plugin QuickShop(null if not present) + */ + @Getter(AccessLevel.PUBLIC) + @Nullable + @NonFinal + private Plugin quickShop; + + + /** + * onLoad + */ + @Override + public void onLoad() { + instance = this; + } + + /** + * onEnable + */ + @Override + public void onEnable() { + Instant start = Instant.now(); + saveDefaultConfig(); + reloadConfig(); + startup(); + Bukkit.getConsoleSender().sendMessage(" Loaded! " + Duration.between(Instant.now(), start).toMillis() + "ms"); + } + + /** + * Reload this plugin. + */ + private void reload() { + Bukkit.getConsoleSender().sendMessage(" Reloading " + getName()); + unregisterListeners(); + unloadHooks(); + reloadConfig(); + startup(); + } + + /** + * Startup procedures. + */ + private void startup() { + loadHooks(); + registerListeners(); + } + + /** + * Register Listeners. + */ + private void registerListeners() { + Bukkit.getConsoleSender().sendMessage(" Registering Listeners..."); + Bukkit.getPluginManager().registerEvents(new GriefPreventionListener(this), this); + Bukkit.getPluginManager().registerEvents(new QuickShopListener(this), this); + } + + /** + * Unregister Listeners. + */ + private void unregisterListeners() { + Bukkit.getConsoleSender().sendMessage(" Unregistering Listeners..."); + HandlerList.unregisterAll(this); + } + + /** + * Reload config + */ + @SuppressWarnings("EmptyMethod") + @Override + public void reloadConfig() { + super.reloadConfig(); + } + + /** + * Load hooks. + */ + private void loadHooks() { + Bukkit.getConsoleSender().sendMessage(" Loading Hooks..."); + griefPrevention = hookPlugin(this.getName() + " GriefPrevention"); + quickShop = hookPlugin(this.getName() + " QuickShop"); + } + + /** + * Unload hooks + */ + private void unloadHooks() { + Bukkit.getConsoleSender().sendMessage(" Unloading Hooks..."); + this.griefPrevention = null; + this.quickShop = null; + } + + /** + * Get the plugin from plugin manager with the + * given name. + *

+ * Returns null, if none found. + * + * @param pluginName String name of the plugin. + * @return Plugin + */ + private @Nullable Plugin hookPlugin(@NotNull @NonNull String pluginName) { + @Nullable Plugin thirdPlugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (thirdPlugin != null) { + Bukkit.getConsoleSender().sendMessage(" Hooked: " + pluginName); + } + return thirdPlugin; + } +} diff --git a/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/GriefPreventionListener.java b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/GriefPreventionListener.java new file mode 100644 index 0000000..e79b266 --- /dev/null +++ b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/GriefPreventionListener.java @@ -0,0 +1,89 @@ +package com.github.judgetread.GriefPreventionQuickShopBridge.listeners; + +import com.github.judgetread.GriefPreventionQuickShopBridge.GriefPreventionQuickShopBridge; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.maxgamer.quickshop.Event.ShopPreCreateEvent; +import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.Shop.ContainerShop; +import org.maxgamer.quickshop.Shop.Shop; + +import java.util.Iterator; + +@AllArgsConstructor +public class GriefPreventionListener implements Listener { + + /** + * The instance of GriefPreventionQuickShopBridge + */ + @NonNull + private final GriefPreventionQuickShopBridge plugin; + + /** + * GriefPrevention Claim Delete Event + * + * @param event + */ + @EventHandler + public void onClaimDeleteEvent(ClaimDeletedEvent event) { + if(plugin.getConfig().getBoolean("delete-shops-when-claims-deleted", true)) { + deleteAllShopsInClaim(event.getClaim()); + } + } + + /** + * GriefPrevention Claim Expire Event + * + * @param event + */ + @EventHandler + public void onClaimExpireEvent(ClaimExpirationEvent event) { + if(plugin.getConfig().getBoolean("delete-shops-when-claims-expires", true)) { + deleteAllShopsInClaim(event.getClaim()); + } + } + + + /** + * Delete any shop found inside the claim. + * + * @param claim A GriefPrevention claim + */ + private void deleteAllShopsInClaim(final Claim claim) { + Iterator bIt = ((QuickShop) plugin.getQuickShop()).getShopManager().getShopIterator(); + + if (bIt == null) { + return; + } + + while (bIt.hasNext()) { + final Location loc = bIt.next().getLocation(); + + if (loc == null) { + continue; + } + + if (claim.contains(loc, false, false)) { + final ContainerShop shop = (ContainerShop) ((QuickShop) plugin.getQuickShop()).getShopManager().getShop(loc); + + if (shop == null) { + continue; + } + + // Try force saving of chunk ??? + loc.getChunk().addPluginChunkTicket(plugin); + shop.delete(false); + loc.getChunk().removePluginChunkTicket(plugin); + } + + } + + } + +} diff --git a/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/QuickShopListener.java b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/QuickShopListener.java new file mode 100644 index 0000000..45b9828 --- /dev/null +++ b/src/main/java/com/github/judgetread/GriefPreventionQuickShopBridge/listeners/QuickShopListener.java @@ -0,0 +1,68 @@ +package com.github.judgetread.GriefPreventionQuickShopBridge.listeners; + +import com.github.judgetread.GriefPreventionQuickShopBridge.GriefPreventionQuickShopBridge; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.GriefPrevention; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.maxgamer.quickshop.Event.ShopPreCreateEvent; + +import java.util.Optional; + +@AllArgsConstructor +public final class QuickShopListener implements Listener { + + /** + * The instance of GriefPreventionQuickShopBridge + */ + @NonNull + private final GriefPreventionQuickShopBridge plugin; + + /** + * QuickShop Remake ShopPreCreateEvent. + * + *

+ * Check the location of when the shop is goinf to be placed, + * and if the shops location is not inside a claim cancel the shop creation. + * + * If the shops location is inside a claim, check that the player making the + * shop is the same player that owns the claim, if not cancel the shop creation. + *

+ * + * @param event QuickShop ShopPreCreateEvent + */ + @EventHandler(priority = EventPriority.HIGH) + public final void onPreShopEvent(@NonNull ShopPreCreateEvent event) { + + if (event.isCancelled()) { + return; + } + + final Location location = event.getLocation(); + final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null); + final Player player = event.getPlayer(); + + if(plugin.getConfig().getBoolean("op-bypass-claim-checks", true) && player.isOp()){ + return; + } + + if(claim == null){ + event.setCancelled(true); + return; + } + + if(plugin.getConfig().getBoolean("only-claim-owner-can-create-shops", true) && !claim.ownerID.toString().equals(player.getUniqueId().toString())){ + event.setCancelled(true); + return; + } + + + + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..ea85155 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,12 @@ +# Only allow shops to be created in claims that player is owner of. +# --> If false anyone can create a shop in the any claim. +only-claim-owner-can-create-shops: true + +# Ignore claim checks if player is op, allows op to create shop anywhere. +op-bypass-claim-checks: true + +# Delete shops inside a claim if that claim is deleted/removed +delete-shops-when-claims-deleted: true + +# Delete shops inside a claim if that claim expires +delete-shops-when-claims-expires: true \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..1ee1269 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +name: ${name} +main: ${package}.${name} +version: ${project.version} +authors: [Judgetread] + +description: QuickShop Reremake GriefPrevtion Bridge +softdepend: [GriefPrevention, QuickShop] + +api-version: 1.13 \ No newline at end of file