(我在想啥呢)今天闲的没事干找GPT问了个服务器插件做法,于是······
本帖最后由 战虎 于 2023-6-29 16:40 编辑一开始回复的代码是这样的↓
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Team;
public class NoAttackPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().info("插件已启用");
getServer().getPluginManager().registerEvents(this, this);
setupScoreboardTeam();
}
@Override
public void onDisable() {
getLogger().info("插件已禁用");
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player damaged = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
if ((damaged.getGameMode() == GameMode.CREATIVE || damaged.getGameMode() == GameMode.SURVIVAL || damaged.getGameMode() == GameMode.ADVENTURE)
&& !isSameTeam(damaged, damager)) {
event.setCancelled(true);
damager.sendMessage(ChatColor.RED + "你不能攻击生存模式或冒险模式的玩家!");
}
}
}
private void setupScoreboardTeam() {
Team noAttackTeam = Bukkit.getScoreboardManager().getMainScoreboard().getTeam("NoAttackTeam");
if (noAttackTeam == null) {
noAttackTeam = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam("NoAttackTeam");
}
noAttackTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
}
private boolean isSameTeam(Player player1, Player player2) {
Team team1 = player1.getScoreboard().getPlayerTeam(player1);
Team team2 = player2.getScoreboard().getPlayerTeam(player2);
return team1 != null && team2 != null && team1.equals(team2);
}
}
这只是很小一部分,也就是主体功能的运行逻辑:禁止创造模式玩家攻击生存模式玩家。
然而作为一个JAVA0基础的小萌新来说就算是现成代码,进一步完善并导出JAR几乎不可能
一个上午到下午看了无数教程,但毫无进展。脑阔疼
就连CHATGPT的多次协助也救不了这个烂项目。最终在构建JAR(也就是最后一步)停止了——无法找到org.bukkit:craftbukkit:jar:1.12.2-R0.1-SNAPSHOT的依赖
下方的报错信息
没完全做好的插件我上传云盘了,送给有基础的同学可以拿去开发 摆了
戳我下载
总结:刚刚接触JAVA的小萌新闲的*疼 委托GPT写插件,得到一串意义不明的代码,一脸懵逼的找半天编程软件,又一脸懵逼的在软件里迷路,一脸懵逼的看完了几个超长教学、一脸懵逼的在GPT的提示下反复修改······最后一脸懵逼的退出编辑器[贴吧_喷]。入门到入坟[贴吧_滑稽]
9666666666666 苦力怕论坛,感谢有您~ 楼主加油
页: [1]