I tryed to code a plugin who disables xp bottles when gamemode is Creativ

Discussion in 'Plugin Development' started by Lemonn_, Jul 12, 2012.

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

    Lemonn_

    Code:
    package NoXpmain;
     
     
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.EntityType;
     
     
    public class NoXpMainClass extends JavaPlugin implements Listener{
     
     
    @Override
    public void onEnable() {
    this.getServer().getPluginManager().registerEvents(this, this);
     
    }
     
     
    @EventHandler
    public void PlayerInteractEntityEvent(PlayerEvent event) {
     
    if (event.getPlayer().getGameMode() == GameMode.SURVIVAL);
        return;
        }
     
    public void preventLaunches(ProjectileLaunchEvent event) {
       
            if (event.getEntityType() == EntityType.EGG){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SNOWBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_SIGNAL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.FIREBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SPLASH_POTION){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_PEARL){
            event.setCancelled(true);
            }
            }
            }
    When i login and i try my plugin in crative or survival mode nothing get blocked
    i am not really good in coding java so can someone help me please
     
  2. Offline

    bartboy8

    Put @EventHandler above public void preventLaunches(ProjectileLaunchEvent event) {
     
  3. Offline

    Lemonn_

    do you mean

    Code:
    package NoXpmain;
     
     
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.EntityType;
     
     
    public class NoXpMainClass extends JavaPlugin implements Listener{
     
     
    @Override
    public void onEnable() {
    this.getServer().getPluginManager().registerEvents(this, this);
     
    }
     
     
    @EventHandler
    public void PlayerInteractEntityEvent(PlayerEvent event) {
     
    if (event.getPlayer().getGameMode() == GameMode.SURVIVAL);
        return;
        }
     
    @EventHandler
    public void preventLaunches(ProjectileLaunchEvent event) {
     
            if (event.getEntityType() == EntityType.EGG){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SNOWBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_SIGNAL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.FIREBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SPLASH_POTION){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_PEARL){
            event.setCancelled(true);
            }
            }
            }
     
  4. Offline

    VeryBIgCorp

    (unrelated)
    In your PlayerInteractEntityEvent, it will always return, regardless of the result of the if statement.
     
  5. PlayerEvent
    is also wrong, that causes an error while registering the listener
     
  6. Offline

    Lemonn_

    can someone help me to fix the code. It will be helpfull for me i do not now how long i have to read untill I am able to fix that problem

    Code:
    package NoXpmain;
     
     
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
     
     
    public class NoXpMainClass extends JavaPlugin implements Listener{
     
     
    @Override
    public void onEnable() {
    this.getServer().getPluginManager().registerEvents(this, this);
     
    }
     
     
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event1) {
    Player player = event1.getPlayer();
    if ((event1.getAction() == Action.RIGHT_CLICK_AIR)){
    if (player.getGameMode() == GameMode.CREATIVE);}
        }
    public void preventLaunches(ProjectileLaunchEvent event) {
     
            if (event.getEntityType() == EntityType.EGG){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SNOWBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_SIGNAL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.FIREBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SPLASH_POTION){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_PEARL){
            event.setCancelled(true);
            }
            }
            }
     
  7. Offline

    Kenazi

    Just a thought, try this:

    Code:
    @EventHandler
    public void preventLaunches(ProjectileLaunchEvent event) {
            Player player = event.getPlayer();
     
            if(player.getGameMode == GAMEMODE.SURVIVAL){
            return;
     
            if (event.getEntityType() == EntityType.EGG){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SNOWBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_SIGNAL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.FIREBALL){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.SPLASH_POTION){
            event.setCancelled(true);
            }
            else if (event.getEntityType() == EntityType.ENDER_PEARL){
            event.setCancelled(true);
            }
            }
            }
    I'm still pretty new though, and I didn't test it.. and you may have to add or remove some brackets, but it may work.
     
  8. Offline

    EnvisionRed

    Make sure to register the events in your onEnable ^-^
     
  9. Offline

    messageofdeath

Thread Status:
Not open for further replies.

Share This Page