Plugin don't recognize BlockPlaceEvent!!

Discussion in 'Plugin Development' started by FameForAim, Dec 11, 2014.

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

    FameForAim

    Hi everyone, i tried to write a plugin which protect placed chest from other player.
    But my Plugin does not recognize the BlockPlaceEvent.
    So where is my fault?
    - The Eventlistener works!!!! Because the playerdeathevent works! it must be something in the blockplace event.
    Here my class:
    Code:
    package me.ffa.varo;
    
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class Eventlistener implements Listener {  
        public static Varo plugin;
        public Eventlistener(Varo instance) {
            plugin = instance;
        }
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent de) {
            Player p = de.getEntity();
            p.kickPlayer("Du bist aus Varo ausgeschieden");
            p.setBanned(true);
    
    
          
            }
        public void Varo() {
        }
      
        public void onChestCreate(BlockPlaceEvent bp) {
          
            Player p = bp.getPlayer();
            Block placed = bp.getBlockPlaced();
            if(placed.getType() == Material.CHEST) {
                plugin.getConfig().set("Location", placed.getLocation());
                plugin.getConfig().set("Anzahl", 1);
                plugin.saveConfig();
                    p.sendMessage("Die Kiste wurde gesichert");                          
                }
              
            }
      
        public void onPlayerChestopen(PlayerInteractEvent pe) {
            Player p = pe.getPlayer();
            Block interact = pe.getClickedBlock();
            Location loc = interact.getLocation();
            if(interact.getType() == Material.CHEST) {
                if(plugin.getConfig().get("Location") == loc) {
                    if(plugin.getConfig().get("Location" + p) == p) {
                        p.sendMessage("Deine gesicherte Kiste wurde geöffnet");
                    }else if(plugin.getConfig().get("Location" + p) != p) {
                        pe.setCancelled(true);
                        p.sendMessage("Dies ist nicht deine gesicherte Kiste");                  
                    }
                  
                }
    
              
            }
            p.sendMessage("Kiste geöffnet");
        }
        }
    
     
    Last edited by a moderator: Dec 11, 2014
  2. Offline

    mythbusterma

    @FameForAim

    Why would you have a public static reference to your main class?

    Also, you forgot the event handler annotation.
     
  3. Offline

    FameForAim

    This isnt my main class this is the second class :)
     
  4. @FameForAim He's asking why you have "public static Varo plugin"
     
  5. Offline

    FameForAim

    This is the contructor for the main class (varo) :)
    i need it for the getconfig()
     
  6. Offline

    teej107

    @FameForAim
    Because any answer you give honestly won't be a good one. Read up on Encapsulation and don't use static until you know how to properly use it.
     
    PreFiXAUT and AdamQpzm like this.
  7. Offline

    PreFiXAUT

    Like @teej107 said, remove the static and make it private (private Varo plugin).

    Why the Listener doesn't work, is because you forgot the @EventListener Annotations before the Methods.

    --- GERMAN Translated, since he's German and I guess it's easier for him then ---

    Benutz Static einfach nicht. Es macht Sachen zwar einfacher, aber komplett falsch, da es am Gedanken von Objektorientierten Programmiern vorbeigeht. Das is aber nicht das ding der Welt -> Du hast über deine Listener Funktionen das @EventListener vergessen. Dadurch werden die Funktionen nicht als Listener-Funktionen angesehen und werden dadurch nie getriggert. Falls du Hilfe brauchst mit Bukkit/Java dann kann ich dir gern weiterhelfen ;)
     
    Last edited: Dec 11, 2014
    FameForAim and teej107 like this.
  8. Offline

    FameForAim

    Thanks so much:)

    --German:
    Danke:) hab das völlig übersehen :)

    Have another problem now:
    I want on Playerjoin a special part in my config.yml for every Player.

    If this is my config.yml:
    Code:
    Player:
        Spieler1:
            Location:
            Anzahl:
    On player join of player "xyz" should stand there than:
    Code:
    Player:
        Spieler1:
            Location:
            Anzahl:
        xyz:
            Location: (should be inserted later)
            Anzahl: 0
    How do i manage this?
    I dont know the command of the getConfig to create a new "Categorie".
    Can someone help me please?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Dec 11, 2014
  9. Offline

    mythbusterma

    @SuperOriginal

    I would use ConfigurationSection#set(path,Object) so that way it won't overwrite an already created section.
     
    FameForAim and SuperOriginal like this.
  10. Offline

    FameForAim

Thread Status:
Not open for further replies.

Share This Page