我试图不去试论在论坛上发帖,但我所做的一切都不会使这项工作成功。我想要做的是,如果一个ArrayList没有包含一个玩家名字,那么它会将它们添加到ArrayList中,但它会跳过它并将它们从列表中删除它们从来没有添加到。这个插件的最终目标是,如果他们处于上帝模式,他们就不会受到伤害。 命令类:
public static List<String> playerList = new ArrayList<String>();
@Override
public boolean onCommand(CommandSender sender, Command cmd, String str, String[] args) {
Player player = (Player) sender;
String p = player.getName();
List<String> isGod = new ArrayList<String>();
if (cmd.getName().equalsIgnoreCase("god") && sender instanceof Player) {
if (!isGod.contains(p)) {
isGod.add(p);
playerList.add(p);
player.sendMessage(ChatColor.GREEN + "Godmode is enabled");
return true;
} else {
isGod.remove(p);
playerList.remove(p);
player.sendMessage(ChatColor.GREEN + "Godmode is disabled");
return true;
}
}
return true;
}
}
听众类:
@EventHandler
public void isDamaged(EntityDamageEvent e) {
String player = e.getEntity().getName();
if (playerList.contains(player)) {
e.setCancelled(true);
}
}
}
答案 0 :(得分:0)
当 dly 表示是,每次执行命令时都会创建新的空列表。您必须在类中将列表初始化为全局静态,以确保这只是所有操作的列表。
<record model="ir.ui.view" id="hidden_discount">
<field name="name">account.invoice.line.hidden.discount</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="account.view_invoice_line_form"/>
<field name="arch" type="xml">
<field name="discount" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>