这是我目前的代码:
import java.util.Random;
import java.util.stream.IntStream;
import org.bukkit.Bukkit;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
}
@Override
public void onDisable() {
}
public class MobListener implements Listener {
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
Random r = new Random();
int randomInt = r.nextInt(100) + 1;
int[] myNum = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] uncommon = {1,2,3,4,5,6};
int[] rare = {1,2,3,4,5};
int[] epic = {1,2};
int[] legendary = {1};
int[] a = IntStream.range(1, 100).toArray();
if(event.getEntity() instanceof Monster)
{
Monster monsterEnt = (Monster) event.getEntity();
if(monsterEnt.getKiller() instanceof Player)
{
Player mcPlayer = (Player)monsterEnt.getKiller();
if(mcPlayer == null)
return;
if(mcPlayer.hasPermission("customdrops.use"))
for(int i : myNum)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "crate give to" + mcPlayer + "CommonChest");
for(int i : uncommon)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "crate give to" + mcPlayer + "UncommonChest");
for(int i : rare)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "crate give to" + mcPlayer + "RareChest");
for(int i : epic)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "crate give to" + mcPlayer + "EpicChest");
for(int i : legendary)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "crate give to" + mcPlayer + "LegendaryChest");
for(int i : a)
if(randomInt == i)
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "give" + mcPlayer + "dirt 64");
}
}
}
}
}
我添加了污垢的东西只是为了测试,到目前为止,没有板条箱或污垢已下降。控制台中没有错误,插件在/pl中显示为绿色。使用1.16.2。我要它在敌方暴徒被杀时执行命令。命令将给他们板条箱或污垢(目前,这将被删除)。
2条答案
按热度按时间vcirk6k61#
据我所知,您没有注册侦听器类。
你可以这样做,下面这一行在你的
onEnable()
方法。wgeznvg72#
您使用的命令无效。
这是你的命令
"crate give to" + mcPlayer + "CommonChest"
,我们来分解一下。首先,我非常确定不能在命令中直接引用player对象。
其次,你需要在玩家名字的两边加空格
现在大家一起:
注意:您确定这是由插件注册的有效命令吗:
crate give to Toasterr1066 CommonChest
?