mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-25 11:46:45 +01:00
Remove SyncTouch.
This commit is contained in:
parent
6de2f2ff08
commit
0e546f9894
@ -18,7 +18,6 @@ import com.songoda.epichoppers.boost.BoostManager;
|
||||
import com.songoda.epichoppers.commands.*;
|
||||
import com.songoda.epichoppers.database.DataManager;
|
||||
import com.songoda.epichoppers.database.migrations._1_InitialMigration;
|
||||
import com.songoda.epichoppers.enchantment.Enchantment;
|
||||
import com.songoda.epichoppers.handlers.TeleportHandler;
|
||||
import com.songoda.epichoppers.hopper.*;
|
||||
import com.songoda.epichoppers.hopper.levels.Level;
|
||||
@ -50,8 +49,7 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
|
||||
private static EpicHoppers INSTANCE;
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
public Enchantment enchantmentHandler;
|
||||
private Config levelsConfig = new Config(this, "levels.yml");
|
||||
private final Config levelsConfig = new Config(this, "levels.yml");
|
||||
private HopperManager hopperManager;
|
||||
private CommandManager commandManager;
|
||||
private LevelManager levelManager;
|
||||
@ -101,14 +99,12 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.commandManager.addCommand(new CommandEpicHoppers(this))
|
||||
.addSubCommands(
|
||||
new CommandBook(this),
|
||||
new CommandBoost(this),
|
||||
new CommandGive(this),
|
||||
new CommandReload(this),
|
||||
new CommandSettings(this)
|
||||
);
|
||||
|
||||
this.enchantmentHandler = new Enchantment();
|
||||
this.hopperManager = new HopperManager();
|
||||
this.playerDataManager = new PlayerDataManager();
|
||||
this.boostManager = new BoostManager();
|
||||
@ -225,10 +221,10 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
guiManager.init();
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
pluginManager.registerEvents(new HopperListeners(this), this);
|
||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||
pluginManager.registerEvents(new EntityListeners(), this);
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(), this);
|
||||
|
||||
// Check for liquid tanks
|
||||
if (pluginManager.isPluginEnabled("LiquidTanks")) liquidtanks = true;
|
||||
|
@ -1,57 +0,0 @@
|
||||
package com.songoda.epichoppers.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBook extends AbstractCommand {
|
||||
|
||||
final EpicHoppers instance;
|
||||
|
||||
public CommandBook(EpicHoppers instance) {
|
||||
super(false, "book");
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length == 0) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).getInventory().addItem(instance.enchantmentHandler.getbook());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
} else if (Bukkit.getPlayerExact(args[0]) == null) {
|
||||
instance.getLocale().newMessage("&cThat username does not exist, or the user is not online!")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
Bukkit.getPlayerExact(args[0]).getInventory().addItem(instance.enchantmentHandler.getbook());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/eh book [player]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives Sync Touch book to you or a player.";
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.songoda.epichoppers.enchantment;
|
||||
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/22/2017.
|
||||
*/
|
||||
public class Enchantment {
|
||||
|
||||
public ItemStack createSyncTouch(ItemStack item, Block block) {
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
List<String> lore = itemmeta.hasLore() ? itemmeta.getLore() : new ArrayList<>();
|
||||
|
||||
for (String str : lore) {
|
||||
if (!str.contains("Sync Touch")) continue;
|
||||
lore.remove(str);
|
||||
break;
|
||||
}
|
||||
|
||||
if (block != null) {
|
||||
lore.add(Methods.convertToInvisibleString(Methods.serializeLocation(block) + "~")
|
||||
+ Methods.formatText("&aSync Touch"));
|
||||
} else {
|
||||
lore.add(Methods.formatText("&7Sync Touch"));
|
||||
}
|
||||
itemmeta.setLore(lore);
|
||||
item.setItemMeta(itemmeta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemStack getbook() {
|
||||
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta meta = book.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText("&eEnchanted Book"));
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Methods.formatText("&7Sync Touch"));
|
||||
meta.setLore(lore);
|
||||
book.setItemMeta(meta);
|
||||
return book;
|
||||
}
|
||||
}
|
@ -106,8 +106,6 @@ public class BlockListeners implements Listener {
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
handleSyncTouch(event);
|
||||
|
||||
if (event.getBlock().getType() != Material.HOPPER) return;
|
||||
|
||||
if (instance.isLiquidtanks() && net.arcaniax.liquidtanks.object.LiquidTankAPI.isLiquidTank(block.getLocation()))
|
||||
@ -143,125 +141,4 @@ public class BlockListeners implements Listener {
|
||||
|
||||
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||
}
|
||||
|
||||
private void handleSyncTouch(BlockBreakEvent event) {
|
||||
if (!Methods.isSync(event.getPlayer())) return;
|
||||
|
||||
ItemStack tool = event.getPlayer().getInventory().getItemInHand();
|
||||
ItemMeta meta = tool.getItemMeta();
|
||||
Location location = null;
|
||||
|
||||
for (String lore : meta.getLore()) {
|
||||
if (!lore.contains(Methods.formatText("&aSync Touch"))) continue;
|
||||
String[] loreSplit = lore.split("~");
|
||||
location = Methods.unserializeLocation(loreSplit[0].replace(ChatColor.COLOR_CHAR + "", "")
|
||||
.replace("~", ""));
|
||||
break;
|
||||
}
|
||||
|
||||
Material material = event.getBlock().getType();
|
||||
|
||||
if (location == null
|
||||
|| material == Material.CHEST
|
||||
|| Settings.SYNC_TOUCH_BLACKLIST.getStringList().contains(event.getBlock().getType().name())
|
||||
|
||||
|| material.name().contains("SHULKER")
|
||||
|| material == CompatibleMaterial.SPAWNER.getMaterial()) {
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
|
||||
Player player = event.getPlayer();
|
||||
Collection<ItemStack> drops = event.getBlock().getDrops();
|
||||
if (drops.isEmpty()) {
|
||||
drops = new ArrayList<>();
|
||||
ItemStack itemStack = getOreDrop(CompatibleMaterial.getMaterial(material), random);
|
||||
if (itemStack != null)
|
||||
drops.add(getOreDrop(CompatibleMaterial.getMaterial(material), random));
|
||||
}
|
||||
if (meta.hasEnchant(Enchantment.SILK_TOUCH)) {
|
||||
ih.getInventory().addItem(new ItemStack(event.getBlock().getType(), 1, event.getBlock().getData()));
|
||||
} else {
|
||||
if (meta.hasEnchant(Enchantment.LOOT_BONUS_BLOCKS)) {
|
||||
int level = meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS);
|
||||
int dropAmount = calculateFortuneDrops(material, level, random);
|
||||
for (int i = 0; i < dropAmount; i++) {
|
||||
for (ItemStack is : drops) ih.getInventory().addItem(is);
|
||||
}
|
||||
} else {
|
||||
for (ItemStack is : drops) ih.getInventory().addItem(is);
|
||||
}
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||
event.setDropItems(false);
|
||||
return;
|
||||
}
|
||||
|
||||
event.isCancelled();
|
||||
player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability() + 1));
|
||||
if (player.getItemInHand().getDurability() >= player.getItemInHand().getType().getMaxDurability()) {
|
||||
player.getItemInHand().setType(null);
|
||||
}
|
||||
if (event.getExpToDrop() > 0)
|
||||
player.getWorld().spawn(event.getBlock().getLocation(), ExperienceOrb.class).setExperience(event.getExpToDrop());
|
||||
event.getBlock().setType(Material.AIR);
|
||||
|
||||
}
|
||||
|
||||
private int calculateFortuneDrops(Material material, int level, Random random) {
|
||||
if (material != CompatibleMaterial.COAL_ORE.getMaterial()
|
||||
&& material != CompatibleMaterial.DIAMOND_ORE.getMaterial()
|
||||
&& material != CompatibleMaterial.EMERALD_ORE.getMaterial()
|
||||
&& material != CompatibleMaterial.NETHER_QUARTZ_ORE.getMaterial()
|
||||
&& material != CompatibleMaterial.LAPIS_ORE.getMaterial()) return 1;
|
||||
if (level <= 0) return 1;
|
||||
int drops = random.nextInt(level + 2) - 1;
|
||||
if (drops < 0) drops = 0;
|
||||
return applyLapisDrops(material, random) * (drops + 1);
|
||||
}
|
||||
|
||||
private int applyLapisDrops(Material material, Random random) {
|
||||
return material == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1;
|
||||
}
|
||||
|
||||
private ItemStack getOreDrop(CompatibleMaterial material, Random random) {
|
||||
ItemStack item = null;
|
||||
switch (material) {
|
||||
case COAL_ORE:
|
||||
item = CompatibleMaterial.COAL.getItem();
|
||||
break;
|
||||
case DIAMOND_ORE:
|
||||
item = CompatibleMaterial.DIAMOND.getItem();
|
||||
break;
|
||||
case EMERALD_ORE:
|
||||
item = CompatibleMaterial.EMERALD.getItem();
|
||||
break;
|
||||
case GOLD_ORE:
|
||||
item = CompatibleMaterial.GOLD_ORE.getItem();
|
||||
break;
|
||||
case IRON_ORE:
|
||||
item = CompatibleMaterial.IRON_ORE.getItem();
|
||||
break;
|
||||
case LAPIS_ORE:
|
||||
item = CompatibleMaterial.LAPIS_LAZULI.getItem();
|
||||
break;
|
||||
case NETHER_QUARTZ_ORE:
|
||||
item = CompatibleMaterial.QUARTZ.getItem();
|
||||
break;
|
||||
case REDSTONE_ORE:
|
||||
item = CompatibleMaterial.REDSTONE.getItem();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (material) {
|
||||
case LAPIS_ORE:
|
||||
item.setAmount(random.nextInt((9 - 4) + 1) + 4);
|
||||
break;
|
||||
case REDSTONE_ORE:
|
||||
item.setAmount(random.nextInt((5 - 4) + 1) + 4);
|
||||
break;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
@ -1,69 +1,13 @@
|
||||
package com.songoda.epichoppers.listeners;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleSuction;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
private final EpicHoppers instance;
|
||||
private Map<UUID, Player> ents = new HashMap<>();
|
||||
|
||||
public EntityListeners(EpicHoppers instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDed(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player)) return;
|
||||
Player p = (Player) event.getDamager();
|
||||
if (!Methods.isSync(p)) return;
|
||||
double d = ((LivingEntity) event.getEntity()).getHealth() - event.getDamage();
|
||||
if (d < 1) {
|
||||
ents.put(event.getEntity().getUniqueId(), p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrop(EntityDeathEvent event) {
|
||||
if (!ents.containsKey(event.getEntity().getUniqueId())) return;
|
||||
Player p = ents.get(event.getEntity().getUniqueId());
|
||||
|
||||
ItemStack item = p.getItemInHand();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (!meta.hasLore()) return;
|
||||
String str = meta.getLore().get(0).split("~")[0].replaceAll("§", "");
|
||||
if (!str.contains(":")) return;
|
||||
Location location = Methods.unserializeLocation(str);
|
||||
if (location.getBlock().getType() != Material.CHEST) return;
|
||||
InventoryHolder ih = (InventoryHolder) location.getBlock().getState();
|
||||
for (ItemStack is : event.getDrops()) {
|
||||
Map<Integer, ItemStack> notDropped = ih.getInventory().addItem(is);
|
||||
if (!notDropped.isEmpty())
|
||||
location.getWorld().dropItemNaturally(event.getEntity().getLocation(), new ArrayList<>(notDropped.values()).get(0));
|
||||
}
|
||||
event.getDrops().clear();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPickup(PlayerPickupItemEvent event) {
|
||||
if (ModuleSuction.isBlacklisted(event.getItem().getUniqueId()))
|
||||
|
@ -64,29 +64,6 @@ public class InteractListeners implements Listener {
|
||||
if (WorldGuardHook.isInteractAllowed(event.getClickedBlock().getLocation()))
|
||||
return;
|
||||
|
||||
if (event.getClickedBlock().getType() == Material.CHEST && Methods.isSync(player)) {
|
||||
ItemStack item = event.getPlayer().getInventory().getItemInHand();
|
||||
boolean isLinked = false;
|
||||
|
||||
for (String lore : item.getItemMeta().getLore()) {
|
||||
if (!lore.contains(Methods.formatText("&aSync Touch"))) continue;
|
||||
isLinked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isLinked) {
|
||||
instance.getLocale().getMessage("event.hopper.desyncchest")
|
||||
.processPlaceholder("name", item.getType().toString()).sendPrefixedMessage(player);
|
||||
instance.enchantmentHandler.createSyncTouch(item, null);
|
||||
} else {
|
||||
instance.getLocale().getMessage("event.hopper.syncchest")
|
||||
.processPlaceholder("name", item.getType().toString()).sendPrefixedMessage(player);
|
||||
instance.enchantmentHandler.createSyncTouch(item, event.getClickedBlock());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
|
||||
if (playerData.getSyncType() == null) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.songoda.epichoppers.listeners;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppers;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -15,31 +14,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private final EpicHoppers instance;
|
||||
|
||||
public InventoryListeners(EpicHoppers instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (event.getCurrentItem() == null) return;
|
||||
|
||||
if (event.getCursor() != null && event.getCurrentItem() != null) {
|
||||
ItemStack c = event.getCursor();
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (c.hasItemMeta()
|
||||
&& c.getItemMeta().hasLore()
|
||||
&& c.getType() == Material.ENCHANTED_BOOK
|
||||
&& (item.getType().name().toUpperCase().contains("AXE") || item.getType().name().toUpperCase().contains("SHOVEL") || item.getType().name().toUpperCase().contains("SWORD"))
|
||||
&& c.getItemMeta().getLore().equals(instance.enchantmentHandler.getbook().getItemMeta().getLore())) {
|
||||
instance.enchantmentHandler.createSyncTouch(item, null);
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
|
||||
|
||||
if (!event.getCurrentItem().hasItemMeta()) return;
|
||||
|
@ -29,20 +29,6 @@ public class Methods {
|
||||
|
||||
private static final Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
public static boolean isSync(Player p) {
|
||||
if (p.getItemInHand().hasItemMeta()
|
||||
&& p.getItemInHand().getType() != Material.AIR
|
||||
&& p.getItemInHand().getType() != Material.ENCHANTED_BOOK
|
||||
&& p.getItemInHand().getItemMeta().hasLore()) {
|
||||
for (String str : p.getItemInHand().getItemMeta().getLore()) {
|
||||
if (str.contains(Methods.formatText("&7Sync Touch")) || str.contains(Methods.formatText("&aSync Touch"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
return is1.getType() == is2.getType();
|
||||
|
Loading…
Reference in New Issue
Block a user