Files
src
build.gradle
settings.gradle
Code
4 89
src/main/java/com/example/trendgamemode/TrendGameModePlugin.java
package com.example.trendgamemode;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class TrendGameModePlugin extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
getCommand("trend").setExecutor(this);
getCommand("trend2").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}
if (command.getName().equalsIgnoreCase("trend")) {
player.setGameMode(GameMode.CREATIVE);
player.sendMessage(ChatColor.GREEN + "You are now in creative mode.");
return true;
}
if (command.getName().equalsIgnoreCase("trend2")) {
player.setGameMode(GameMode.SURVIVAL);
player.sendMessage(ChatColor.GREEN + "You are now in survival mode.");
return true;
}
return false;
}
}