Added ClearLagg Support

This commit is contained in:
Eric 2015-09-02 16:18:32 +02:00
parent 0cdcfb5cc6
commit 24c32b5e64
3 changed files with 85 additions and 8 deletions

View File

@ -24,6 +24,7 @@ import de.epiceric.shopchest.event.InteractShop;
import de.epiceric.shopchest.event.NotifyUpdate; import de.epiceric.shopchest.event.NotifyUpdate;
import de.epiceric.shopchest.event.ProtectChest; import de.epiceric.shopchest.event.ProtectChest;
import de.epiceric.shopchest.event.RegenerateShopItem; import de.epiceric.shopchest.event.RegenerateShopItem;
import de.epiceric.shopchest.event.RegenerateShopItemAfterRemove;
import de.epiceric.shopchest.event.UpdateHolograms; import de.epiceric.shopchest.event.UpdateHolograms;
import de.epiceric.shopchest.shop.Hologram; import de.epiceric.shopchest.shop.Hologram;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
@ -33,7 +34,6 @@ import de.epiceric.shopchest.utils.JsonBuilder.HoverAction;
import de.epiceric.shopchest.utils.Metrics; import de.epiceric.shopchest.utils.Metrics;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker; import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.EntityArmorStand;
@ -75,12 +75,6 @@ public class ShopChest extends JavaPlugin{
return perm != null; return perm != null;
} }
@Override
public void onLoad() {
getLogger().info(Utils.getVersion());
}
@Override @Override
public void onEnable() { public void onEnable() {
@ -162,6 +156,7 @@ public class ShopChest extends JavaPlugin{
getServer().getPluginManager().registerEvents(new InteractShop(this), this); getServer().getPluginManager().registerEvents(new InteractShop(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdate(), this); getServer().getPluginManager().registerEvents(new NotifyUpdate(), this);
getServer().getPluginManager().registerEvents(new ProtectChest(), this); getServer().getPluginManager().registerEvents(new ProtectChest(), this);
if (getServer().getPluginManager().getPlugin("ClearLag") != null) getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this);
} }

View File

@ -12,6 +12,8 @@ public class RegenerateShopItem implements Listener{
public RegenerateShopItem() {} public RegenerateShopItem() {}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onItemDespawn(ItemDespawnEvent e) { public void onItemDespawn(ItemDespawnEvent e) {
Item item = e.getEntity(); Item item = e.getEntity();

View File

@ -0,0 +1,80 @@
package de.epiceric.shopchest.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.shop.Hologram;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ShopUtils;
import net.minecraft.server.v1_8_R3.EntityArmorStand;
public class RegenerateShopItemAfterRemove implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onEntityRemove(me.minebuilders.clearlag.events.EntityRemoveEvent e) {
boolean containsShopItem = false;
for (Entity entity : e.getEntityList()) {
if (entity.hasMetadata("shopItem")) {
containsShopItem = true;
break;
}
}
if (containsShopItem) reload();
}
private void reload() {
for (Shop shop : ShopUtils.getShops()) {
Hologram hologram = shop.getHologram();
shop.getItem().remove();
ShopUtils.removeShop(shop);
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
hologram.hidePlayer(p);
}
for (Object o : hologram.getEntities()) {
EntityArmorStand e = (EntityArmorStand) o;
e.getWorld().removeEntity(e);
}
}
for (String key : ShopChest.getInstance().shopChests.getKeys(false)) {
OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor");
int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x");
int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y");
int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z");
World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world"));
Location location = new Location(locationWorld, locationX, locationY, locationZ);
ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product");
double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy");
double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell");
boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite");
ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite));
}
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
}
}
}