咒语滚动条不起作用 [英] Spell Scroller doesn't work

查看:106
本文介绍了咒语滚动条不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个MagicBows插件,您可以通过单击鼠标左键来选择咒语,如果您射击弓箭,则所选咒语会产生效果,但选择器不起作用。我不确定如何解决此问题。

I'm making a MagicBows plugin where you can select spells by doing left click and if you shoot the bow the selected spell will give its effect, but the selector doesn't work. I'm not sure how to fix this.

这是我的主文件:

package me.Pixel;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
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.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {
    public Main plugin;
    public List<String> spells = new ArrayList<String>();
    public getTargets getTargets = new getTargets();
    private Arrow arrow;
    public LightningShot LightningShot = new LightningShot(arrow);
    public ExplosionShot ExplosionShot = new ExplosionShot(arrow);

    @Override
    public void onEnable() {    
        plugin = this;
        this.getServer().getPluginManager().registerEvents(this, this);
        getCommand("bow").setExecutor(new BowCommand());
        spells.add("LightningShot");
        spells.add("ExplosionShot");
    }

    @EventHandler
    public void onEntityShootBow(EntityShootBowEvent event) {
        if(event.getProjectile() instanceof Arrow) {
            Arrow arrow = (Arrow) event.getProjectile();
            new LightningShot(arrow).runTaskTimer(this, 0, 1);
        }
    }       

    @EventHandler
    public void onEntityShootBow1(EntityShootBowEvent event) {
        if(event.getProjectile() instanceof Arrow) {
            Arrow arrow = (Arrow) event.getProjectile();
            new ExplosionShot(arrow).runTaskTimer(this, 0, 1);
        }
    }

    @EventHandler
    public void onClick(PlayerInteractEvent e) {
        if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
            Player p = e.getPlayer();
            ItemStack stack = p.getItemInHand();
            if(stack != null && stack.getType() == Material.BOW && stack.hasItemMeta() && stack.getItemMeta().getDisplayName().equals(ChatColor.RED + "Bow")) {
                int SpellSelected = stack.getDurability();
                if (SpellSelected < 2) {
                    stack.setDurability((short) (SpellSelected + 1));
                    p.getWorld().playEffect(p.getLocation(), Effect.STEP_SOUND, ParticleEffect.SNOW_SHOVEL);
                } else {
                    stack.setDurability((short) 0);
                }
                ChatUtilities.sendMessage(p, "Selected: " + spells.get(SpellSelected));
            }
        }
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            Player p = e.getPlayer();
            ItemStack stack = p.getItemInHand();
            if(stack != null && stack.getType() == Material.BOW && stack.hasItemMeta() && stack.getItemMeta().getDisplayName().equals(ChatColor.RED + "Bow")) {
                int SpellSelected = stack.getDurability();
                if(SpellSelected == 1) {
                    this.LightningShot.run();
                } else if (SpellSelected == 2) {
                    this.ExplosionShot.run();
                }
            }
        }
    }
}

这是我的第一个咒语:LightningShot

And this is my first spell: LightningShot

package me.Pixel;

import org.bukkit.entity.Arrow;
import org.bukkit.scheduler.BukkitRunnable;

public class LightningShot extends BukkitRunnable {
    private Arrow arrow;
    private int tick = 1;

    public LightningShot(Arrow arrow) {
        this.arrow = arrow;
    }

    @Override
    public void run() {
        if (arrow == null || arrow.isOnGround() || tick++ > 20 * 10) {
            this.cancel();
        } else {
            arrow.getWorld().strikeLightning(arrow.getLocation());
        }
    }
}

这是我的第二个咒语:爆炸射击(我正在尝试制造爆炸波)

And this is my second spell: ExplosionShot (I'm trying to make an "explosion wave")

package me.Pixel;

import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.entity.Arrow;
import org.bukkit.scheduler.BukkitRunnable;

public class ExplosionShot extends BukkitRunnable {
    private Arrow arrow;
    private int tick = 1;

    public ExplosionShot(Arrow arrow) {
        this.arrow = arrow;
    }

    @Override
    public void run() {
        if (arrow == null || arrow.isOnGround() || tick++ > 20 * 10) {
            this.cancel();
        } else {
            arrow.getWorld().createExplosion(arrow.getLocation(), 1);
            FireworkEffect.builder().with(Type.BALL).withColor(Color.AQUA).withFade(Color.FUCHSIA).flicker(true).trail(true);
        }
    }
}

此外, ExplosionShot LightningShot 结合起来了,所以LightningShot在箭头的踪迹上爆炸了吗?

Also, somehow the ExplosionShot and LightningShot are combining so the LightningShot has explosions at the arrow's trail?

因此,如果用户单击鼠标右键,则聊天中应显示一条消息:

So if a user clicks their right mouse button there should be a message in chat that says:


[X](此是我的聊天实用程序,因此无需担心)已选择:LightningShot

[X] (this is my chat utility so this is nothing to worry about) Selected: LightningShot

如果他们再次单击鼠标右键:

And if they click their right mouse button again:


[X]已选择:爆炸

[X] Selected: ExplosionShot

那么它应该沿着箭头的方向创建这个爆炸波,但是我无法使滚动条起作用。

And then it should create this "explosion wave" as it's following the arrow, but I can't get the scroller to work.

推荐答案

我建议您不要使用BukkitRunnable,而是创建一个新的抽象类(ArrowSpell?),并使LightningShot和ExplosiveShot扩展该类。您可以向LightningShot和ExplosiveShot必须实现的ArrowSpell添加抽象方法,例如onShoot(EntityShootBowEvent)或onHit(EntityDamageByEntityEvent),它们不会侦听而是传递给它。我实际上做了类似的事情,您可以在此处看到示例:
https://github.com/ViperLordX/Divinity/tree/master/src/redempt/divinity/ability/modifier

I suggest that instead of using a BukkitRunnable, you make a new abstract class (ArrowSpell?) and make LightningShot and ExplosiveShot extend that class. You can add abstract methods to ArrowSpell which LightningShot and ExplosiveShot must implement, such as onShoot(EntityShootBowEvent) or onHit(EntityDamageByEntityEvent) which it does not listen for, but get passed to it. I actually did something similar, you can see an example here: https://github.com/ViperLordX/Divinity/tree/master/src/redempt/divinity/ability/modifier

,您不需要使用BukkitRunnable,据我所知,这是一种非常尴尬的操作方式。

This way, you don't need to use a BukkitRunnable, which is, from what I see, a very awkward way of doing it.

这篇关于咒语滚动条不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆