1
Command is not registering correctly.
Hey, I just finished programming a plugin. It's called "GuardFreeze" which allows guards to hit players that are holding contraband items, which teleports them to an interrogation room. Where they have to give up the item to the guard, if not they receive jail time. The plugin is 30% done. You first as a guard, have to type '/guard' to receive the punisher(stick). But once I'm ingame I try to type '/guard' it doesn't register. It justs sends the same message over and over again: '/guard' It repeats it in white chat color.
Here is the code:
package me.GoldenRod.GuardFreeze;
import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class Freeze extends JavaPlugin implements Listener{
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if(sender instanceof Player){
if (!((Player) sender).hasPermission("custom.guardfreeze")) {
Player p = (Player)sender;
if((commandLabel.equalsIgnoreCase("guard"))&&(args.length == 0)) {
ItemStack guard = new ItemStack(Material.STICK, 1);
Inventory inv = p.getInventory();
inv.setItem(0, guard);
p.updateInventory();
if(inv.getItem(0) !=null){
ItemMeta guardIM = inv.getItem(0).getItemMeta();
guardIM.setDisplayName(ChatColor.GOLD + "Jail em");
List<String> lore = Arrays.asList("This amazing stick", "made with special powers, crafted", "from Apollo's Gods ");
guardIM.setLore(lore);
inv.getItem(0).setItemMeta(guardIM);
}
}
}
}
return false;
}
}
===============================================
Here's the plugin.yml:
name: GuardFreeze
version: 1
description: Freeze em players!
main: me.GoldenRod.GuardFreeze.Freeze
author: GoldenRodHero
commands:
guard:
description: freeze dem.
usage: /<command>
===============================================
Thank you if you find out what the problem was!
Here is the code:
package me.GoldenRod.GuardFreeze;
import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class Freeze extends JavaPlugin implements Listener{
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if(sender instanceof Player){
if (!((Player) sender).hasPermission("custom.guardfreeze")) {
Player p = (Player)sender;
if((commandLabel.equalsIgnoreCase("guard"))&&(args.length == 0)) {
ItemStack guard = new ItemStack(Material.STICK, 1);
Inventory inv = p.getInventory();
inv.setItem(0, guard);
p.updateInventory();
if(inv.getItem(0) !=null){
ItemMeta guardIM = inv.getItem(0).getItemMeta();
guardIM.setDisplayName(ChatColor.GOLD + "Jail em");
List<String> lore = Arrays.asList("This amazing stick", "made with special powers, crafted", "from Apollo's Gods ");
guardIM.setLore(lore);
inv.getItem(0).setItemMeta(guardIM);
}
}
}
}
return false;
}
}
===============================================
Here's the plugin.yml:
name: GuardFreeze
version: 1
description: Freeze em players!
main: me.GoldenRod.GuardFreeze.Freeze
author: GoldenRodHero
commands:
guard:
description: freeze dem.
usage: /<command>
===============================================
Thank you if you find out what the problem was!
Create an account or sign in to comment.
4
I fixed it. Ty for the help. All it was, was registering the events.
Thank you!
EDIT: Thanks for the suggestion, but that did not solve the problem. By the way that is how the PMC text box pastes the plugin.yml all that is spaced correctly on eclipse.
EDIT: Thanks for the suggestion, but that did not solve the problem. By the way that is how the PMC text box pastes the plugin.yml all that is spaced correctly on eclipse.
Np, mind posting the error from the console?
Implement command executer not listener, and make sure that you use spaces and not tabs when your spacing out the plugin.yml