This commit is contained in:
Ghost_chu committed 2018-07-30 22:15:12 +08:00
1 parent 7e39bae813
commit 28c4708dfe
4 files changed
+303 -32

No files matched your search

@@ -7,15 +7,9 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Hopper;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Player;
import org.bukkit.entity.Silverfish;
import org.bukkit.entity.Wither;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.entity.minecart.HopperMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -34,13 +28,11 @@ import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Shop.Info;
import org.maxgamer.quickshop.Shop.Shop;
import org.maxgamer.quickshop.Shop.ShopAction;
import org.maxgamer.quickshop.Shop.ShopManager;
import org.maxgamer.quickshop.Util.MsgUtil;
import org.maxgamer.quickshop.Util.Util;
public class BlockListener implements Listener {
private QuickShop plugin;
private ShopManager shop;
public BlockListener(QuickShop plugin) {
this.plugin = plugin;
@@ -105,7 +97,7 @@ public class BlockListener implements Listener {
return;
e.setCancelled(true); // Cancel the event so that the sign does not
// drop.. TODO: Find a better way.
b.setType(Material.AIR);
//b.setType(Material.AIR);
}
}
//Protect Minecart steal shop
@@ -116,43 +108,47 @@ public class BlockListener implements Listener {
if (event.getDestination().getHolder() instanceof HopperMinecart) {
HopperMinecart hm = (HopperMinecart) event.getDestination().getHolder();
Location minecartLoc = new Location(hm.getWorld(), hm.getLocation().getBlockX(), hm.getLocation().getBlockY()+1, hm.getLocation().getBlockZ());
if(shop.getShop(minecartLoc)!=null)
event.setCancelled(true);{
Shop shop = plugin.getShopManager().getShop(minecartLoc);
if (shop == null) {
return;
}
event.setCancelled(true);
hm.remove();
plugin.getLogger().warning("[Exploit Alert] a HopperMinecart tried to move the item of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A HopperMinecart tried to move the item of "+shop);
hm.remove();
}
}
if(plugin.getConfig().getBoolean("protect.hopper")) {
if (event.getDestination().getHolder() instanceof Hopper) {
Hopper h = (Hopper) event.getDestination().getHolder();
Location minecartLoc = new Location(h.getWorld(), h.getLocation().getBlockX(), h.getLocation().getBlockY()+1, h.getLocation().getBlockZ());
if(shop.getShop(minecartLoc)!=null) {
event.setCancelled(true);
Shop shop = plugin.getShopManager().getShop(minecartLoc);
if (shop == null) {
return;
}
event.setCancelled(true);
h.setType(Material.AIR);
plugin.getLogger().warning("[Exploit Alert] a HopperMinecart tried to move the item of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A HopperMinecart tried to move the item of "+shop);
}
}
}
}
}
}
//Protect Entity pickup shop
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onMobChangeBlock(EntityChangeBlockEvent event) {
if ((event.getEntity() instanceof Enderman) ||
(event.getEntity() instanceof Wither) ||
(event.getEntity() instanceof Zombie) ||
(event.getEntity() instanceof Silverfish)){
if (shop.getShop(event.getBlock().getLocation())!=null){
Shop shop = plugin.getShopManager().getShop(event.getBlock().getLocation());
if (shop == null) {
return;
}
if (shop !=null){
if(plugin.getConfig().getBoolean("protect.entity")) {
event.setCancelled(true);
event.getEntity().remove();
plugin.getLogger().warning("[Exploit Alert] a Entity tried to break the shop of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A Entity tried to break the shop of "+shop);
event.getEntity().remove();
}else {
shop.getShop(event.getBlock().getLocation()).delete();
}
}
shop.delete();
}
}
}
//Protect Redstone active shop
@@ -161,19 +157,28 @@ public class BlockListener implements Listener {
if (!plugin.getConfig().getBoolean("protect.redstone")){
return;
}
if (shop.getShop(event.getBlock().getLocation()) != null){
Shop shop = plugin.getShopManager().getShop(event.getBlock().getLocation());
if (shop == null) {
return;
}
if (shop != null){
event.setNewCurrent(event.getOldCurrent());
plugin.getLogger().warning("[Exploit Alert] a Redstone tried to active of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A Redstone tried to active of "+shop);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event){
if (!plugin.getConfig().getBoolean("protect.structuregrow")) {
return;
}
for (BlockState blockstate : event.getBlocks()){
if(shop.getShop(blockstate.getLocation())!=null) {
Shop shop = plugin.getShopManager().getShop(blockstate.getLocation());
if (shop == null) {
return;
}
if(shop !=null) {
event.setCancelled(true);
plugin.getLogger().warning("[Exploit Alert] a StructureGrowing tried to break the shop of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A StructureGrowing tried to break the shop of "+shop);
@@ -195,9 +200,9 @@ public class BlockListener implements Listener {
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if(plugin.getConfig().getBoolean("protect.explode")) {
e.setCancelled(true);
plugin.getLogger().warning("[Exploit Alert] a EntityExplode tried to break the shop of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A EntityExplode tried to break the shop of "+shop);
e.setCancelled(true);
}else {
shop.delete();
}
@@ -214,9 +219,9 @@ public class BlockListener implements Listener {
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if(plugin.getConfig().getBoolean("protect.explode")) {
e.setCancelled(true);
plugin.getLogger().warning("[Exploit Alert] a BlockExplode tried to break the shop of "+shop);
Util.sendMessageToOps(ChatColor.RED+"[QuickShop][Exploit alert] A BlockExplode tried to break the shop of "+shop);
e.setCancelled(true);
}else {
shop.delete();
}
@@ -0,0 +1,266 @@
//package org.maxgamer.quickshop.Util;
//
//import java.util.Collection;
//import java.util.Map;
//
//import org.bukkit.inventory.ItemStack;
//import org.bukkit.potion.PotionEffect;
//import org.bukkit.potion.PotionEffectType;
//import org.bukkit.potion.PotionType;
//
//public class CustomPotionsName {
// private static Map<PotionType,Names> potionTypes;
// private static Map<PotionEffectType,String> potionEffects;
// private static String[] signFormat, shopInfoFormat;
//
// private CustomPotionsName() {}
//
// public static String getSignName(ItemStack potionItemStack) {
// GenericPotionData potion = NMS.getPotionData(potionItemStack);
// if (potion==null) {
// return "InvalidPotion";
// }
//
// if (potion.isCustom() && potionItemStack.hasItemMeta() && potionItemStack.getItemMeta().hasDisplayName()) {
// // return potion name for custom potions
// return potionItemStack.getItemMeta().getDisplayName().replace(" ", "");
// }
//
// Names names = potionTypes.get(potion.getType());
// String type;
// if (names==null) {
// if (potion.getType()==PotionType.WATER) {
// return "WaterBottle";
// }
// type = Util.prettifyText(potion.getType().toString()).replace(" ", "")+"Potion";
// } else {
// type = names.getSign();
// }
//
// type+=(potion.getAmplifier()>1 ? potion.getAmplifier() : "")+(potion.getDuration()==-1 ? "+" : "");
//
// String variety;
// switch(potion.getCategory()) {
// case NORMAL:
// variety = getSignFormat()[1];
// break;
// case SPLASH:
// variety = getSignFormat()[2];
// break;
// case LINGERING:
// variety = getSignFormat()[3];
// break;
// default:
// variety = "Invalid";
// break;
// }
//
// return (getSignFormat()[0].replace("%variety", variety).replace("%type", type)).trim();
// }
//
// public static String getFullName(ItemStack potionItemStack) {
// GenericPotionData potion = NMS.getPotionData(potionItemStack);
// if (potion==null) {
// return "InvalidPotion";
// }
//
// if (potion.isCustom() && potionItemStack.hasItemMeta() && potionItemStack.getItemMeta().hasDisplayName()) {
// // return potion name for custom potions
// return potionItemStack.getItemMeta().getDisplayName().replace(" ", "");
// }
//
// Names names = potionTypes.get(potion.getType());
// String type;
// if (names==null) {
// if (potion.getType()==PotionType.WATER) {
// return "Water Bottle";
// }
// type = Util.prettifyText(potion.getType().toString())+" Potion";
// } else {
// type = names.getFull();
// }
//
// type+=(potion.getAmplifier()>1 ? " "+potion.getAmplifier() : "")+(potion.getDuration()>0 ? " ("+((int)(potion.getDuration()/20))+"s)" : potion.getDuration()==-1 ? "+" : "");
//
// String variety;
// switch(potion.getCategory()) {
// case NORMAL:
// variety = getShopInfoFormat()[1];
// break;
// case SPLASH:
// variety = getShopInfoFormat()[2];
// break;
// case LINGERING:
// variety = getShopInfoFormat()[3];
// break;
// default:
// variety = "Invalid";
// break;
// }
//
// return (getShopInfoFormat()[0].replace("%variety", variety).replace("%type", type)).trim();
// }
//
// public static String getEffects(ItemStack potionItemStack) {
// GenericPotionData potion = NMS.getPotionData(potionItemStack);
// if (potion==null) {
// return "InvalidPotion";
// }
//
// StringBuilder sb = new StringBuilder();
//
// for (PotionEffect potionEffect : potion.getEffects()) {
// PotionEffectType type = potionEffect.getType();
// String name = potionEffects.get(type);
// if (name==null) {
// name = Util.prettifyText(type.getName());
// }
//
// sb.append(name.trim()+(potionEffect.getAmplifier()>1 ? " "+potionEffect.getAmplifier() : "")+(potionEffect.getDuration()>0 ? " ("+((int)(potionEffect.getDuration()/20))+"s)" : potionEffect.getDuration()==-1 ? "+" : "")+" | ");
// }
//
// if (sb.length()>0) {
// sb.setLength(sb.length()-3);
// }
//
// return sb.toString();
// }
//
// public static class Names {
// private String sign, full;
//
// public Names(String sign, String full) {
// this.sign = sign;
// this.full = full;
// }
//
// public String getSign() {
// return sign;
// }
//
// public String getFull() {
// return full;
// }
//
// @Override
// public String toString() {
// return "Names [sign=" + sign + ", full=" + full + "]";
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((full == null) ? 0 : full.hashCode());
// result = prime * result + ((sign == null) ? 0 : sign.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (!(obj instanceof Names)) {
// return false;
// }
// Names other = (Names) obj;
// if (full == null) {
// if (other.full != null) {
// return false;
// }
// } else if (!full.equals(other.full)) {
// return false;
// }
// if (sign == null) {
// if (other.sign != null) {
// return false;
// }
// } else if (!sign.equals(other.sign)) {
// return false;
// }
// return true;
// }
//
// }
//
// public static class GenericPotionData {
// private PotionType type;
// private Collection<PotionEffect> effects;
// private Category category;
// private boolean custom;
// private int amplifier, duration;
//
// public GenericPotionData(PotionType type, Collection<PotionEffect> effects, Category category, boolean isCustom, int duration, int amplifier) {
// this.type = type;
// this.effects = effects;
// this.category = category;
// this.custom = isCustom;
// this.duration = duration;
// this.amplifier = amplifier;
// }
//
// public PotionType getType() {
// return type;
// }
//
// public Collection<PotionEffect> getEffects() {
// return effects;
// }
//
// public Category getCategory() {
// return category;
// }
//
// public boolean isCustom() {
// return custom;
// }
//
// public int getAmplifier() {
// return amplifier;
// }
//
// public int getDuration() {
// return duration;
// }
//
// public enum Category {
// NORMAL, SPLASH, LINGERING;
// }
// }
//
// public static String[] getSignFormat() {
// return signFormat;
// }
//
// public static String[] getShopInfoFormat() {
// return shopInfoFormat;
// }
//
// public static void setSignFormat(String[] signFormat) {
// CustomPotionsName.signFormat = signFormat;
// }
//
// public static void setShopInfoFormat(String[] shopInfoFormat) {
// CustomPotionsName.shopInfoFormat = shopInfoFormat;
// }
//
// public static Map<PotionType, Names> getPotionTypes() {
// return potionTypes;
// }
//
// public static void setPotionTypes(Map<PotionType, Names> potionTypes) {
// CustomPotionsName.potionTypes = potionTypes;
// }
//
// public static Map<PotionEffectType,String> getPotionEffects() {
// return potionEffects;
// }
//
// public static void setPotionEffects(Map<PotionEffectType,String> potionEffects) {
// CustomPotionsName.potionEffects = potionEffects;
// }
//}