[Solved] Storage Minecart protection?

Discussion in 'Plugin Development' started by recon88, Feb 22, 2012.

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

    recon88

    I'm confused about this storage minecart stuff.
    How to protect it? I just messed around a bit.

    I tried this, but it seems to be totally wrong:

    PHP:
        @EventHandler
        
    public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event){
            if (!(
    event.getRightClicked() instanceof StorageMinecart)) {
                return;
                }
            if(
    event instanceof PlayerInteractEntityEvent){
                
    PlayerInteractEntityEvent evt = (PlayerInteractEntityEventevent;
                if(
    evt.getPlayer() instanceof Player){
                        
    Player player = (Playerevt.getPlayer();
                        
    OwnedChunk newchunk = new OwnedChunk(event.getRightClicked().getLocation().getBlock().getChunk());
                        
    String claimcheck plugin.RegionHandler.ClaimCheck(newchunk);
                        if (
    claimcheck != ""){
                            if (new 
    ConfigChunk(newchunk).animal==1){
                                if (
    plugin.RegionHandler.CanBuildHere(playernewchunk) == false){
                                    
    event.setCancelled(true);
                                    
    player.sendMessage(ChatColor.RED "cart owned by " claimcheck ". can't steal here.");
                                }
                            }
                        }
                    }
            }
     
        }
    Nobody? :/
    Still can't finde the mistake

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  2. Offline

    Sir Savary

    recon88
    Well, post a stack trace/server.log.

    Edit: Tell us what you need really, is it broken? Do you get an error? Do you not know how to do it?
     
  3. Offline

    recon88

    No errors.
    No debug messages.
    Just nothing happens. Plugin loads correctly.
    And yes the event is registered (if i took the right one)

    What i need:
    If someone right clicks on a storage minecart it should cancel the event. But i'm not sure that i used the right stuff in my code.
     
  4. Offline

    Sir Savary

    recon88
    To cancel an event, that code is very, very wrong. Here is a fixed version:
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event){
    4. if (!(event.getRightClicked() instanceof StorageMinecart)) {
    5. event.setCancelled(true);
    6. }
    7.  
    8. }
    9.  
     
  5. Offline

    recon88

    That's the same i already got.

    The rest of the code is the chunk management system.
    I mean the storage minecart is only protected in someones chunk.
    But i can't figure out what's wrong with it.


    PHP:
    // General Stuff //
    @EventHandler
        
    public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event){
            if (!(
    event.getRightClicked() instanceof StorageMinecart)) {
                return;
                }
     
    // From here there is something wrong //
            
    if(event instanceof PlayerInteractEntityEvent){
                
    PlayerInteractEntityEvent evt = (PlayerInteractEntityEventevent;
                if(
    evt.getPlayer() instanceof Player){
                        
    Player player = (Playerevt.getPlayer();
                        
    OwnedChunk newchunk = new OwnedChunk(event.getRightClicked().getLocation().getBlock().getChunk());
               
              
    // That part should be right //
          
    String claimcheck plugin.RegionHandler.ClaimCheck(newchunk);
                    if (
    claimcheck != ""){
                            if (new 
    ConfigChunk(newchunk).storage==1){
                                if (
    plugin.RegionHandler.CanBuildHere(playernewchunk) == false){
                                    
    event.setCancelled(true);
                                    
    player.sendMessage(ChatColor.RED "cart owned by " claimcheck ". can't steal here.");
                                }
                            }
                        }
                    }
            }
     
        }
     
  6. Offline

    dillyg10

    • Do not fill the forums with useless content.
    Lol, storage carts...
     
  7. Offline

    Sir Savary

    recon88
    Try this
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event){
    4. if (!(event.getRightClicked() instanceof StorageMinecart)) {
    5. return;
    6. }
    7. Player player = event.getPlayer();
    8. OwnedChunk newchunk = new OwnedChunk(event.getRightClicked().getLocation().getBlock().getChunk());
    9.  
    10. String claimcheck = plugin.RegionHandler.ClaimCheck(newchunk);
    11. if (claimcheck != ""){
    12. if (new ConfigChunk(newchunk).storage==1){
    13. if (plugin.RegionHandler.CanBuildHere(player, newchunk) == false){
    14. event.setCancelled(true);
    15. player.sendMessage(ChatColor.RED + "cart owned by " + claimcheck + ". can't steal here.");
    16. }
    17. }
    18. }
    19. }
    20.  


    dillyg10
    This is not the first time I've seen you post irrelevant information in a thread, take it elsewhere.
     
  8. Offline

    recon88

    What's so Lol with it? Never saw a storage system with this minecarts?
    Go troll other forums -.-°



    Thanks man. Works great =)
    .
     
  9. Offline

    dillyg10

    No, I'm just saying that it's pretty funny that somone finally is trying to make a use of them, concidering notch couldn't even figure out how to :D
     
  10. Offline

    recon88

  11. Offline

    dillyg10

    K, good luck with your plugin, I'll make sure I'll dl it :D when it's done :).
     
  12. Offline

    Sir Savary

    recon88
    I guess I should be responsible here and tell you what I did. Bascially, you were checking to see if the event was an instance of that very event, so you had it twice. You were also casting Player to a getPlayer() method, which is pointless. You also checked to see if getPlayer() returned a player, also pointless. So, just double check little things like that next time :)
     
  13. Offline

    recon88

    Yea, now I'm seeing what's wrong with it...
    Should not work on plugins if i'm sick but need to finish this soon.

    Thanks for helping me =)
     
  14. Offline

    Sir Savary

    recon88
    You're welcome, I love helping people because it helps me improve my code :)
     
  15. Sooo do you have a plugin page for this???
     
Thread Status:
Not open for further replies.

Share This Page