Signs doesn't works

Discussion in 'Plugin Development' started by Betagear, Sep 6, 2015.

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

    Betagear

    Hi.
    I've got a code to get the sign's lines, and it doesn't outputs anything. My code :
    Code:
               Block targetblock = actor.getClickedBlock();
                player.sendMessage("Type : " + targetblock.getType());
                Sign TargetSign =(Sign)targetblock.getState();
                player.sendMessage("First line : " + TargetSign.getLine(0));
    I can see Type : SIGN_POST or Type : WALL_SIGN but in all the cases It never outputs the line 0. I used org.bukkit.block.sign, registered my event (It's a PlayerInteractEvent), but it still doesn't does anything and doesn'tsays First Line :
    Help requested :)
     
  2. Offline

    DuaneTheDev_

    Last edited: Sep 7, 2015
  3. Offline

    Betagear

    Still doesn't works. The sign is not empty but it doesn't outputs.
     
  4. Offline

    DuaneTheDev_

  5. Offline

    Betagear

    Yep, here it is, and I don't know what can cause this problem :
    Code:
        @EventHandler(priority = EventPriority.HIGH)
        public void Interactions(PlayerInteractEvent actor) { //Ecoute des clics, travail à faire sur les vies et le retour au hub
            Player player = actor.getPlayer(); //Joueur
            Action action = actor.getAction(); //Clic
            if (TrueWorld(actor.getPlayer())) {
                switch (actor.getPlayer().getGameMode()) {
                case SURVIVAL:
                   
                    if (player.getItemInHand().getType() == Material.TNT) {
                        switch (action) {
                        case RIGHT_CLICK_AIR:
                        case RIGHT_CLICK_BLOCK:
                           
                            if (player.getWorld().getBlockAt(player.getLocation().add(0, -0.01, 0)).getType() == Material.AIR) {
                                player.setFallDistance(5);
                                Vector Stompvelocity = new Vector(0, - 1 - (player.getItemInHand() .getAmount() /2), 0);
                                player.setVelocity(Stompvelocity);
                                player.getWorld().playSound(player.getLocation(), Sound.FUSE, 2, 1);
                                player.setMetadata("Fallpower", new FixedMetadataValue(plugin, player.getItemInHand().getAmount()));
                                player.setMetadata("FallY", new FixedMetadataValue(plugin, player.getLocation().getY()));
                                player.getInventory().remove(Material.TNT);
                            }
                           
                            break;
                           
                        case LEFT_CLICK_AIR:
                        case LEFT_CLICK_BLOCK:
                           
                            if (player.getItemInHand().getAmount() > 1 && player.getLocation().getY() > minposY(player) -20) {
                               
                                if (player.hasMetadata("AltFlight")) {
                                    DashForward(player, 2, 0, true, true);
                                } else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
                                    DashForward(player, 1.5, 0.75, true, false);
                                } else if(player.hasPotionEffect(PotionEffectType.SLOW)) {
                                    player.setVelocity(player.getVelocity().setY(2));
                                } else {
                                    player.setVelocity(player.getVelocity().setY(1.25));
                                }
                                player.getWorld().playSound(player.getLocation(), Sound.FIZZ, 1, 1);
                                player.getInventory().setItemInHand(new ItemStack(Material.TNT, player.getItemInHand().getAmount() - 1));
                            }
                           
                            break;
           
                        default:
                            break;
                        }
                    }
                   
                    break;
                   
                case CREATIVE:
                    if (action == Action.LEFT_CLICK_AIR || action == Action.RIGHT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK || action == Action.RIGHT_CLICK_BLOCK) {
                        switch (player.getItemInHand().getType()) {
                        case EXP_BOTTLE:
                           
                           
                            //Consummer une vie
                           
                            player.getInventory().clear();
                            for (Player others : Bukkit.getOnlinePlayers()) {
                                others.showPlayer(player);
                            }
                            player.teleport(player.getWorld().getSpawnLocation());
                            player.setGameMode(GameMode.SURVIVAL);
                            player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 100, 1));
                            break;
                           
                        case BARRIER:
                           
                           
                            //Retourner au Hub
                           
                           
                            break;
       
                        default:
                            break;
                        }
                    }
                    break;
       
                default:
                    break;
                }
            } else { // This is what will interest you.
                Block targetblock = actor.getClickedBlock();
                player.sendMessage("Type : " + targetblock.getType());
                Sign TargetSign =(Sign)targetblock.getState();
                player.sendMessage("First Line : " + TargetSign.getLine(0));
                switch (targetblock.getType()) {
                case SIGN_POST:
                case WALL_SIGN:
                   
                    if (TargetSign.getLine(0) == "StompArena") {
                        player.sendMessage("It works");
                        for (World world : Bukkit.getWorlds()) {
                            if (TargetSign.getLine(1).equalsIgnoreCase(plugin.getConfig().getString("General.World." + world.getName() + ".Type"))) {
                                if (plugin.getConfig().getBoolean("General.Signs." + TargetSign.getLocation().toString())) {
                                    player.teleport(world.getSpawnLocation());
                                }
                            }
                        }
                    }
                    break;
                default:
                    break;
                }
            }
        }
        
     
  6. Offline

    Hawktasard

  7. Offline

    AdobeGFX

    @Betagear That is a completely new code..
    lel never mind, didn't scroll down to the bottom :)
     
  8. @Betagear
    There are 2 Sign classes, 1 of type MaterialData and 1 of type BlockState. I'm guessing you imported the MaterialData (package org.bukkit.material), replace it with org.bukkit.block.Sign
     
  9. Offline

    Betagear

    This is what I did since the first post.

    The interesting part is in the bottom, and this is only a tiny chunk of my whole code :)
     
  10. Offline

    stormneo7

    What's that supposed to mean?

    Also, is this triggering?
    player.sendMessage("Type : "+ targetblock.getType());

    If not, can you show us what TrueWorld(actor.getPlayer()) is?
     
  11. Offline

    Betagear

    I said this is a tiny chunk because my whole code lenghts 884 lines. The player.sendMessage("Type : "+ targetblock.getType()); is just a test to make that the sign is detected.
    The top part won't help you, I sent it just becaue he asked me. TrueWorld is a test to make sure that the world the player is on is an enabled arena... miscelianous stuff...
    I really don't know what to do, signs still doesn't works, I tried to do it with a command, still same results.
    Here are all my imports, I think there is something that matters.
    Code:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.event.entity.ItemSpawnEvent;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerGameModeChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.metadata.FixedMetadataValue;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.util.Vector;
    
    and for the main class :
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    All my code works, except the part to get the sign lines : Still getting nothing, I'll try redownloading Bukkit again to see if it works better then.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page