mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-12-24 01:58:40 +01:00
Changed way of checking if chests are protected
If another plugin cancelled the PlayerInteractEvent before ShopChest, the player is not permitted to create a shop on the clicked chest. The dependency of 'Lockette' is no longer needed. It might occur that a plugin, which is not used for protections, cancels the PlayerInteractEvent so a shop cannot be created. This closes #14
This commit is contained in:
parent
7dcd61a56a
commit
76ea273ad6
@ -56,12 +56,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yi.acru.bukkit</groupId>
|
||||
<artifactId>lockette</artifactId>
|
||||
<version>1.8.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.minebuilders</groupId>
|
||||
<artifactId>clearlag</artifactId>
|
||||
|
@ -41,7 +41,6 @@ public class ShopChest extends JavaPlugin {
|
||||
private Config config = null;
|
||||
private Economy econ = null;
|
||||
private Permission perm = null;
|
||||
private boolean lockette = false;
|
||||
private boolean lwc = false;
|
||||
private Database database;
|
||||
private boolean isUpdateNeeded = false;
|
||||
@ -239,7 +238,6 @@ public class ShopChest extends JavaPlugin {
|
||||
}, config.auto_reload_time * 20, config.auto_reload_time * 20);
|
||||
}
|
||||
|
||||
lockette = getServer().getPluginManager().isPluginEnabled("Lockette");
|
||||
lwc = getServer().getPluginManager().isPluginEnabled("LWC");
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@ -455,13 +453,6 @@ public class ShopChest extends JavaPlugin {
|
||||
return lwc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether Lockette is available
|
||||
*/
|
||||
public boolean hasLockette() {
|
||||
return lockette;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether an update is needed (will return false if not checked)
|
||||
*/
|
||||
|
@ -1,7 +1,5 @@
|
||||
package de.epiceric.shopchest.listeners;
|
||||
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.model.Protection;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Regex;
|
||||
import de.epiceric.shopchest.event.ShopBuySellEvent;
|
||||
@ -28,6 +26,7 @@ import org.bukkit.block.Chest;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -36,7 +35,6 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -57,6 +55,47 @@ public class ShopInteractListener implements Listener {
|
||||
this.shopUtils = plugin.getShopUtils();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerInteractCreate(PlayerInteractEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
Block b = e.getClickedBlock();
|
||||
|
||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (ClickType.getPlayerClickType(p) != null) {
|
||||
if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) {
|
||||
if (!shopUtils.isShop(b.getLocation())) {
|
||||
if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED));
|
||||
ClickType.removePlayerClickType(p);
|
||||
return;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||
ClickType clickType = ClickType.getPlayerClickType(p);
|
||||
ItemStack product = clickType.getProduct();
|
||||
double buyPrice = clickType.getBuyPrice();
|
||||
double sellPrice = clickType.getSellPrice();
|
||||
ShopType shopType = clickType.getShopType();
|
||||
|
||||
create(p, b.getLocation(), product, buyPrice, sellPrice, shopType);
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED));
|
||||
}
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP));
|
||||
}
|
||||
|
||||
ClickType.removePlayerClickType(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
Block b = e.getClickedBlock();
|
||||
@ -71,53 +110,6 @@ public class ShopInteractListener implements Listener {
|
||||
if (ClickType.getPlayerClickType(p) != null) {
|
||||
|
||||
switch (ClickType.getPlayerClickType(p).getClickType()) {
|
||||
|
||||
case CREATE:
|
||||
e.setCancelled(true);
|
||||
|
||||
if (!perm.has(p, "shopchest.create.protected")) {
|
||||
if (plugin.hasLockette()) {
|
||||
if (Lockette.isProtected(b)) {
|
||||
if (!Lockette.isOwner(b, p) || !Lockette.isUser(b, p, true)) {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED));
|
||||
ClickType.removePlayerClickType(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.hasLWC()) {
|
||||
if (LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()) != null) {
|
||||
Protection protection = LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||
if (!protection.isOwner(p) || !protection.isRealOwner(p)) {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED));
|
||||
ClickType.removePlayerClickType(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!shopUtils.isShop(b.getLocation())) {
|
||||
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||
ClickType clickType = ClickType.getPlayerClickType(p);
|
||||
ItemStack product = clickType.getProduct();
|
||||
double buyPrice = clickType.getBuyPrice();
|
||||
double sellPrice = clickType.getSellPrice();
|
||||
ShopType shopType = clickType.getShopType();
|
||||
|
||||
create(p, b.getLocation(), product, buyPrice, sellPrice, shopType);
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP));
|
||||
}
|
||||
|
||||
ClickType.removePlayerClickType(p);
|
||||
break;
|
||||
|
||||
case INFO:
|
||||
e.setCancelled(true);
|
||||
|
||||
|
@ -57,7 +57,7 @@ message.hologram.only-buy=Kauf %BUY-PRICE%
|
||||
message.hologram.only-sell=Verkauf %SELL-PRICE%
|
||||
message.noPermission.create=&cDu hast keine Berechtigung einen Shop zu erstellen.
|
||||
message.noPermission.create-admin=&cDu hast keine Berechtigung einen Admin-Shop zu erstellen.
|
||||
message.noPermission.create-protected=&cDu hast keine Berechtigung einen Shop auf einer gesicherten Truhe zu erstellen.
|
||||
message.noPermission.create-protected=&cDu hast keine Berechtigung hier einen Shop zu erstellen.
|
||||
message.noPermission.open-others=&cDu hast keine Berechtigung diesen Shop zu öffnen.
|
||||
message.noPermission.buy=&cDu hast keine Berechtigung etwas zu kaufen.
|
||||
message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen.
|
||||
|
@ -204,7 +204,7 @@ message.noPermission.create=&cYou don't have permission to create a shop.
|
||||
message.noPermission.create-admin=&cYou don't have permission to create an admin shop.
|
||||
|
||||
# Set the message when a not permitted player tries to create a shop on a protected chest.
|
||||
message.noPermission.create-protected=&cYou don't have permission to create a shop on a protected chest.
|
||||
message.noPermission.create-protected=&cYou don't have permission to create a shop here.
|
||||
|
||||
# Set the message when a not permitted player tries to open another player's shop.
|
||||
message.noPermission.open-others=&cYou don't have permission to open this chest.
|
||||
|
6
pom.xml
6
pom.xml
@ -58,12 +58,6 @@
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yi.acru.bukkit</groupId>
|
||||
<artifactId>lockette</artifactId>
|
||||
<version>1.8.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.minebuilders</groupId>
|
||||
<artifactId>clearlag</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user