Help Im Making a Plugin

Discussion in 'Plugin Development' started by YoYoNoYo555, Jul 3, 2015.

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

    YoYoNoYo555

    So I'm Making this parkour plugin for my friend where when u touch certain color of stained clay, it gives you certain potion effects, and when u hit bedrock, you just stay at 20 health. I have 1 command and thats /parkour to test if it works. The command works, but the effects don't. This is my first plugin I've ever made so It would be grateful If you were to help me. I'm probably doing everything wrong lol.

    package me.YoYoNoYo555.YoshiCraft;

    import java.util.logging.Logger;

    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class YoshiCraft extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static YoshiCraft plugin;

    @Override
    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Has Been Enabled");
    }

    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Has Been Disabled");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    if(commandLabel.equalsIgnoreCase("Parkour")){
    player.sendMessage(ChatColor.GOLD + "Complete The Parkour For $300 and 1 Uncommon Crate Key!");
    }
    return true;

    }
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent ev){
    Player player = ev.getPlayer();
    World world = player.getWorld();
    Location loc = ev.getTo().subtract(0, 1, 0);
    Block block = world.getBlockAt(loc);
    if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.RED)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 1));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.ORANGE)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.YELLOW)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 2));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.LIME)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 2));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.GREEN)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1));
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 1));
    }else if(block.getType()==Material.BEDROCK){
    player.setHealth(20);
    }


    }
    }






    ~~~~~Plugin.yml
    name: YoYoNoYo555
    main: me.YoYoNoYo555.YoshiCraft.YoshiCraft
    version: 1.0
    description: >
    YoYoNoYo555's
    commands:
    Parkour:
    description: Complete It!
     
  2. Offline

    schwabfl

    Let your class implement org.bukkit.event.Listener
    and then register the Listener
     
  3. Offline

    webbhead

    And register events
     
  4. Offline

    YoYoNoYo555

    Sorry, I'm REally new to this. I did this and it's still not working.
    package me.YoYoNoYo555.YoshiCraft;

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    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.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class YoshiCraft extends JavaPlugin implements Listener{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static YoshiCraft plugin;

    @Override
    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + "Nolan's Plugin Has Been Enabled");
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + "Nolan's Plugin Has Been Disabled");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    if(commandLabel.equalsIgnoreCase("Parkour")){
    player.sendMessage(ChatColor.GOLD + "Complete The Parkour For $2000 and 1 Uncommon Crate Key!");
    }
    return true;
    }
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent ev){
    Player player = ev.getPlayer();
    World world = player.getWorld();
    Location loc = ev.getTo().subtract(0, 1, 0);
    Block block = world.getBlockAt(loc);
    if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.RED)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 1));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.ORANGE)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.YELLOW)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 2));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.LIME)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 2));
    }else if(block.getType()==Material.STAINED_CLAY&&block.getType().getData().equals(DyeColor.GREEN)){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 3));
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, 3));
    }else if(block.getType()==Material.BEDROCK){
    player.setHealth(20);
    }


    }
    }



    ~~~Thanks for the help tho
     
  5. @YoYoNoYo555
    block.getType().getData().equals(DyeColor.RED) will never return true, as DyeColor is an enum and Material#getData() returns a MaterialData object. Use block#getData() instead, use DyeColor.<color>.getWoolData(), and compare those using == as they are byte values
     
  6. Offline

    _Error

    Use
    [co.de=java]
    // Code here
    and [./code]

    Remove the points.[/code]
     
  7. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page