mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
split playerListener into two listeners so one can be disabled by MCore
MMOCore is going to have custom mitigation formulas, MI must not interfere
This commit is contained in:
parent
6f38f52902
commit
f05e4fd110
@ -1,416 +1,418 @@
|
||||
package net.Indyuce.mmoitems;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.command.AdvancedWorkbenchCommand;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommand;
|
||||
import net.Indyuce.mmoitems.command.UpdateItemCommand;
|
||||
import net.Indyuce.mmoitems.command.completion.MMOItemsCompletion;
|
||||
import net.Indyuce.mmoitems.command.completion.UpdateItemCompletion;
|
||||
import net.Indyuce.mmoitems.comp.AdvancedEnchantmentsHook;
|
||||
import net.Indyuce.mmoitems.comp.MMOItemsMetrics;
|
||||
import net.Indyuce.mmoitems.comp.MMOItemsRewardTypes;
|
||||
import net.Indyuce.mmoitems.comp.RealDualWieldHook;
|
||||
import net.Indyuce.mmoitems.comp.flags.DefaultFlags;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin;
|
||||
import net.Indyuce.mmoitems.comp.flags.ResidenceFlags;
|
||||
import net.Indyuce.mmoitems.comp.flags.WorldGuardFlags;
|
||||
import net.Indyuce.mmoitems.comp.holograms.CMIPlugin;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HologramSupport;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HologramsPlugin;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HolographicDisplaysPlugin;
|
||||
import net.Indyuce.mmoitems.comp.inventory.DefaultPlayerInventory;
|
||||
import net.Indyuce.mmoitems.comp.inventory.PlayerInventory;
|
||||
import net.Indyuce.mmoitems.comp.inventory.RPGInventoryHook;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.ItemGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.NoGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader;
|
||||
import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsHook;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.DefaultParser;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.PlaceholderAPIParser;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.PlaceholderParser;
|
||||
import net.Indyuce.mmoitems.comp.rpg.DefaultHook;
|
||||
import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import net.Indyuce.mmoitems.gui.listener.GuiListener;
|
||||
import net.Indyuce.mmoitems.listener.AdvancedWorkbenchListener;
|
||||
import net.Indyuce.mmoitems.listener.CustomDurability;
|
||||
import net.Indyuce.mmoitems.listener.DisableInteractions;
|
||||
import net.Indyuce.mmoitems.listener.ElementListener;
|
||||
import net.Indyuce.mmoitems.listener.ItemUse;
|
||||
import net.Indyuce.mmoitems.listener.PlayerListener;
|
||||
import net.Indyuce.mmoitems.listener.version.Listener_v1_13;
|
||||
import net.Indyuce.mmoitems.manager.AbilityManager;
|
||||
import net.Indyuce.mmoitems.manager.ConfigManager;
|
||||
import net.Indyuce.mmoitems.manager.CraftingManager;
|
||||
import net.Indyuce.mmoitems.manager.DamageManager;
|
||||
import net.Indyuce.mmoitems.manager.DropTableManager;
|
||||
import net.Indyuce.mmoitems.manager.EntityManager;
|
||||
import net.Indyuce.mmoitems.manager.ItemManager;
|
||||
import net.Indyuce.mmoitems.manager.PluginUpdateManager;
|
||||
import net.Indyuce.mmoitems.manager.RecipeManager;
|
||||
import net.Indyuce.mmoitems.manager.SetManager;
|
||||
import net.Indyuce.mmoitems.manager.StatManager;
|
||||
import net.Indyuce.mmoitems.manager.TierManager;
|
||||
import net.Indyuce.mmoitems.manager.TypeManager;
|
||||
import net.Indyuce.mmoitems.manager.UpdaterManager;
|
||||
import net.Indyuce.mmoitems.manager.UpgradeManager;
|
||||
import net.Indyuce.mmoitems.version.ServerVersion;
|
||||
import net.Indyuce.mmoitems.version.SpigotPlugin;
|
||||
import net.Indyuce.mmoitems.version.nms.NMSHandler;
|
||||
|
||||
public class MMOItems extends JavaPlugin {
|
||||
public static MMOItems plugin;
|
||||
|
||||
private ServerVersion version;
|
||||
private RecipeManager recipeManager;
|
||||
private ConfigManager configManager;
|
||||
private StatManager statManager;
|
||||
private EntityManager entityManager;
|
||||
private DamageManager damageManager;
|
||||
private DropTableManager dropTableManager;
|
||||
private UpdaterManager itemUpdaterManager;
|
||||
private TypeManager typeManager;
|
||||
private TierManager tierManager;
|
||||
private ItemManager itemManager;
|
||||
private SetManager setManager;
|
||||
private UpgradeManager upgradeManager;
|
||||
private AbilityManager abilityManager = new AbilityManager();
|
||||
private CraftingManager stationRecipeManager = new CraftingManager();
|
||||
private PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
|
||||
|
||||
private RPGHandler rpgPlugin;
|
||||
private PlaceholderParser placeholderParser = new DefaultParser();
|
||||
private HologramSupport hologramSupport;
|
||||
private FlagPlugin flagPlugin = new DefaultFlags();
|
||||
private PlayerInventory inventory = new DefaultPlayerInventory();
|
||||
private NMSHandler nms;
|
||||
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
version = new ServerVersion(Bukkit.getServer().getClass());
|
||||
|
||||
try {
|
||||
getLogger().log(Level.INFO, "Detected Bukkit Version: " + version.toString());
|
||||
nms = (NMSHandler) Class.forName("net.Indyuce.mmoitems.version.nms.NMSHandler_" + version.toString().substring(1)).newInstance();
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.INFO, "Your server version is not compatible.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
// nms = new NMSHandler_Reflection();
|
||||
}
|
||||
|
||||
try {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null && version.isStrictlyHigher(1, 12)) {
|
||||
flagPlugin = new WorldGuardFlags();
|
||||
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7+");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
|
||||
new MMOCoreMMOLoader();
|
||||
|
||||
saveDefaultConfig();
|
||||
statManager = new StatManager();
|
||||
typeManager = new TypeManager();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
new SpigotPlugin(39267, this).checkForUpdate();
|
||||
|
||||
new MMOItemsMetrics();
|
||||
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
|
||||
abilityManager.registerDefaultAbilities();
|
||||
abilityManager.stopRegistration();
|
||||
|
||||
configManager = new ConfigManager();
|
||||
itemManager = new ItemManager();
|
||||
tierManager = new TierManager();
|
||||
setManager = new SetManager();
|
||||
upgradeManager = new UpgradeManager();
|
||||
|
||||
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
|
||||
stationRecipeManager.reload();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(entityManager = new EntityManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(damageManager = new DamageManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(dropTableManager = new DropTableManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(itemUpdaterManager = new UpdaterManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemUse(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomDurability(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DisableInteractions(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
|
||||
if (version.isStrictlyHigher(1, 12))
|
||||
Bukkit.getPluginManager().registerEvents(new Listener_v1_13(), this);
|
||||
|
||||
/*
|
||||
* this class implements the Listener, if the option
|
||||
* perm-effects-apply-on-move is enabled the loop will not apply perm
|
||||
* effects and this class will be registered as a listener. starts with
|
||||
* a 5s delay to let the other plugins time to load nicely
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateEffects()), 100, 20);
|
||||
|
||||
/*
|
||||
* this tasks updates twice a second player inventories on the server.
|
||||
* allows now to use a glitchy itemEquipEvent. must be called after
|
||||
* loading the config since it checks for a config option
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).checkForInventoryUpdate()), 100, getConfig().getInt("inventory-update-delay"));
|
||||
|
||||
if (!getConfig().getBoolean("disable-craftings.advanced"))
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancedWorkbenchListener(), this);
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("Residence") != null) {
|
||||
flagPlugin = new ResidenceFlags();
|
||||
getLogger().log(Level.INFO, "Hooked onto Residence");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("RPGInventory") != null) {
|
||||
inventory = new RPGInventoryHook(this);
|
||||
getLogger().log(Level.INFO, "Hooked onto RPGInventory");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto AdvancedEnchantments");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("HolographicDisplays") != null) {
|
||||
hologramSupport = new HolographicDisplaysPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto HolographicDisplays");
|
||||
} else if (Bukkit.getPluginManager().getPlugin("CMI") != null) {
|
||||
hologramSupport = new CMIPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto CMI Holograms");
|
||||
} else if (Bukkit.getPluginManager().getPlugin("Holograms") != null) {
|
||||
hologramSupport = new HologramsPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto Holograms");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
getLogger().log(Level.INFO, "Hooked onto PlaceholderAPI");
|
||||
placeholderParser = new PlaceholderAPIParser();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new MythicMobsHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto MythicMobs");
|
||||
}
|
||||
|
||||
if (getConfig().getBoolean("item-glow")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("GlowAPI") != null && Bukkit.getPluginManager().getPlugin("PacketListenerApi") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new ItemGlowListener(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto GlowAPI (Item Glow)");
|
||||
} else
|
||||
Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("RealDualWield") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new RealDualWieldHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto RealDualWield");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
|
||||
|
||||
/*
|
||||
* runs async because of plugin loading order issues, this way it
|
||||
* only registers after BossShop is initialized
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
new MMOItemsRewardTypes().register();
|
||||
getLogger().log(Level.INFO, "Hooked onto BossShopPro (async)");
|
||||
});
|
||||
}
|
||||
|
||||
findRpgPlugin();
|
||||
|
||||
// compatibility with /reload
|
||||
Bukkit.getOnlinePlayers().forEach(player -> PlayerData.load(player));
|
||||
|
||||
// advanced recipes
|
||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||
recipeManager = new RecipeManager();
|
||||
|
||||
// commands
|
||||
getCommand("mmoitems").setExecutor(new MMOItemsCommand());
|
||||
getCommand("advancedworkbench").setExecutor(new AdvancedWorkbenchCommand());
|
||||
getCommand("updateitem").setExecutor(new UpdateItemCommand());
|
||||
|
||||
// tab completion
|
||||
getCommand("mmoitems").setTabCompleter(new MMOItemsCompletion());
|
||||
getCommand("updateitem").setTabCompleter(new UpdateItemCompletion());
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
// save player data
|
||||
PlayerData.getLoaded().forEach(data -> data.save());
|
||||
|
||||
// save item updater data
|
||||
ConfigFile updater = new ConfigFile("/dynamic", "updater");
|
||||
updater.getConfig().getKeys(false).forEach(key -> updater.getConfig().set(key, null));
|
||||
itemUpdaterManager.getDatas().forEach(data -> data.save(updater.getConfig()));
|
||||
updater.save();
|
||||
|
||||
// drop abandonned soulbound items
|
||||
SoulboundInfo.getAbandonnedInfo().forEach(info -> info.dropItems());
|
||||
|
||||
// close inventories
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory)
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return ChatColor.YELLOW + "MI" + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY;
|
||||
}
|
||||
|
||||
public File getJarFile() {
|
||||
return plugin.getFile();
|
||||
}
|
||||
|
||||
public CraftingManager getCrafting() {
|
||||
return stationRecipeManager;
|
||||
}
|
||||
|
||||
public UpdaterManager getUpdater() {
|
||||
return itemUpdaterManager;
|
||||
}
|
||||
|
||||
public SetManager getSets() {
|
||||
return setManager;
|
||||
}
|
||||
|
||||
public NMSHandler getNMS() {
|
||||
return nms;
|
||||
}
|
||||
|
||||
public FlagPlugin getFlags() {
|
||||
return flagPlugin;
|
||||
}
|
||||
|
||||
public void setFlags(FlagPlugin value) {
|
||||
flagPlugin = value;
|
||||
}
|
||||
|
||||
public RPGHandler getRPG() {
|
||||
return rpgPlugin;
|
||||
}
|
||||
|
||||
public void setRPG(RPGHandler handler) {
|
||||
rpgPlugin = handler;
|
||||
}
|
||||
|
||||
public PluginUpdateManager getUpdates() {
|
||||
return pluginUpdateManager;
|
||||
}
|
||||
|
||||
public PlayerInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setPlayerInventory(PlayerInventory value) {
|
||||
inventory = value;
|
||||
}
|
||||
|
||||
public ServerVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public StatManager getStats() {
|
||||
return statManager;
|
||||
}
|
||||
|
||||
public TierManager getTiers() {
|
||||
return tierManager;
|
||||
}
|
||||
|
||||
public EntityManager getEntities() {
|
||||
return entityManager;
|
||||
}
|
||||
|
||||
public DamageManager getDamage() {
|
||||
return damageManager;
|
||||
}
|
||||
|
||||
public DropTableManager getDropTables() {
|
||||
return dropTableManager;
|
||||
}
|
||||
|
||||
public AbilityManager getAbilities() {
|
||||
return abilityManager;
|
||||
}
|
||||
|
||||
public RecipeManager getRecipes() {
|
||||
return recipeManager;
|
||||
}
|
||||
|
||||
public ConfigManager getLanguage() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
public TypeManager getTypes() {
|
||||
return typeManager;
|
||||
}
|
||||
|
||||
public UpgradeManager getUpgrades() {
|
||||
return upgradeManager;
|
||||
}
|
||||
|
||||
public PlaceholderParser getPlaceholderParser() {
|
||||
return placeholderParser;
|
||||
}
|
||||
|
||||
public HologramSupport getHolograms() {
|
||||
return hologramSupport;
|
||||
}
|
||||
|
||||
public ItemManager getItems() {
|
||||
return itemManager;
|
||||
}
|
||||
|
||||
public void findRpgPlugin() {
|
||||
if (rpgPlugin != null)
|
||||
return;
|
||||
|
||||
for (RPGHandler.PluginEnum plugin : RPGHandler.PluginEnum.values())
|
||||
if (Bukkit.getPluginManager().getPlugin(plugin.getName()) != null) {
|
||||
setRPG(plugin.load());
|
||||
getLogger().log(Level.INFO, "Hooked onto " + plugin.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
setRPG(new DefaultHook());
|
||||
}
|
||||
|
||||
public boolean isBlacklisted(Material material) {
|
||||
return getConfig().getStringList("block-blacklist").contains(material.name());
|
||||
}
|
||||
|
||||
public void debug(Object... message) {
|
||||
if (!getConfig().getBoolean("debug"))
|
||||
return;
|
||||
|
||||
for (Object line : message) {
|
||||
getLogger().log(Level.INFO, "Debug> " + line.toString());
|
||||
Bukkit.getOnlinePlayers().forEach(online -> online.sendMessage(ChatColor.YELLOW + "Debug> " + ChatColor.WHITE + line.toString()));
|
||||
}
|
||||
}
|
||||
package net.Indyuce.mmoitems;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.command.AdvancedWorkbenchCommand;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommand;
|
||||
import net.Indyuce.mmoitems.command.UpdateItemCommand;
|
||||
import net.Indyuce.mmoitems.command.completion.MMOItemsCompletion;
|
||||
import net.Indyuce.mmoitems.command.completion.UpdateItemCompletion;
|
||||
import net.Indyuce.mmoitems.comp.AdvancedEnchantmentsHook;
|
||||
import net.Indyuce.mmoitems.comp.MMOItemsMetrics;
|
||||
import net.Indyuce.mmoitems.comp.MMOItemsRewardTypes;
|
||||
import net.Indyuce.mmoitems.comp.RealDualWieldHook;
|
||||
import net.Indyuce.mmoitems.comp.flags.DefaultFlags;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin;
|
||||
import net.Indyuce.mmoitems.comp.flags.ResidenceFlags;
|
||||
import net.Indyuce.mmoitems.comp.flags.WorldGuardFlags;
|
||||
import net.Indyuce.mmoitems.comp.holograms.CMIPlugin;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HologramSupport;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HologramsPlugin;
|
||||
import net.Indyuce.mmoitems.comp.holograms.HolographicDisplaysPlugin;
|
||||
import net.Indyuce.mmoitems.comp.inventory.DefaultPlayerInventory;
|
||||
import net.Indyuce.mmoitems.comp.inventory.PlayerInventory;
|
||||
import net.Indyuce.mmoitems.comp.inventory.RPGInventoryHook;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.ItemGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.NoGlowListener;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader;
|
||||
import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsHook;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.DefaultParser;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.PlaceholderAPIParser;
|
||||
import net.Indyuce.mmoitems.comp.placeholderapi.PlaceholderParser;
|
||||
import net.Indyuce.mmoitems.comp.rpg.DefaultHook;
|
||||
import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import net.Indyuce.mmoitems.gui.listener.GuiListener;
|
||||
import net.Indyuce.mmoitems.listener.AdvancedWorkbenchListener;
|
||||
import net.Indyuce.mmoitems.listener.CustomDurability;
|
||||
import net.Indyuce.mmoitems.listener.DisableInteractions;
|
||||
import net.Indyuce.mmoitems.listener.ElementListener;
|
||||
import net.Indyuce.mmoitems.listener.ItemUse;
|
||||
import net.Indyuce.mmoitems.listener.MitigationListener;
|
||||
import net.Indyuce.mmoitems.listener.PlayerListener;
|
||||
import net.Indyuce.mmoitems.listener.version.Listener_v1_13;
|
||||
import net.Indyuce.mmoitems.manager.AbilityManager;
|
||||
import net.Indyuce.mmoitems.manager.ConfigManager;
|
||||
import net.Indyuce.mmoitems.manager.CraftingManager;
|
||||
import net.Indyuce.mmoitems.manager.DamageManager;
|
||||
import net.Indyuce.mmoitems.manager.DropTableManager;
|
||||
import net.Indyuce.mmoitems.manager.EntityManager;
|
||||
import net.Indyuce.mmoitems.manager.ItemManager;
|
||||
import net.Indyuce.mmoitems.manager.PluginUpdateManager;
|
||||
import net.Indyuce.mmoitems.manager.RecipeManager;
|
||||
import net.Indyuce.mmoitems.manager.SetManager;
|
||||
import net.Indyuce.mmoitems.manager.StatManager;
|
||||
import net.Indyuce.mmoitems.manager.TierManager;
|
||||
import net.Indyuce.mmoitems.manager.TypeManager;
|
||||
import net.Indyuce.mmoitems.manager.UpdaterManager;
|
||||
import net.Indyuce.mmoitems.manager.UpgradeManager;
|
||||
import net.Indyuce.mmoitems.version.ServerVersion;
|
||||
import net.Indyuce.mmoitems.version.SpigotPlugin;
|
||||
import net.Indyuce.mmoitems.version.nms.NMSHandler;
|
||||
|
||||
public class MMOItems extends JavaPlugin {
|
||||
public static MMOItems plugin;
|
||||
|
||||
private ServerVersion version;
|
||||
private RecipeManager recipeManager;
|
||||
private ConfigManager configManager;
|
||||
private StatManager statManager;
|
||||
private EntityManager entityManager;
|
||||
private DamageManager damageManager;
|
||||
private DropTableManager dropTableManager;
|
||||
private UpdaterManager itemUpdaterManager;
|
||||
private TypeManager typeManager;
|
||||
private TierManager tierManager;
|
||||
private ItemManager itemManager;
|
||||
private SetManager setManager;
|
||||
private UpgradeManager upgradeManager;
|
||||
private AbilityManager abilityManager = new AbilityManager();
|
||||
private CraftingManager stationRecipeManager = new CraftingManager();
|
||||
private PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
|
||||
|
||||
private RPGHandler rpgPlugin;
|
||||
private PlaceholderParser placeholderParser = new DefaultParser();
|
||||
private HologramSupport hologramSupport;
|
||||
private FlagPlugin flagPlugin = new DefaultFlags();
|
||||
private PlayerInventory inventory = new DefaultPlayerInventory();
|
||||
private NMSHandler nms;
|
||||
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
version = new ServerVersion(Bukkit.getServer().getClass());
|
||||
|
||||
try {
|
||||
getLogger().log(Level.INFO, "Detected Bukkit Version: " + version.toString());
|
||||
nms = (NMSHandler) Class.forName("net.Indyuce.mmoitems.version.nms.NMSHandler_" + version.toString().substring(1)).newInstance();
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.INFO, "Your server version is not compatible.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
// nms = new NMSHandler_Reflection();
|
||||
}
|
||||
|
||||
try {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null && version.isStrictlyHigher(1, 12)) {
|
||||
flagPlugin = new WorldGuardFlags();
|
||||
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7+");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
|
||||
new MMOCoreMMOLoader();
|
||||
|
||||
saveDefaultConfig();
|
||||
statManager = new StatManager();
|
||||
typeManager = new TypeManager();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
new SpigotPlugin(39267, this).checkForUpdate();
|
||||
|
||||
new MMOItemsMetrics();
|
||||
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
|
||||
abilityManager.registerDefaultAbilities();
|
||||
abilityManager.stopRegistration();
|
||||
|
||||
configManager = new ConfigManager();
|
||||
itemManager = new ItemManager();
|
||||
tierManager = new TierManager();
|
||||
setManager = new SetManager();
|
||||
upgradeManager = new UpgradeManager();
|
||||
|
||||
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
|
||||
stationRecipeManager.reload();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(entityManager = new EntityManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(damageManager = new DamageManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(dropTableManager = new DropTableManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(itemUpdaterManager = new UpdaterManager(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemUse(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MitigationListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomDurability(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DisableInteractions(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
|
||||
if (version.isStrictlyHigher(1, 12))
|
||||
Bukkit.getPluginManager().registerEvents(new Listener_v1_13(), this);
|
||||
|
||||
/*
|
||||
* this class implements the Listener, if the option
|
||||
* perm-effects-apply-on-move is enabled the loop will not apply perm
|
||||
* effects and this class will be registered as a listener. starts with
|
||||
* a 5s delay to let the other plugins time to load nicely
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateEffects()), 100, 20);
|
||||
|
||||
/*
|
||||
* this tasks updates twice a second player inventories on the server.
|
||||
* allows now to use a glitchy itemEquipEvent. must be called after
|
||||
* loading the config since it checks for a config option
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).checkForInventoryUpdate()), 100, getConfig().getInt("inventory-update-delay"));
|
||||
|
||||
if (!getConfig().getBoolean("disable-craftings.advanced"))
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancedWorkbenchListener(), this);
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("Residence") != null) {
|
||||
flagPlugin = new ResidenceFlags();
|
||||
getLogger().log(Level.INFO, "Hooked onto Residence");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("RPGInventory") != null) {
|
||||
inventory = new RPGInventoryHook(this);
|
||||
getLogger().log(Level.INFO, "Hooked onto RPGInventory");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto AdvancedEnchantments");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("HolographicDisplays") != null) {
|
||||
hologramSupport = new HolographicDisplaysPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto HolographicDisplays");
|
||||
} else if (Bukkit.getPluginManager().getPlugin("CMI") != null) {
|
||||
hologramSupport = new CMIPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto CMI Holograms");
|
||||
} else if (Bukkit.getPluginManager().getPlugin("Holograms") != null) {
|
||||
hologramSupport = new HologramsPlugin();
|
||||
getLogger().log(Level.INFO, "Hooked onto Holograms");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
getLogger().log(Level.INFO, "Hooked onto PlaceholderAPI");
|
||||
placeholderParser = new PlaceholderAPIParser();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new MythicMobsHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto MythicMobs");
|
||||
}
|
||||
|
||||
if (getConfig().getBoolean("item-glow")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("GlowAPI") != null && Bukkit.getPluginManager().getPlugin("PacketListenerApi") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new ItemGlowListener(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto GlowAPI (Item Glow)");
|
||||
} else
|
||||
Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("RealDualWield") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new RealDualWieldHook(), this);
|
||||
getLogger().log(Level.INFO, "Hooked onto RealDualWield");
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
|
||||
|
||||
/*
|
||||
* runs async because of plugin loading order issues, this way it
|
||||
* only registers after BossShop is initialized
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
new MMOItemsRewardTypes().register();
|
||||
getLogger().log(Level.INFO, "Hooked onto BossShopPro (async)");
|
||||
});
|
||||
}
|
||||
|
||||
findRpgPlugin();
|
||||
|
||||
// compatibility with /reload
|
||||
Bukkit.getOnlinePlayers().forEach(player -> PlayerData.load(player));
|
||||
|
||||
// advanced recipes
|
||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||
recipeManager = new RecipeManager();
|
||||
|
||||
// commands
|
||||
getCommand("mmoitems").setExecutor(new MMOItemsCommand());
|
||||
getCommand("advancedworkbench").setExecutor(new AdvancedWorkbenchCommand());
|
||||
getCommand("updateitem").setExecutor(new UpdateItemCommand());
|
||||
|
||||
// tab completion
|
||||
getCommand("mmoitems").setTabCompleter(new MMOItemsCompletion());
|
||||
getCommand("updateitem").setTabCompleter(new UpdateItemCompletion());
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
// save player data
|
||||
PlayerData.getLoaded().forEach(data -> data.save());
|
||||
|
||||
// save item updater data
|
||||
ConfigFile updater = new ConfigFile("/dynamic", "updater");
|
||||
updater.getConfig().getKeys(false).forEach(key -> updater.getConfig().set(key, null));
|
||||
itemUpdaterManager.getDatas().forEach(data -> data.save(updater.getConfig()));
|
||||
updater.save();
|
||||
|
||||
// drop abandonned soulbound items
|
||||
SoulboundInfo.getAbandonnedInfo().forEach(info -> info.dropItems());
|
||||
|
||||
// close inventories
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory)
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return ChatColor.YELLOW + "MI" + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY;
|
||||
}
|
||||
|
||||
public File getJarFile() {
|
||||
return plugin.getFile();
|
||||
}
|
||||
|
||||
public CraftingManager getCrafting() {
|
||||
return stationRecipeManager;
|
||||
}
|
||||
|
||||
public UpdaterManager getUpdater() {
|
||||
return itemUpdaterManager;
|
||||
}
|
||||
|
||||
public SetManager getSets() {
|
||||
return setManager;
|
||||
}
|
||||
|
||||
public NMSHandler getNMS() {
|
||||
return nms;
|
||||
}
|
||||
|
||||
public FlagPlugin getFlags() {
|
||||
return flagPlugin;
|
||||
}
|
||||
|
||||
public void setFlags(FlagPlugin value) {
|
||||
flagPlugin = value;
|
||||
}
|
||||
|
||||
public RPGHandler getRPG() {
|
||||
return rpgPlugin;
|
||||
}
|
||||
|
||||
public void setRPG(RPGHandler handler) {
|
||||
rpgPlugin = handler;
|
||||
}
|
||||
|
||||
public PluginUpdateManager getUpdates() {
|
||||
return pluginUpdateManager;
|
||||
}
|
||||
|
||||
public PlayerInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setPlayerInventory(PlayerInventory value) {
|
||||
inventory = value;
|
||||
}
|
||||
|
||||
public ServerVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public StatManager getStats() {
|
||||
return statManager;
|
||||
}
|
||||
|
||||
public TierManager getTiers() {
|
||||
return tierManager;
|
||||
}
|
||||
|
||||
public EntityManager getEntities() {
|
||||
return entityManager;
|
||||
}
|
||||
|
||||
public DamageManager getDamage() {
|
||||
return damageManager;
|
||||
}
|
||||
|
||||
public DropTableManager getDropTables() {
|
||||
return dropTableManager;
|
||||
}
|
||||
|
||||
public AbilityManager getAbilities() {
|
||||
return abilityManager;
|
||||
}
|
||||
|
||||
public RecipeManager getRecipes() {
|
||||
return recipeManager;
|
||||
}
|
||||
|
||||
public ConfigManager getLanguage() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
public TypeManager getTypes() {
|
||||
return typeManager;
|
||||
}
|
||||
|
||||
public UpgradeManager getUpgrades() {
|
||||
return upgradeManager;
|
||||
}
|
||||
|
||||
public PlaceholderParser getPlaceholderParser() {
|
||||
return placeholderParser;
|
||||
}
|
||||
|
||||
public HologramSupport getHolograms() {
|
||||
return hologramSupport;
|
||||
}
|
||||
|
||||
public ItemManager getItems() {
|
||||
return itemManager;
|
||||
}
|
||||
|
||||
public void findRpgPlugin() {
|
||||
if (rpgPlugin != null)
|
||||
return;
|
||||
|
||||
for (RPGHandler.PluginEnum plugin : RPGHandler.PluginEnum.values())
|
||||
if (Bukkit.getPluginManager().getPlugin(plugin.getName()) != null) {
|
||||
setRPG(plugin.load());
|
||||
getLogger().log(Level.INFO, "Hooked onto " + plugin.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
setRPG(new DefaultHook());
|
||||
}
|
||||
|
||||
public boolean isBlacklisted(Material material) {
|
||||
return getConfig().getStringList("block-blacklist").contains(material.name());
|
||||
}
|
||||
|
||||
public void debug(Object... message) {
|
||||
if (!getConfig().getBoolean("debug"))
|
||||
return;
|
||||
|
||||
for (Object line : message) {
|
||||
getLogger().log(Level.INFO, "Debug> " + line.toString());
|
||||
Bukkit.getOnlinePlayers().forEach(online -> online.sendMessage(ChatColor.YELLOW + "Debug> " + ChatColor.WHITE + line.toString()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +1,43 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.gui.AdvancedWorkbench;
|
||||
import net.Indyuce.mmoitems.version.VersionMaterial;
|
||||
|
||||
public class AdvancedWorkbenchListener implements Listener {
|
||||
@EventHandler
|
||||
public void a(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock().getType() != VersionMaterial.CRAFTING_TABLE.toMaterial())
|
||||
return;
|
||||
|
||||
boolean shiftClick = MMOItems.plugin.getConfig().getBoolean("advanced-workbench.open-when.shift-click");
|
||||
boolean simpleClick = MMOItems.plugin.getConfig().getBoolean("advanced-workbench.open-when.simple-click");
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if ((shiftClick && player.isSneaking()) || (simpleClick && !player.isSneaking())) {
|
||||
event.setCancelled(true);
|
||||
new AdvancedWorkbench(player).open();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void b(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv.getHolder() instanceof AdvancedWorkbench)
|
||||
for (int j : MMOItems.plugin.getRecipes().recipeSlots) {
|
||||
ItemStack drop = inv.getItem(j);
|
||||
if (drop != null)
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), drop);
|
||||
}
|
||||
}
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.gui.AdvancedWorkbench;
|
||||
import net.Indyuce.mmoitems.version.VersionMaterial;
|
||||
|
||||
public class AdvancedWorkbenchListener implements Listener {
|
||||
@EventHandler
|
||||
public void a(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock().getType() != VersionMaterial.CRAFTING_TABLE.toMaterial())
|
||||
return;
|
||||
|
||||
boolean shiftClick = MMOItems.plugin.getConfig().getBoolean("advanced-workbench.open-when.shift-click");
|
||||
boolean simpleClick = MMOItems.plugin.getConfig().getBoolean("advanced-workbench.open-when.simple-click");
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if ((shiftClick && player.isSneaking()) || (simpleClick && !player.isSneaking())) {
|
||||
event.setCancelled(true);
|
||||
new AdvancedWorkbench(player).open();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void b(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv.getHolder() instanceof AdvancedWorkbench)
|
||||
for (int j : MMOItems.plugin.getRecipes().recipeSlots) {
|
||||
ItemStack drop = inv.getItem(j);
|
||||
if (drop != null)
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), drop);
|
||||
}
|
||||
}
|
||||
}
|
99
src/net/Indyuce/mmoitems/listener/MitigationListener.java
Normal file
99
src/net/Indyuce/mmoitems/listener/MitigationListener.java
Normal file
@ -0,0 +1,99 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
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.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Message;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.Indyuce.mmoitems.version.VersionSound;
|
||||
|
||||
public class MitigationListener implements Listener {
|
||||
private static final Random random = new Random();
|
||||
private static final List<DamageCause> mitigationCauses = Arrays.asList(DamageCause.PROJECTILE, DamageCause.ENTITY_ATTACK, DamageCause.ENTITY_EXPLOSION, DamageCause.ENTITY_SWEEP_ATTACK);
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void a(EntityDamageEvent event) {
|
||||
if (event.isCancelled() || !(event.getEntity() instanceof Player) || !mitigationCauses.contains(event.getCause()) || event.getEntity().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
PlayerStats stats = playerData.getStats();
|
||||
|
||||
// dodging
|
||||
double dodgeRating = Math.min(stats.getStat(ItemStat.DODGE_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.dodge.rating-max")) / 100;
|
||||
if (random.nextDouble() < dodgeRating && !playerData.isOnCooldown(CooldownType.DODGE)) {
|
||||
playerData.applyCooldown(CooldownType.DODGE, stats.getStat(ItemStat.DODGE_COOLDOWN_REDUCTION));
|
||||
event.setCancelled(true);
|
||||
|
||||
Message.ATTACK_DODGED.format(ChatColor.RED).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), VersionSound.ENTITY_ENDER_DRAGON_FLAP.toSound(), 2, 1);
|
||||
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 16, 0, 0, 0, .06);
|
||||
if (MMOItems.plugin.getLanguage().dodgeKnockbackEnabled)
|
||||
player.setVelocity(getVector(player, event).multiply(.85 * MMOItems.plugin.getLanguage().dodgeKnockbackForce).setY(.3));
|
||||
return;
|
||||
}
|
||||
|
||||
// parrying
|
||||
double parryRating = Math.min(stats.getStat(ItemStat.PARRY_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.parry.rating-max")) / 100;
|
||||
if (random.nextDouble() < parryRating && !playerData.isOnCooldown(CooldownType.PARRY)) {
|
||||
playerData.applyCooldown(CooldownType.PARRY, stats.getStat(ItemStat.PARRY_COOLDOWN_REDUCTION));
|
||||
event.setCancelled(true);
|
||||
|
||||
Message.ATTACK_PARRIED.format(ChatColor.RED).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), VersionSound.ENTITY_ENDER_DRAGON_FLAP.toSound(), 2, 1);
|
||||
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 16, 0, 0, 0, .06);
|
||||
if (event instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) event).getDamager() instanceof LivingEntity) {
|
||||
LivingEntity attacker = (LivingEntity) ((EntityDamageByEntityEvent) event).getDamager();
|
||||
attacker.setVelocity(attacker.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().setY(.35).multiply(MMOItems.plugin.getConfig().getDouble("mitigation.parry.knockback-force")));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// blocking
|
||||
double blockRating = Math.min(stats.getStat(ItemStat.BLOCK_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.block.rating-max")) / 100;
|
||||
if (random.nextDouble() < blockRating && !playerData.isOnCooldown(CooldownType.BLOCK)) {
|
||||
double blockPower = Math.min(MMOItems.plugin.getConfig().getDouble("mitigation.block.power.default") + stats.getStat(ItemStat.BLOCK_POWER), MMOItems.plugin.getConfig().getDouble("mitigation.block.power.max")) / 100;
|
||||
playerData.applyCooldown(CooldownType.BLOCK, stats.getStat(ItemStat.BLOCK_COOLDOWN_REDUCTION));
|
||||
event.setDamage(event.getDamage() * (1 - blockPower));
|
||||
|
||||
Message.ATTACK_BLOCKED.format(ChatColor.RED, "#percent#", new DecimalFormat("0.#").format(blockPower * 100)).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 2, 1);
|
||||
|
||||
double yaw = getYaw(player, getVector(player, event)) + 95;
|
||||
for (double j = yaw - 90; j < yaw + 90; j += 5)
|
||||
for (double y = 0; y < 2; y += .1)
|
||||
MMOItems.plugin.getVersion().getVersionWrapper().spawnParticle(Particle.REDSTONE, player.getLocation().clone().add(Math.cos(Math.toRadians(j)) * .7, y, Math.sin(Math.toRadians(j)) * .7), Color.GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getVector(Player player, EntityDamageEvent event) {
|
||||
return event instanceof EntityDamageByEntityEvent ? player.getLocation().subtract(((EntityDamageByEntityEvent) event).getDamager().getLocation()).toVector().normalize() : player.getEyeLocation().getDirection();
|
||||
}
|
||||
|
||||
private double getYaw(Entity player, Vector vec) {
|
||||
return new Location(player.getWorld(), vec.getX(), vec.getY(), vec.getZ()).setDirection(vec).getYaw();
|
||||
}
|
||||
}
|
@ -1,212 +1,132 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
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.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.ability.Magical_Shield;
|
||||
import net.Indyuce.mmoitems.api.Ability.CastingMode;
|
||||
import net.Indyuce.mmoitems.api.AttackResult;
|
||||
import net.Indyuce.mmoitems.api.Message;
|
||||
import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.Indyuce.mmoitems.version.VersionSound;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private static final Random random = new Random();
|
||||
private static final List<DamageCause> mitigationCauses = Arrays.asList(DamageCause.PROJECTILE, DamageCause.ENTITY_ATTACK, DamageCause.ENTITY_EXPLOSION, DamageCause.ENTITY_SWEEP_ATTACK);
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void a(EntityDamageEvent event) {
|
||||
if (event.isCancelled() || !(event.getEntity() instanceof Player) || !mitigationCauses.contains(event.getCause()) || event.getEntity().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
PlayerStats stats = playerData.getStats();
|
||||
|
||||
// dodging
|
||||
double dodgeRating = Math.min(stats.getStat(ItemStat.DODGE_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.dodge.rating-max")) / 100;
|
||||
if (random.nextDouble() < dodgeRating && !playerData.isOnCooldown(CooldownType.DODGE)) {
|
||||
playerData.applyCooldown(CooldownType.DODGE, stats.getStat(ItemStat.DODGE_COOLDOWN_REDUCTION));
|
||||
event.setCancelled(true);
|
||||
|
||||
Message.ATTACK_DODGED.format(ChatColor.RED).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), VersionSound.ENTITY_ENDER_DRAGON_FLAP.toSound(), 2, 1);
|
||||
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 16, 0, 0, 0, .06);
|
||||
if (MMOItems.plugin.getLanguage().dodgeKnockbackEnabled)
|
||||
player.setVelocity(getVector(player, event).multiply(.85 * MMOItems.plugin.getLanguage().dodgeKnockbackForce).setY(.3));
|
||||
return;
|
||||
}
|
||||
|
||||
// parrying
|
||||
double parryRating = Math.min(stats.getStat(ItemStat.PARRY_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.parry.rating-max")) / 100;
|
||||
if (random.nextDouble() < parryRating && !playerData.isOnCooldown(CooldownType.PARRY)) {
|
||||
playerData.applyCooldown(CooldownType.PARRY, stats.getStat(ItemStat.PARRY_COOLDOWN_REDUCTION));
|
||||
event.setCancelled(true);
|
||||
|
||||
Message.ATTACK_PARRIED.format(ChatColor.RED).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), VersionSound.ENTITY_ENDER_DRAGON_FLAP.toSound(), 2, 1);
|
||||
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 16, 0, 0, 0, .06);
|
||||
if (event instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) event).getDamager() instanceof LivingEntity) {
|
||||
LivingEntity attacker = (LivingEntity) ((EntityDamageByEntityEvent) event).getDamager();
|
||||
attacker.setVelocity(attacker.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().setY(.35).multiply(MMOItems.plugin.getConfig().getDouble("mitigation.parry.knockback-force")));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// blocking
|
||||
double blockRating = Math.min(stats.getStat(ItemStat.BLOCK_RATING), MMOItems.plugin.getConfig().getDouble("mitigation.block.rating-max")) / 100;
|
||||
if (random.nextDouble() < blockRating && !playerData.isOnCooldown(CooldownType.BLOCK)) {
|
||||
double blockPower = Math.min(MMOItems.plugin.getConfig().getDouble("mitigation.block.power.default") + stats.getStat(ItemStat.BLOCK_POWER), MMOItems.plugin.getConfig().getDouble("mitigation.block.power.max")) / 100;
|
||||
playerData.applyCooldown(CooldownType.BLOCK, stats.getStat(ItemStat.BLOCK_COOLDOWN_REDUCTION));
|
||||
event.setDamage(event.getDamage() * (1 - blockPower));
|
||||
|
||||
Message.ATTACK_BLOCKED.format(ChatColor.RED, "#percent#", new DecimalFormat("0.#").format(blockPower * 100)).send(player, "mitigation");
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 2, 1);
|
||||
|
||||
double yaw = getYaw(player, getVector(player, event)) + 95;
|
||||
for (double j = yaw - 90; j < yaw + 90; j += 5)
|
||||
for (double y = 0; y < 2; y += .1)
|
||||
MMOItems.plugin.getVersion().getVersionWrapper().spawnParticle(Particle.REDSTONE, player.getLocation().clone().add(Math.cos(Math.toRadians(j)) * .7, y, Math.sin(Math.toRadians(j)) * .7), Color.GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getVector(Player player, EntityDamageEvent event) {
|
||||
return event instanceof EntityDamageByEntityEvent ? player.getLocation().subtract(((EntityDamageByEntityEvent) event).getDamager().getLocation()).toVector().normalize() : player.getEyeLocation().getDirection();
|
||||
}
|
||||
|
||||
private double getYaw(Entity player, Vector vec) {
|
||||
return new Location(player.getWorld(), vec.getX(), vec.getY(), vec.getZ()).setDirection(vec).getYaw();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void b(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player) || event.isCancelled() || event.getEntity().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
// magical shield ability
|
||||
for (Location loc : Magical_Shield.magicalShield.keySet())
|
||||
if (loc.getWorld().equals(player.getWorld())) {
|
||||
Double[] values = Magical_Shield.magicalShield.get(loc);
|
||||
if (loc.distanceSquared(player.getLocation()) <= values[0])
|
||||
event.setDamage(event.getDamage() * (1 - Math.max(values[1], 1)));
|
||||
}
|
||||
|
||||
// damage reduction stats
|
||||
PlayerStats stats = PlayerData.get(player).getStats();
|
||||
|
||||
if (MMOItems.plugin.getRPG().canBeDamaged(player) && !MMOItems.plugin.getDamage().isDamaged(player)) {
|
||||
if (event.getCause() == DamageCause.FIRE)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FIRE_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.FALL)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FALL_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.MAGIC)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.MAGIC_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.ENTITY_ATTACK || event.getCause() == DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == DamageCause.PROJECTILE)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.PHYSICAL_DAMAGE_REDUCTION) / 100));
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.DAMAGE_REDUCTION) / 100));
|
||||
}
|
||||
|
||||
// regeneration
|
||||
@EventHandler
|
||||
public void c(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player)
|
||||
event.setAmount(event.getAmount() * (1 + PlayerData.get((Player) event.getEntity()).getStats().getStat(ItemStat.REGENERATION) / 100));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void d(PlayerJoinEvent event) {
|
||||
PlayerData.load(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void e(PlayerQuitEvent event) {
|
||||
PlayerData.get(event.getPlayer()).save();
|
||||
}
|
||||
|
||||
// apply on-hit abilities from armor pieces.
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void f(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled() || !(event.getEntity() instanceof Player) || !(event.getDamager() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC") || event.getDamager().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
LivingEntity damager = (LivingEntity) event.getDamager();
|
||||
Player player = (Player) event.getEntity();
|
||||
PlayerData.get(player).castAbilities(damager, new AttackResult(true, event.getDamage()), CastingMode.WHEN_HIT);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void g(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.PHYSICAL)
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
boolean left = event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK;
|
||||
PlayerData.get(player).castAbilities(null, new AttackResult(true), player.isSneaking() ? (left ? CastingMode.SHIFT_LEFT_CLICK : CastingMode.SHIFT_RIGHT_CLICK) : (left ? CastingMode.LEFT_CLICK : CastingMode.RIGHT_CLICK));
|
||||
}
|
||||
|
||||
/*
|
||||
* prevent players from droping items which are bound to them with a
|
||||
* soulbound. items are cached inside a map waiting for the player to
|
||||
* respawn. if he does not respawn the items are dropped on the ground, this
|
||||
* way there don't get lost
|
||||
*/
|
||||
@EventHandler
|
||||
public void h(PlayerDeathEvent event) {
|
||||
if (event.getKeepInventory())
|
||||
return;
|
||||
|
||||
Player player = event.getEntity();
|
||||
SoulboundInfo soulboundInfo = new SoulboundInfo(player);
|
||||
|
||||
ItemStack item;
|
||||
Iterator<ItemStack> iterator = event.getDrops().iterator();
|
||||
while (iterator.hasNext())
|
||||
if (MMOItems.plugin.getNMS().getNBTItem(item = iterator.next()).getString("MMOITEMS_SOULBOUND").equals(player.getUniqueId().toString())) {
|
||||
iterator.remove();
|
||||
soulboundInfo.add(item);
|
||||
}
|
||||
|
||||
soulboundInfo.setup();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void i(PlayerRespawnEvent event) {
|
||||
SoulboundInfo.read(event.getPlayer());
|
||||
}
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Location;
|
||||
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.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.ability.Magical_Shield;
|
||||
import net.Indyuce.mmoitems.api.Ability.CastingMode;
|
||||
import net.Indyuce.mmoitems.api.AttackResult;
|
||||
import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerStats;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void b(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player) || event.isCancelled() || event.getEntity().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
// magical shield ability
|
||||
for (Location loc : Magical_Shield.magicalShield.keySet())
|
||||
if (loc.getWorld().equals(player.getWorld())) {
|
||||
Double[] values = Magical_Shield.magicalShield.get(loc);
|
||||
if (loc.distanceSquared(player.getLocation()) <= values[0])
|
||||
event.setDamage(event.getDamage() * (1 - Math.max(values[1], 1)));
|
||||
}
|
||||
|
||||
// damage reduction stats
|
||||
PlayerStats stats = PlayerData.get(player).getStats();
|
||||
|
||||
if (MMOItems.plugin.getRPG().canBeDamaged(player) && !MMOItems.plugin.getDamage().isDamaged(player)) {
|
||||
if (event.getCause() == DamageCause.FIRE)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FIRE_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.FALL)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FALL_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.MAGIC)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.MAGIC_DAMAGE_REDUCTION) / 100));
|
||||
else if (event.getCause() == DamageCause.ENTITY_ATTACK || event.getCause() == DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == DamageCause.PROJECTILE)
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.PHYSICAL_DAMAGE_REDUCTION) / 100));
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.DAMAGE_REDUCTION) / 100));
|
||||
}
|
||||
|
||||
// regeneration
|
||||
@EventHandler
|
||||
public void c(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player)
|
||||
event.setAmount(event.getAmount() * (1 + PlayerData.get((Player) event.getEntity()).getStats().getStat(ItemStat.REGENERATION) / 100));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void d(PlayerJoinEvent event) {
|
||||
PlayerData.load(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void e(PlayerQuitEvent event) {
|
||||
PlayerData.get(event.getPlayer()).save();
|
||||
}
|
||||
|
||||
// apply on-hit abilities from armor pieces.
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void f(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled() || !(event.getEntity() instanceof Player) || !(event.getDamager() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC") || event.getDamager().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
LivingEntity damager = (LivingEntity) event.getDamager();
|
||||
Player player = (Player) event.getEntity();
|
||||
PlayerData.get(player).castAbilities(damager, new AttackResult(true, event.getDamage()), CastingMode.WHEN_HIT);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void g(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.PHYSICAL)
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
boolean left = event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK;
|
||||
PlayerData.get(player).castAbilities(null, new AttackResult(true), player.isSneaking() ? (left ? CastingMode.SHIFT_LEFT_CLICK : CastingMode.SHIFT_RIGHT_CLICK) : (left ? CastingMode.LEFT_CLICK : CastingMode.RIGHT_CLICK));
|
||||
}
|
||||
|
||||
/*
|
||||
* prevent players from droping items which are bound to them with a
|
||||
* soulbound. items are cached inside a map waiting for the player to
|
||||
* respawn. if he does not respawn the items are dropped on the ground, this
|
||||
* way there don't get lost
|
||||
*/
|
||||
@EventHandler
|
||||
public void h(PlayerDeathEvent event) {
|
||||
if (event.getKeepInventory())
|
||||
return;
|
||||
|
||||
Player player = event.getEntity();
|
||||
SoulboundInfo soulboundInfo = new SoulboundInfo(player);
|
||||
|
||||
ItemStack item;
|
||||
Iterator<ItemStack> iterator = event.getDrops().iterator();
|
||||
while (iterator.hasNext())
|
||||
if (MMOItems.plugin.getNMS().getNBTItem(item = iterator.next()).getString("MMOITEMS_SOULBOUND").equals(player.getUniqueId().toString())) {
|
||||
iterator.remove();
|
||||
soulboundInfo.add(item);
|
||||
}
|
||||
|
||||
soulboundInfo.setup();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void i(PlayerRespawnEvent event) {
|
||||
SoulboundInfo.read(event.getPlayer());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user