Solved String to Player

Discussion in 'Plugin Development' started by Cammy_the_block, Nov 30, 2012.

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

    Cammy_the_block

    What is the method to make a string into a player?

    Thanks All
     
  2. Offline

    Bryguy

    There isn't one....

    Could you expand upon what you're attempting though? If you're taking a string which is a player's name to get the instance of a Player, then that's entirely possible. The way you've worded it though, that's relatively impossible.
     
  3. Offline

    Cammy_the_block

    I'm making a plugin that when you do the command it adds you to a list of Meta Data then once you shoot an arrow it makes tnt expload where your arrow lands.

    Main Class
    Code:
    package com.awesomepossumcraft.coolthings1;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class CoolThings1 extends JavaPlugin {
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(
                    new ProjectileHitEventListener(), this);
            getLogger().info("CoolThings1 enabled!");
     
        }
     
        public void onDisable() {
            getLogger().info("CoolThings1 disabled.");
        }
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args){
            if (command.getName().equalsIgnoreCase("TntArrows")) {
                if (args.length == 0){
                    if (sender instanceof Player) {
                    String playerString = sender.getName();
                    Player playerPlayer = playerString;
                    ProjectileHitEventListener.setPlayerStatus(sender.getName());
                }
            }
            return false;
        }
     
    }
    Listener
    Code:
    package com.awesomepossumcraft.coolthings1;
     
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.metadata.FixedMetadataValue;
    import org.bukkit.plugin.Plugin;
     
    public class ProjectileHitEventListener implements Listener {
     
        @EventHandler
        public void onProjectileHitEvent(ProjectileHitEvent event) {
     
            float pw = 2;
            event.getEntity().getWorld()
                    .createExplosion(event.getEntity().getLocation(), pw, true);
     
        }
     
        public static void setPlayerStatus(String player, String key, Boolean value,
                Plugin plugin) {
            player.setMetadata(key, new FixedMetadataValue(plugin, value));
     
        }
    }
    
     
  4. Offline

    stirante

    Bukkit.getPlayerExact(playerName);

    I think this is what you want
     
  5. Offline

    Cammy_the_block

    Thanks it worked
     
Thread Status:
Not open for further replies.

Share This Page