mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Add AreaShop support and special-region-only settings.
Former-commit-id: 750e46c1089982b34e1e45a3d11347362b3caee5 [formerly 18e0203056327353b0df150ef5698514bd81308a] Former-commit-id: 84ef8cca17e2170a46f33f2ff9776d7264e1bb58
This commit is contained in:
1 parent
b193649f4f
commit
b4926ca05f
13 files changed
+132
-54
No files matched your search
@@ -359,7 +359,7 @@ public class QS implements CommandExecutor {
|
||||
|
||||
while (bIt.hasNext()) {
|
||||
Block b = bIt.next();
|
||||
if (Util.canBeShop(b)) {
|
||||
if (Util.canBeShop(b,null,true)) {
|
||||
if (p != null && b != null && p.isOnline()) {
|
||||
BlockBreakEvent be = new BlockBreakEvent(b, p);
|
||||
Bukkit.getPluginManager().callEvent(be);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.maxgamer.quickshop.Util.*;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
|
||||
|
||||
public class AreaShopListener implements Listener {
|
||||
QuickShop plugin = QuickShop.instance;
|
||||
|
||||
@EventHandler
|
||||
public void unRentedArea(UnrentedRegionEvent e) {
|
||||
Vector areaMaxVector = e.getRegion().getMaximumPoint();
|
||||
Vector areaMinVector = e.getRegion().getMinimumPoint();
|
||||
int minX = areaMinVector.getBlockX();
|
||||
int maxX = areaMaxVector.getBlockX();
|
||||
int minY = areaMinVector.getBlockY();
|
||||
int maxY = areaMaxVector.getBlockY();
|
||||
int minZ = areaMinVector.getBlockZ();
|
||||
int maxZ = areaMaxVector.getBlockZ();
|
||||
Iterator<Shop> shops = plugin.getShopManager().getShopIterator();
|
||||
while (shops.hasNext()) {
|
||||
Shop shop = shops.next();
|
||||
if(shop.getLocation().getWorld().getName()==e.getRegion().getWorld().getName()) {
|
||||
int bX = shop.getLocation().getBlockX();
|
||||
int bY = shop.getLocation().getBlockY();
|
||||
int bZ = shop.getLocation().getBlockZ();
|
||||
if(bX>=minX && bX<=maxX) {
|
||||
if(bY>=minY && bY<=maxY) {
|
||||
if(bZ>=minZ && bZ<=maxZ) {
|
||||
//In region, we need remove that shop.
|
||||
Util.debugLog("Removed shop at:["+shop.getLocation().toString()+"] cause AreaShop region unrented!");
|
||||
shop.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
Player p = e.getPlayer();
|
||||
// If the shop was a chest
|
||||
if (Util.canBeShop(b)) {
|
||||
if (Util.canBeShop(b,null,true)) {
|
||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||
if (shop == null)
|
||||
return;
|
||||
@@ -261,7 +261,7 @@ public class BlockListener implements Listener {
|
||||
|
||||
for (Block oBlock : event.getBlocks()) {
|
||||
Block otherBlock = oBlock.getRelative(event.getDirection()).getRelative(BlockFace.DOWN);
|
||||
if (Util.canBeShop(otherBlock)) {
|
||||
if (Util.canBeShop(otherBlock,null,true)) {
|
||||
shop = plugin.getShopManager().getShop(otherBlock.getLocation());
|
||||
if (shop!=null) {
|
||||
event.setCancelled(true);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class LockListener implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return; // Didn't right click it, we dont care.
|
||||
if (!Util.canBeShop(b))
|
||||
if (!Util.canBeShop(b,null,true))
|
||||
return; // Interacted with air
|
||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||
// Make sure they're not using the non-shop half of a double chest.
|
||||
@@ -93,7 +93,7 @@ public class LockListener implements Listener {
|
||||
}
|
||||
Player p = e.getPlayer();
|
||||
// If the chest was a chest
|
||||
if (Util.canBeShop(b)) {
|
||||
if (Util.canBeShop(b,null,true)) {
|
||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||
if (shop == null)
|
||||
return; // Wasn't a shop
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PlayerListener implements Listener {
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||
Block b = e.getClickedBlock();
|
||||
if (!Util.canBeShop(b) && b.getType() != Material.WALL_SIGN) {
|
||||
if (!Util.canBeShop(b,null,true) && b.getType() != Material.WALL_SIGN) {
|
||||
Util.debugLog("No shop block");
|
||||
return;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (!e.isCancelled() && shop == null && item != null && item.getType() != Material.AIR
|
||||
&& p.hasPermission("quickshop.create.sell") && Util.canBeShop(b)
|
||||
&& p.hasPermission("quickshop.create.sell") && Util.canBeShop(b,null,true)
|
||||
&& p.getGameMode() != GameMode.CREATIVE) {
|
||||
if(e.isCancelled())
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.maxgamer.quickshop;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -75,6 +77,8 @@ public class QuickShop extends JavaPlugin {
|
||||
public boolean priceChangeRequiresFee = false;
|
||||
/** Whether or not to limit players shop amounts */
|
||||
public boolean limit = false;
|
||||
/** Only allow create shop in special region */
|
||||
public boolean special_region_only=false;
|
||||
|
||||
/** The plugin OpenInv (null if not present) */
|
||||
public Plugin openInvPlugin;
|
||||
@@ -83,7 +87,8 @@ public class QuickShop extends JavaPlugin {
|
||||
public boolean useSpout = false;
|
||||
// private Metrics metrics;
|
||||
QS commandExecutor =null;
|
||||
MultiverseCore mPlugin = null;
|
||||
public MultiverseCore mPlugin = null;
|
||||
public AreaShop areaShopPlugin = null;
|
||||
private int displayItemCheckTicks;
|
||||
private boolean noopDisable;
|
||||
private boolean setupDBonEnableding = false;
|
||||
@@ -96,7 +101,6 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
@@ -113,8 +117,8 @@ public class QuickShop extends JavaPlugin {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if(getServer().getName().toLowerCase().contains("catserver")) {
|
||||
//Send FATAL ERROR TO CatServer's users.
|
||||
if (getServer().getName().toLowerCase().contains("catserver")) {
|
||||
// Send FATAL ERROR TO CatServer's users.
|
||||
getLogger().info("NOTICE: QSRR nolonger support CatServer ALERT!");
|
||||
getLogger().info("NOTICE: From 1.3.1.9, QSRR already nolonger support CatServer");
|
||||
getLogger().info("NOTICE: Cause this server have important license issues,");
|
||||
@@ -159,12 +163,19 @@ public class QuickShop extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
if (getConfig().getBoolean("plugin.Multiverse-Core")) {
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) {
|
||||
mPlugin = (MultiverseCore) Bukkit.getPluginManager().getPlugin("Multiverse-Core");
|
||||
getLogger().info("Successfully loaded MultiverseCore support!");
|
||||
}
|
||||
}
|
||||
if (getConfig().getBoolean("plugin.AreaShop")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("AreaShop") != null) {
|
||||
areaShopPlugin = (AreaShop) Bukkit.getPluginManager().getPlugin("AreaShop");
|
||||
AreaShopListener areaShopListener = new AreaShopListener();
|
||||
Bukkit.getPluginManager().registerEvents(areaShopListener, this);
|
||||
getLogger().info("Successfully loaded AreaShop support!");
|
||||
}
|
||||
}
|
||||
// added for compatibility reasons with OpenInv - see
|
||||
// https://github.com/KaiKikuchi/QuickShop/issues/139
|
||||
if (getConfig().getBoolean("plugin.OpenInv")) {
|
||||
@@ -194,6 +205,22 @@ public class QuickShop extends JavaPlugin {
|
||||
LockListener ll = new LockListener(this);
|
||||
getServer().getPluginManager().registerEvents(ll, this);
|
||||
}
|
||||
// Impossible create shop check.
|
||||
this.special_region_only = getConfig().getBoolean("shop.special-region-only");
|
||||
if (special_region_only) {
|
||||
if (areaShopPlugin == null) {
|
||||
special_region_only=false;
|
||||
getLogger().warning(
|
||||
"WARNING: You enabled Special Region Only but not install AreaShop, we already auto disabled it this time.");
|
||||
getLogger().warning("WARNING: Server will continue load in 15 secs.");
|
||||
try {
|
||||
Thread.sleep(15000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new UpdateWatcher(), this);
|
||||
ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits");
|
||||
if (limitCfg != null) {
|
||||
@@ -269,7 +296,7 @@ public class QuickShop extends JavaPlugin {
|
||||
Location loc = new Location(world, x, y, z);
|
||||
/* Skip invalid shops, if we know of any */
|
||||
step = "Checking InventoryHolder";
|
||||
if (world != null && Util.canBeShop(loc.getBlock()) == false) {
|
||||
if (world != null && Util.canBeShop(loc.getBlock(),null,true) == false) {
|
||||
step = "Removeing shop in world: Because it not a correct InventoryHolder";
|
||||
getLogger().info("Shop is not an InventoryHolder in " + rs.getString("world") + " at: " + x
|
||||
+ ", " + y + ", " + z + ". Deleting.");
|
||||
@@ -693,6 +720,14 @@ public class QuickShop extends JavaPlugin {
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
if (selectedVersion == 13) {
|
||||
getConfig().set("plugin.AreaShop",false);
|
||||
getConfig().set("shop.special-region-only", false);
|
||||
getConfig().set("config-version", 14);
|
||||
selectedVersion = 14;
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -605,7 +605,6 @@ public class ContainerShop implements Shop {
|
||||
try {
|
||||
DatabaseHelper.removeShop(plugin.getDB(), x, y, z, world);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Refund if necessary
|
||||
@@ -620,7 +619,7 @@ public class ContainerShop implements Shop {
|
||||
|
||||
public boolean isValid() {
|
||||
checkDisplay();
|
||||
return Util.canBeShop(this.getLocation().getBlock());
|
||||
return Util.canBeShop(this.getLocation().getBlock(),null,true);
|
||||
}
|
||||
|
||||
private void checkDisplay() {
|
||||
|
||||
@@ -349,7 +349,7 @@ public class ShopManager {
|
||||
// Get the shop they interacted with
|
||||
Shop shop = plugin.getShopManager().getShop(info.getLocation());
|
||||
// It's not valid anymore
|
||||
if (shop == null || Util.canBeShop(info.getLocation().getBlock()) == false) {
|
||||
if (shop == null || Util.canBeShop(info.getLocation().getBlock(),null,true) == false) {
|
||||
p.sendMessage(MsgUtil.getMessage("chest-was-removed"));
|
||||
return;
|
||||
}
|
||||
@@ -439,7 +439,7 @@ public class ShopManager {
|
||||
private void actionSell(Player p, HashMap<UUID, Info> actions2, Info info, String message, Shop shop2, int amount) {
|
||||
Shop shop = plugin.getShopManager().getShop(info.getLocation());
|
||||
// It's not valid anymore
|
||||
if (shop == null || Util.canBeShop(info.getLocation().getBlock()) == false) {
|
||||
if (shop == null || Util.canBeShop(info.getLocation().getBlock(),null,true) == false) {
|
||||
p.sendMessage(MsgUtil.getMessage("chest-was-removed"));
|
||||
return;
|
||||
}
|
||||
@@ -539,7 +539,7 @@ public class ShopManager {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.canBeShop(info.getLocation().getBlock()) == false) {
|
||||
if (Util.canBeShop(info.getLocation().getBlock(),null,true) == false) {
|
||||
p.sendMessage(MsgUtil.getMessage("chest-was-removed"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ public class MsgUtil {
|
||||
* on space.
|
||||
*/
|
||||
public static void clean() {
|
||||
plugin.getLogger().log(Level.WARNING, "Cleaning purchase messages from database that are over a week old...");
|
||||
plugin.getLogger().info("Cleaning purchase messages from database that are over a week old...");
|
||||
// 604800,000 msec = 1 week.
|
||||
long weekAgo = System.currentTimeMillis() - 604800000;
|
||||
DatabaseHelper.cleanMessage(weekAgo);
|
||||
|
||||
@@ -27,6 +27,9 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.DisplayItem;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -132,11 +135,23 @@ public class Util {
|
||||
/**
|
||||
* Returns true if the given block could be used to make a shop out of.
|
||||
*
|
||||
* @param b
|
||||
* The block to check. Possibly a chest, dispenser, etc.
|
||||
* @param b The block to check, Possibly a chest, dispenser, etc. player The player, can be null if onlyCheck=true, onlyCheck The option to disable check AreaShop use player.
|
||||
* @return True if it can be made into a shop, otherwise false.
|
||||
*/
|
||||
public static boolean canBeShop(Block b) {
|
||||
public static boolean canBeShop(Block b,Player player, boolean onlyCheck) {
|
||||
if (plugin.special_region_only&&onlyCheck==false) {
|
||||
List<RentRegion> regions = me.wiefferink.areashop.tools.Utils.getImportantRentRegions(b.getLocation());
|
||||
boolean passTheRegionCheck = false;
|
||||
for (RentRegion rentRegion : regions) {
|
||||
if(rentRegion.getOwner()!=player.getUniqueId()) {
|
||||
passTheRegionCheck=true;
|
||||
break; //If there passed, will continue to check BlockState
|
||||
}
|
||||
}
|
||||
if(passTheRegionCheck==false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BlockState bs = b.getState();
|
||||
if ((bs instanceof InventoryHolder == false) && b.getState().getType() != Material.ENDER_CHEST) {
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#Default config: https://github.com/KaiKikuchi/QuickShop/blob/master/src/main/resources/config.yml
|
||||
|
||||
#Do not touch if you not clear know about this
|
||||
config-version: 13
|
||||
config-version: 14
|
||||
|
||||
#Do not touch if you not know what is this
|
||||
dev-mode: false
|
||||
@@ -116,36 +116,15 @@ shop:
|
||||
#Ignore trade messages if shop is unlimited
|
||||
ignore-unlimited-shop-messages: false
|
||||
|
||||
#Enable this if you only want player create the shop in special region
|
||||
#When you enable this, you only can create shop in AreaShop's area or have "allow-qs-shop" flags WorldGuard region.
|
||||
special-region-only: false
|
||||
|
||||
|
||||
#List of items to disallow selling of. Anyone with quickshop.bypass.<itemID> can bypass it
|
||||
blacklist:
|
||||
- Bedrock
|
||||
|
||||
# custom-potions-name:
|
||||
# sign:
|
||||
# format: "%variety%type"
|
||||
# variety:
|
||||
# normal: ""
|
||||
# splash: "Splash"
|
||||
# lingering: "Ling"
|
||||
# shopinfo:
|
||||
# format: "%variety %type"
|
||||
# variety:
|
||||
# normal: ""
|
||||
# splash: "Splash"
|
||||
# lingering: "Lingering"
|
||||
|
||||
# #Custom names for potions types. Format: <PotionType>;<CustomSignName>;<CustomFullName>
|
||||
# # PotionType: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionType.html
|
||||
# types:
|
||||
# - INVISIBILITY;Invis;Invisibility
|
||||
|
||||
# #Custom names for potion effect type. Format: <PotionEffectType>;<CustomName>
|
||||
# # PotionEffect: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html
|
||||
# effects:
|
||||
# - FIRE_RESISTANCE;Fire resistance
|
||||
# - INVISIBILITY;Invisibility
|
||||
|
||||
protect:
|
||||
#Protect shop item can or cannot pull out by HopperMincart (Will remove HopprtMincart
|
||||
minecart: true
|
||||
@@ -200,4 +179,7 @@ plugin:
|
||||
#If you have Multiverse-Core, QSRR will try load world when shop's world not exist and throw out exception auto repair the shop.
|
||||
Multiverse-Core: true
|
||||
#If you have OpenInv, QSRR will enable EnderChest feature.
|
||||
OpenInv: true
|
||||
OpenInv: true
|
||||
#Enable AreaShop support
|
||||
#Allow QuickShop detect AS unrented event and remove shop from region.
|
||||
AreaShop: false
|
||||
@@ -5,7 +5,7 @@ authors: [Netherfoam, Timtower, KaiNoMood, Ghost_chu, Mgazul]
|
||||
|
||||
description: Economy Shops plugin
|
||||
#softdepend: [Herochat, Vault, Essentials, OpenInv] OLD Remove Herochat support.
|
||||
softdepend: [Vault, WorldGuard, Essentials, OpenInv, Multiverse-Core]
|
||||
softdepend: [Vault, WorldGuard, Essentials, OpenInv, Multiverse-Core, AreaShop]
|
||||
|
||||
api-version: 1.13
|
||||
|
||||
|
||||
Reference in new issue
Block a user