Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Kelson;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.FoodLevelChangeEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class NoHungerTest extends JavaPlugin implements Listener {
- Commands plugin;
- public NoHungerTest(Commands passedPlugin) {
- this.plugin = passedPlugin;
- }
- public NoHungerTest(){
- // Goes in onEnable, DO NOT remove
- }
- private boolean hungeroff = false;
- public boolean onCommand(CommandSender sender, Command cmd,
- String CommandLabel, String[] args) {
- Player player = (Player) sender;
- Player target = Bukkit.getServer().getPlayer(args[0]);
- /*if(cmd.getName().equalsIgnoreCase("nohunger") && (player.hasPermission("kelson.nohunger")) || (player.isOp())){
- boolean hungeron = true;
- boolean hungeroff = false;
- if(args.length == 0) {
- sender.sendMessage("Too few arguments, command usage: /nohunger <on/off>");
- if (args.length == 1 && (args[0].equalsIgnoreCase("on"))) {
- // Run onFoodChange event, but how?
- }
- }
- } //Disable/ delete all non working code in the future
- */
- return true;
- }
- // Hmm, this isn't working at all, need to figure out how to get the event from a command which I don't know how to do.
- @EventHandler
- public void onFoodChange(FoodLevelChangeEvent event) {
- //If the player has permission or if the player is op it disables their hunger
- /*if ((event.getEntity().hasPermission("no.hunger")) || (event.getEntity().isOp())
- && cmd.getName().equalsIgnoreCase("nohunger")) { //Would this possibly work? unknown yet... */
- //Entity sender = event.getEntity(); //Possibly change this to player instead of sender.
- //Player target = Bukkit.getServer().getEntity(args[0]);
- //Player target = event.getEntity(args[0]);
- //private hungeroff = event.setCancelled(true);
- //private hungeron = event.setCancelled(false);
- Player sender = (Player) event.getEntity();
- if(cmd.getName().equalsIgnoreCase("nohunger") && (event.getEntity().hasPermission("kelson.nohunger"))){
- if (args.length == 0) {
- sender.sendMessage(ChatColor.RED + "Too few arguments, command usage: nohunger <on/off> [player]");
- if (args.length == 1 && (args[0].equalsIgnoreCase("on"))) { // Disables hunger
- // hungeroff(); // Test code with this? that might work and look a little less messy.
- event.setCancelled(true);
- if (args.length == 1 && (args[0].equalsIgnoreCase("off"))) { // Enables hunger
- // hungeron();
- event.setCancelled(false);
- /*
- if(args.length == 2 && (args[1].equals(target)) && (args[0].equalsIgnoreCase("on")) && (event.getEntity().hasPermission("kelson.nohunger.others.on"))){
- event.setCancelled(true);
- target.sendMessage("Your hunger has been disabled by " + sender.getName());
- if(args.length == 2 && (args[1].equals(target)) && (args[0].equalsIgnoreCase("off")) && (event.getEntity().hasPermission("kelson.nohunger.others.off"))){
- event.setCancelled(false);
- target.sendMessage("Your hunger has been enabled by " + sender.getName());
- */
- //... this might work but i highly doubt it, the code above
- /*
- if(target == null){
- sender.sendMessage(ChatColor.BLUE + target + ChatColor.RED + " is not online!"); // If the nohunger for other players code above works then this should work.
- */
- if (args.length > 2) {
- sender.sendMessage("Error in command usage, use /nohunger <on/off> [player]"); //TODO Implement this to where you can turn other players hunger on and off.
- if (!event.getEntity().hasPermission("kelson.nohunger")) { //Permission error, if the player doesn't have permission this should run.
- sender.sendMessage(ChatColor.DARK_RED + "Error: you don't have permission to use this command");
- }
- }
- }
- }
- }
- }
- }
- //Test this command sometime and see if it'll work like this to turn nohunger on and off.
- //TODO Make this code work with a command instead of automatically giving anyone with op and with the permission nohunger
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement