|
1 | 1 | package me.captainbern.animationlib; |
2 | 2 |
|
| 3 | +import me.captainbern.animationlib.command.CommandInfo; |
| 4 | +import me.captainbern.animationlib.command.CommandSource; |
| 5 | +import me.captainbern.animationlib.command.ICommand; |
| 6 | +import me.captainbern.animationlib.command.User; |
| 7 | +import org.bukkit.ChatColor; |
| 8 | +import org.bukkit.block.Block; |
| 9 | +import org.bukkit.command.BlockCommandSender; |
| 10 | +import org.bukkit.command.Command; |
| 11 | +import org.bukkit.command.CommandSender; |
| 12 | +import org.bukkit.entity.Player; |
3 | 13 | import org.bukkit.plugin.java.JavaPlugin; |
4 | 14 |
|
| 15 | +import java.util.logging.Level; |
| 16 | + |
5 | 17 | public class AnimationLib extends JavaPlugin { |
6 | 18 |
|
7 | 19 | private static AnimationLib instance; |
8 | | - public static final String LOG_PREFIX = "[AnimationLib] "; |
| 20 | + |
| 21 | + public static final ModuleLogger LOGGER = new ModuleLogger("AnimationLib"); |
9 | 22 |
|
10 | 23 | public void onEnable(){ |
11 | 24 | instance = this; |
12 | 25 |
|
13 | 26 | getLogger().info("Enabled"); |
14 | 27 | } |
15 | 28 |
|
16 | | - /** |
17 | | - * Used when players would activate this through console or something |
18 | | - */ |
19 | | - public static void main(String[] args){ |
20 | | - System.out.print("This is a library for Bukkit, place it in your plugins folder!"); |
| 29 | + @Override |
| 30 | + public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ |
| 31 | + String permissionPrefix = "animationlib.debug."; |
| 32 | + String commandPath = "me.captainbern.animationlib.command.commands.Command"; |
| 33 | + ICommand cmd = null; |
| 34 | + |
| 35 | + User user = null; |
| 36 | + Block sBlock = null; |
| 37 | + |
| 38 | + if(sender instanceof Player){ |
| 39 | + |
| 40 | + user = new User((Player) sender); |
| 41 | + |
| 42 | + }else if(sender instanceof BlockCommandSender){ |
| 43 | + |
| 44 | + BlockCommandSender bCmdSender = (BlockCommandSender) sender; |
| 45 | + sBlock = bCmdSender.getBlock(); |
| 46 | + |
| 47 | + LOGGER.log(Level.INFO, "CommandBlock at {0}, {1}, {2} issued BackPacks++ command: /{3}", new Object[] |
| 48 | + { |
| 49 | + sBlock.getX(), sBlock.getY(), sBlock.getZ(), command.getName() |
| 50 | + }); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + CommandSource source = new CommandSource(sender); |
| 55 | + |
| 56 | + try { |
| 57 | + |
| 58 | + cmd = (ICommand) this.getClassLoader().loadClass(commandPath + command.getName()).newInstance(); |
| 59 | + |
| 60 | + } catch (Exception e) { |
| 61 | + LOGGER.log(Level.WARNING, "Failed to execute {0} command!", command.getName()); |
| 62 | + return true; |
| 63 | + } |
| 64 | + |
| 65 | + if(user != null && !user.isAuthorized(cmd, permissionPrefix)){ |
| 66 | + user.sendMessage(ChatColor.RED + "You don't have permission to execute this command."); |
| 67 | + LOGGER.log(Level.INFO, "Player {0} issued AnimationLib (debug) command: /{1}", new Object[]{user.getBase().getName(), command.getName()}); |
| 68 | + return true; |
| 69 | + } |
| 70 | + |
| 71 | + //run the command |
| 72 | + try{ |
| 73 | + if(user != null){ |
| 74 | + cmd.run(getServer(), user, new CommandInfo(command, args)); |
| 75 | + return true; |
| 76 | + }else{ |
| 77 | + cmd.run(getServer(), source, new CommandInfo(command, args)); |
| 78 | + return true; |
| 79 | + } |
| 80 | + }catch(Exception e){ |
| 81 | + e.printStackTrace(); |
| 82 | + } |
| 83 | + |
| 84 | + return true; |
21 | 85 | } |
22 | 86 |
|
23 | 87 | public static AnimationLib getInstance(){ |
| 88 | + if(instance == null) { |
| 89 | + LOGGER.warning("Instance is null!"); |
| 90 | + return null; |
| 91 | + } |
24 | 92 | return instance; |
25 | 93 | } |
26 | 94 | } |
0 commit comments