Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Fix create quickshop bypass the protection and fix filter bug.
Browse files Browse the repository at this point in the history
Former-commit-id: 60d0523
  • Loading branch information
Ghost-chu committed Sep 23, 2018
1 parent a14ecc2 commit df36c38
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/maxgamer/quickshop/Command/QS.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -290,14 +291,17 @@ private void create(CommandSender sender, String[] args) {

while (bIt.hasNext()) {
Block b = bIt.next();

if (Util.canBeShop(b)) {
PlayerInteractEvent e = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, b, BlockFace.UP);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return;
}

BlockBreakEvent be = new BlockBreakEvent(b,p);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
return;
}
if (!plugin.getShopManager().canBuildShop(p, b, Util.getYawFace(p.getLocation().getYaw()))) {
// As of the new checking system, most plugins will tell the
// player why they can't create a shop there.
Expand Down
108 changes: 55 additions & 53 deletions src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -51,113 +52,113 @@ public void spawn() {
if (shop.getLocation().getWorld() == null)
return;
Location dispLoc = this.getDisplayLocation();
//Check is or not in blacklist/whitelist
// Check is or not in blacklist/whitelist
boolean showFloatItem = true;
if(plugin.getConfig().getBoolean("float.enable")){
//Enabled! Check start!
//Item
if (plugin.getConfig().getBoolean("float.enable")) {
// Enabled! Check start!

// Item
boolean found_item = false;
boolean found_lore = false;
boolean found_displayname = false;
if(plugin.getConfig().getBoolean("float.item.enable")) {
if (plugin.getConfig().getBoolean("float.item.enable")) {
boolean blacklist = plugin.getConfig().getBoolean("float.item.blacklist");
itemlist = plugin.getConfig().getList("float.item.list");
for (Object material : itemlist) {
String materialname = String.valueOf(material);
Material item = Material.matchMaterial(materialname);
if(item!=null) {
found_item=true;
if (item != null) {
found_item = true;
break;
}else {
plugin.getLogger().info(materialname+" not a bukkit item.");
} else {
plugin.getLogger().info(materialname + " not a bukkit item.");
}
}
if(found_item) {
if(blacklist) {
showFloatItem=false;
}
if (blacklist) {
if (found_item) {
return;
}
}else {
if(!blacklist) {
showFloatItem=false;
} else {
if (!found_item) {
return;
}
}
}
if(!showFloatItem) {
if (!showFloatItem) {
return;
}
//End Item check
//DisplayName
if(plugin.getConfig().getBoolean("float.displayname.enable")) {
// End Item check

// DisplayName
if (plugin.getConfig().getBoolean("float.displayname.enable")) {
boolean blacklist = plugin.getConfig().getBoolean("float.displayname.blacklist");
displaynamelist = plugin.getConfig().getList("float.displayname.list");
if(!iStack.hasItemMeta()) {
found_displayname=false;
}else {
if (!iStack.hasItemMeta()) {
found_displayname = false;
} else {
String itemname = iStack.getItemMeta().getDisplayName();
for (Object name : displaynamelist) {
String listname = String.valueOf(name);
if(itemname.contains(listname)) {
if (itemname.contains(listname)) {
found_displayname = true;
break;
}
}
}
if(blacklist) {
if(found_displayname) {
if (blacklist) {
if (found_displayname) {
showFloatItem = false;
}
}else {
if(!found_displayname) {
} else {
if (!found_displayname) {
showFloatItem = false;
}
}
if(!showFloatItem) {
if (!showFloatItem) {
return;
}
//End DisplayName check
// End DisplayName check
}
//Lore
if(plugin.getConfig().getBoolean("float.lore.enable")) {

// Lore
if (plugin.getConfig().getBoolean("float.lore.enable")) {
boolean blacklist = plugin.getConfig().getBoolean("float.lore.blacklist");
lorelist=plugin.getConfig().getList("float.lore.list");
if(!iStack.hasItemMeta()) {
lorelist = plugin.getConfig().getList("float.lore.list");
if (!iStack.hasItemMeta()) {
found_lore = false;
}else {
} else {
java.util.List<String> itemlores = iStack.getItemMeta().getLore();
for (String loreinItem : itemlores) {
String loreinItem_String = loreinItem;
for (Object loreinList : lorelist) {
String loreinList_String = String.valueOf(loreinList);
if(loreinItem_String.contains(loreinList_String)) {
if (loreinItem_String.contains(loreinList_String)) {
found_lore = true;
break;
}
}
if(found_lore) {
if (found_lore) {
break;
}
}
if(blacklist) {
if(found_lore) {
showFloatItem=false;
if (blacklist) {
if (found_lore) {
showFloatItem = false;
}
}else {
if(!found_lore) {
showFloatItem=false;
} else {
if (!found_lore) {
showFloatItem = false;
}
}
if(!showFloatItem) {
if (!showFloatItem) {
return;
}

}
}
}
}
//Check end
if(!showFloatItem) {
// Check end
if (!showFloatItem) {
return;
}
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
Expand All @@ -167,10 +168,11 @@ public void spawn() {
}
try {
this.safeGuard(this.item);
//NMS.safeGuard
// NMS.safeGuard
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().log(Level.WARNING, "QuickShop version mismatch! This version of QuickShop is incompatible with this version of bukkit! Try update?");
plugin.getLogger().log(Level.WARNING,
"QuickShop version mismatch! This version of QuickShop is incompatible with this version of bukkit! Try update?");
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Sign;
Expand Down Expand Up @@ -54,14 +55,31 @@ public HashMap<UUID, Info> getActions() {
public void createShop(Shop shop) {
Location loc = shop.getLocation();
ItemStack item = shop.getItem();
Player player = Bukkit.getPlayer(shop.getOwner());
if(player==null || !player.isOnline()) {
plugin.getLogger().info("Warning! Something wrong happed when createing shop,Canceling... (Code: Target player not online)");
return;
}
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, shop.getLocation().getBlock(), BlockFace.UP);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
e.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
BlockBreakEvent be = new BlockBreakEvent(shop.getLocation().getBlock(),player);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
be.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
try {
// Write it to the database
String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
plugin.getDB().execute(q, shop.getOwner().toString(), shop.getPrice(), Util.serialize(item), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName(), (shop.isUnlimited() ? 1 : 0), shop.getShopType().toID());
// Add it to the world
addShop(loc.getWorld().getName(), shop);
} catch (Exception e) {
e.printStackTrace();
} catch (Exception error) {
error.printStackTrace();
plugin.getLogger().log(Level.WARNING, "Could not create shop! Changes will revert after a reboot!");
}
}
Expand Down

0 comments on commit df36c38

Please sign in to comment.