BukkitAPI is kinda bad

Discussion in 'Plugin Development' started by largeuntiedknot, Nov 13, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    largeuntiedknot

    Code:
    package me.jaydenderp.jaydenutils.commands;
    
    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 class GamemodesCS extends JavaPlugin implements CommandExecutor {
          @Override
          public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("gmt")) {
            if (sender instanceof Player) {
            Player p = (Player)sender;
            if(p.getGameMode() == GameMode.SURVIVAL) {
                p.setGameMode(GameMode.CREATIVE);
                p.sendMessage("Your gamemode is now CREATIVE!!!!!!!!!!!!!!!!!!!!!!!");
            } else if(p.getGameMode() == GameMode.CREATIVE) {
                p.setGameMode(GameMode.ADVENTURE);
                p.sendMessage("Your gamemode is now ADVENTURE!!!!!!!!!!!!!!!!!!!!!!!");
            } else if (p.getGameMode() == GameMode.ADVENTURE) {
                p.setGameMode(GameMode.SPECTATOR);
                p.sendMessage("ur gamemode now SPECTATOR U CAN PHASE HACK!!!!!!!!!!!!!!!!!!!!!!!!");
            } else if (p.getGameMode() == GameMode.SPECTATOR) {
                p.setGameMode(GameMode.SURVIVAL);
                p.sendMessage("Your gamemode is now SURVIVE!!!!!!!!!!!!!!!!!!!!!!!");
            }
            }
            }
            return false;
          }
    }
    Doesn't work. Also don't ask me "wut u mean by doesn't work". You can read.
    When I do /gmt, nothing happens.
    Suggestion: add a p.toggleGameMode() effect

    Code:
    package me.jaydenderp.jaydenutils.commands;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    // Import libraries
    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;
    
    // Implement Bukkit
    public class Die extends JavaPlugin implements CommandExecutor{
    
    // Start code  
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (command.getName().equalsIgnoreCase("die")) {                  
        if (sender instanceof Player) {
            Player player = (Player) sender;
            player.setHealth(0.0);
            Logger Console = Bukkit.getLogger();
            Console.info(sender + " was killed with /die.");
        } else {
            return false;
        }          
    } return true;
    }
    }
    
    What should happen:
    you do /die and it kills you
    it sends "<player> was killed with /die" to the console
    What happens:
    absolutely freaking nothing

    Could be fixed by adding p.killPlayer() event

    plugin.yml for both plugins:
    Code:
    name: Announcast
    main: me.jaydenderp.announcast.Main
    version: 1.0
    description: Say anything
    authors: [jaydenderp]
    
    commands:
      announce:
        description: Announce text
        usage: /announce
    
    permissions:
      announce.send:
        description: Permission for using the main command
        default: op
    
    Code:
    name: JaydenUtils
    version: 1.0
    description: Useless plugin lol
    load: STARTUP
    author: jaydenderp
    main: me.jaydenderp.jaydenutils.Main
    commands:
      nameget:
        usage: /nameget
      die:
        usage: /die
      gmt:
        usage: /gmt
        permission: jaydenutils.gmt
    Absolutely nothing in my code appears to be incorrect (to me at least).
    bukkit api = not very good
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    largeuntiedknot

    Code:
    [19:44:41] [Server thread/INFO]: Starting minecraft server version 1.14.4
    [19:44:41] [Server thread/INFO]: Loading properties
    [19:44:44] [Server thread/INFO]: This server is running CraftBukkit version git-Spigot-56f8471-56118c6 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)
    [19:44:45] [Server thread/INFO]: Debug logging is disabled
    [19:44:45] [Server thread/INFO]: Using 4 threads for Netty based IO
    [19:44:45] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [19:44:45] [Server thread/INFO]: Default game type: SURVIVAL
    [19:44:45] [Server thread/INFO]: Generating keypair
    [19:44:46] [Server thread/INFO]: Starting Minecraft server on *:25565
    [19:44:46] [Server thread/INFO]: Using default channel type
    [19:45:45] [Server thread/WARN]: Plugin Announcast v1.0 does not specify an api-version.
    [19:45:46] [Server thread/WARN]: Plugin JaydenUtils v1.0 does not specify an api-version.
    [19:45:47] [Server thread/WARN]: Plugin ProtocolLib v4.4.0 does not specify an api-version.
    [19:45:48] [Server thread/WARN]: Plugin TuSKe v1.8.2-Pikachu-Patch-3 does not specify an api-version.
    [19:45:48] [Server thread/INFO]: [Announcast] Loading Announcast v1.0
    [19:45:48] [Server thread/INFO]: [WorldEdit] Loading WorldEdit v7.0.1;61bc012
    [19:45:57] [Server thread/INFO]: Got request to register class com.sk89q.worldedit.bukkit.BukkitServerInterface with WorldEdit [com.sk89q.worldedit.extension.platform.PlatformManager@100c0ab2]
    [19:45:57] [Server thread/INFO]: [Skript] Loading Skript v2.4-beta9
    [19:45:57] [Server thread/INFO]: [JaydenUtils] Loading JaydenUtils v1.0
    [19:45:57] [Server thread/INFO]: [Vault] Loading Vault v1.7.2-b107
    [19:45:57] [Server thread/INFO]: [ProtocolSupport] Loading ProtocolSupport v4.29-dev
    [19:46:31] [Server thread/INFO]: [ProtocolLib] Loading ProtocolLib v4.4.0
    [19:46:31] [Server thread/WARN]: [ProtocolLib] Version (MC: 1.14.4) has not yet been tested! Proceed with caution.
    [19:46:32] [Server thread/INFO]: [WorldGuard] Loading WorldGuard v7.0.0;02b731f
    [19:46:32] [Server thread/INFO]: [LiteBans] Loading LiteBans v2.3.18
    [19:46:32] [Server thread/INFO]: [TuSKe] Loading TuSKe v1.8.2-Pikachu-Patch-3
    [19:46:32] [Server thread/INFO]: [WorldEdit] Enabling WorldEdit v7.0.1;61bc012
    [19:46:32] [Server thread/INFO]: WEPIF: Using the Bukkit Permissions API.
    [19:46:33] [Server thread/INFO]: Using com.sk89q.worldedit.bukkit.adapter.impl.Spigot_v1_14_R4 as the Bukkit adapter
    [19:46:38] [Server thread/INFO]: [JaydenUtils] Enabling JaydenUtils v1.0
    [19:46:38] [Server thread/INFO]: [Vault] Enabling Vault v1.7.2-b107
    [19:46:38] [Server thread/INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
    [19:46:39] [Server thread/INFO]: [Vault] Enabled Version 1.7.2-b107
    [19:46:39] [Server thread/INFO]: WEPIF: Vault detected! Using Vault for permissions
    [19:46:39] [Server thread/INFO]: [ProtocolSupport] Enabling ProtocolSupport v4.29-dev
    [19:46:39] [Server thread/INFO]: [ProtocolLib] Enabling ProtocolLib v4.4.0
    [19:46:39] [Server thread/INFO]: [ProtocolLib] Started structure compiler thread.
    [19:46:39] [Server thread/INFO]: Preparing level "world"
    [19:46:40] [Server thread/INFO]: Reloading ResourceManager: Default, bukkit
    [19:46:43] [Server thread/INFO]: Loaded 6 recipes
    [19:46:47] [Server thread/INFO]: Registering commands with com.sk89q.worldedit.bukkit.BukkitServerInterface
    [19:46:48] [Server thread/INFO]: Preparing start region for dimension 'world'/minecraft:overworld
    [19:46:57] [Server thread/INFO]: Preparing spawn area: 47%
    [19:46:58] [Server thread/INFO]: Time elapsed: 10389 ms
    [19:46:58] [Server thread/INFO]: [Announcast] Enabling Announcast v1.0
    [19:46:58] [Server thread/INFO]: [Skript] Enabling Skript v2.4-beta9
    [19:47:05] [ForkJoinPool.commonPool-worker-1/INFO]: [0;37;22m[[0;33;22mSkript[0;37;22m][m A new version of Skript is available: [0;33;22m2.4-beta10[m (you're currently running [0;33;22m2.4-beta9[m)[m
    [19:47:05] [ForkJoinPool.commonPool-worker-1/INFO]: [0;37;1mDownload it at: <aqua><u><link:[URL]https://github.com/SkriptLang/Skript/releases/download/2.4-beta10/Skript.jar>https://github.com/SkriptLang/Skript/releases/download/2.4-beta10/Skript.jar[m[/URL]
    [19:47:34] [Server thread/INFO]: [Skript] Loaded 114225 aliases in 34896ms
    [19:47:38] [Server thread/INFO]: [Skript]  ~ created by & © Peter Güttinger aka Njol ~
    [19:47:39] [Server thread/INFO]: [WorldGuard] Loaded configuration for world 'world'
    [19:47:39] [Server thread/INFO]: [WorldGuard] Loading region data...
    [19:47:41] [Server thread/INFO]: [LiteBans] Enabling LiteBans v2.3.18
    [19:47:42] [Server thread/INFO]: [LiteBans] Using default database drivers.
    [19:47:44] [Server thread/INFO]: [TuSKe] Enabling TuSKe v1.8.2-Pikachu-Patch-3
    [19:47:45] [Server thread/INFO]: [TuSKe] Enabling Metrics... Done!
    [19:47:45] [Server thread/INFO]: [TuSKe] Check for updates enabled. It will check in some seconds.
    [19:47:45] [Server thread/INFO]: [TuSKe] Documentation enabled. Some files containing all syntax of all addons will be generated.
    [19:47:46] [Server thread/INFO]: [TuSKe] Loaded 8 events, 12 conditions, 20 effects, 62 expressions and 0 types. Have fun!
    [19:47:46] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:47:47] [Server thread/INFO]: Done (67.360s)! For help, type "help"
    [19:47:47] [Server thread/INFO]: [Skript] Loading variables...
    [19:47:47] [Server thread/INFO]: [Skript] Loaded 63 variables in 0.1 seconds
    [19:47:47] [Server thread/INFO]: [Skript] All scripts loaded without errors.
    [19:47:47] [Server thread/WARN]: [Skript] No scripts were found, maybe you should write some ;) (config.sk, line 188: databases:')
    [19:47:47] [Server thread/INFO]: [Skript] Finished loading.
    [19:47:47] [Craft Scheduler Thread - 0/INFO]: [Vault] Checking for Updates ... 
    [19:47:48] [Craft Scheduler Thread - 1/INFO]: [TuSKe] Checking for latest update...
    [19:47:49] [Craft Scheduler Thread - 1/INFO]: [TuSKe] New update available: v1.8.2
    [19:47:49] [Craft Scheduler Thread - 1/INFO]: [TuSKe] Check what's new in: [URL]https://github.com/Tuke-Nuke/TuSKe/releases/tag/1.8.2[/URL]
    [19:47:49] [Craft Scheduler Thread - 1/INFO]: [TuSKe] You can download and update it with /tuske update.
    [19:47:50] [Craft Scheduler Thread - 0/INFO]: [Vault] No new version available
    [19:47:52] [Craft Scheduler Thread - 0/INFO]: [TuSKe] Generating documentation of Skript & Addons.
    [19:47:53] [Craft Scheduler Thread - 0/INFO]: [TuSKe] Documentation was generated successfully.
    [19:47:59] [LoginProcessingThread/INFO]: UUID of player BrokenTwine is 76914db8-ff43-4594-b5f8-49208b71c155
    [19:48:04] [Server thread/INFO]: BrokenTwine[/127.0.0.1:59045] logged in with entity id 78 at ([world]1.5, 67.0, 25.5)
    [19:48:05] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 5748ms or 114 ticks behind
    [19:48:39] [Server thread/INFO]: BrokenTwine issued server command: /gmt
    [19:48:42] [Server thread/INFO]: BrokenTwine issued server command: /die
    [19:48:43] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 7947ms or 158 ticks behind
    [19:48:45] [Server thread/INFO]: BrokenTwine issued server command: /gamemode survival
    [19:48:45] [Server thread/INFO]: [BrokenTwine: Set own game mode to Survival Mode]
    [19:48:46] [Server thread/INFO]: BrokenTwine issued server command: /die
     
    Last edited by a moderator: Nov 14, 2019
  4. Offline

    timtower Administrator Administrator Moderator

    @largeuntiedknot Neither of those classes are the main class yet they extend JavaPlugin.
    That is not possible.
     
  5. Offline

    Strahan

    First, you do not need to implement CommandExecutor if you extend JavaPlugin. Secondly, the plugin.yml that shows your gmt command specifies a startup class of me.jaydenderp.jaydenutils.Main yet this class is GamemodesCS. As timtower said, you can't have more than one class extending JavaPlugin and have the plugin work, it should crash at startup. If it's not, then you aren't registering your command in me.jaydenderp.jaydenutils.Main to use that class which would also explain why it's not working (putting aside the JavaPlugin problem). Same problem with Die.

    Also they can't add .toggleGameMode() because GameMode isn't binary. They could make a cycleGameMode perhaps, but it seems pretty useless as people typically want to go directly to the gamemode they want and not waste time fruitlessly shifting between them all. I'd also ditch that big logic block and just do the Map based cycling I explained over at Spigot, it'd be more efficient.

    It's not the APIs fault if someone doesn't understand how to properly leverage it.
     
  6. Offline

    robertlit

    Why would you extend JavaPlugin twice?

    The API isn't bad, you just don't understand how to use it! If you don't like it, go find an alternative (Good luck with that)
     
  7. Offline

    largeuntiedknot

    Too bad the docs / tutorials don't tell me that.
    Requesting Lock.
     
Thread Status:
Not open for further replies.

Share This Page