Initial commit
This commit is contained in:
@@ -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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
@@ -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<Shop> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -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.
|
||||
*
|
||||
* <P>
|
||||
* 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.
|
||||
* </P>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
12
src/main/resources/config.yml
Normal file
12
src/main/resources/config.yml
Normal file
@@ -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
|
9
src/main/resources/plugin.yml
Normal file
9
src/main/resources/plugin.yml
Normal file
@@ -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
|
Reference in New Issue
Block a user