泡泡插件不起作用

时间:2015-08-14 21:51:24

标签: java bukkit

基本上我正在尝试创建一个插件,允许某人(有烫发)做/泡泡,而且任何名字对应于该名称的人都会“冒泡”。这个泡泡基本上是一个拒绝场,(球体)所以每当除了args [0](泡泡的用户名)之外的人都会非常快速地突然爆发。我不知道你是否见过这个,但是如果你需要更多的概念验证,我的是一个Minecraft服务器,它将这个概念应用到宝箱中。基本上每当有人点击它时,他们就会被困在一个1x2的区域内,每个试图带着5个区块的人都会被击出,有点像他们反弹。这是我提出的代码。我不知道为什么这不起作用,没有任何错误,但它并没有把它们抛弃。

注意:我正在使用一个调用此类的主类(主类称为“Main”。此类,此类称为“Bubble”。

编辑:我刚刚更新了代码以使用散列图。它们目前尚未实现,但我想在插件中使用它们。

package me.Glowhoo.EpicUtil;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
/*
 * Author =
 * Glowhoo
 * 
 */
public class Bubble implements CommandExecutor, Listener {
private Main plugin;

public Bubble(Main plugin)
{
  this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
    if (cmd.getName().equalsIgnoreCase("bubble"))
    {
        if (sender instanceof Player)
        {
            if (args.length > 0 && args.length <= 2)
            {
            if (Bukkit.getPlayer(args[0]) != null)
            { //Note: I suck with hashmaps.
                HashMap<String, Boolean> bubbles = new HashMap<>(); //Attempted to make a hashmap of the player which has the bubble, and if the bubble is on/off.
                Player victim = (Bukkit.getPlayer(args[0]));
                Bukkit.broadcastMessage(ChatColor.BOLD.GREEN + victim.getName() + ChatColor.BOLD.DARK_GRAY + " Is now in a bubble!");
                FixedMetadataValue metadataValue = new FixedMetadataValue((Plugin)this.plugin, true);
                victim.setMetadata("isInBubble", metadataValue);


                if (args[1].equalsIgnoreCase("on")) //i.e /bubble <username> <on/off>
                {
                bubbles.put(args[0], true);
                }else if (args[1].equalsIgnoreCase("off"))
                {
                    bubbles.put(args[0], false);
                }


            }
            else
            {
                sender.sendMessage(ChatColor.RED + "Player is not online!");

            }

            }
            else
            {
                sender.sendMessage(ChatColor.RED + "Invalid arguments!");
            }


        }
        else
        {
            sender.sendMessage(ChatColor.AQUA + "The console cannot bubble someone!");
        }

    }



    return false;
}
public void onPlayerMove(PlayerMoveEvent e) {
     Player mover = e.getPlayer();
     Location from = e.getFrom();
     Location to = e.getTo();
     Collection<Entity> nearbyEntities = mover.getWorld().
     getNearbyEntities(from,  10, 10, 10);//Get entities in a 10 block square from loc "from"
     List<Player> nearbyPlayers = new ArrayList<Player>();
     for (Entity en : nearbyEntities) {
         if (en instanceof Player)
           nearbyPlayers.add((Player) en);
     }
     for (Player victim : nearbyPlayers) {
         if (victim.hasMetadata("isInBubble") && victim != mover) {
            Location victimLoc = victim.getLocation();
            if (victimLoc.distance(to) <= 5) {//Radius 5
                e.setCancelled(true); //Cancel so cant move
                return; //we have nothing left no need to get in for statement again
            }
            }
         }
     }
 }

0 个答案:

没有答案