Help needed with my region market plugin

Discussion in 'Plugin Development' started by mgbeenieboy, Sep 11, 2014.

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

    mgbeenieboy

    I want a plugin for my server that allows players to buy worldguard regions with a right click on a sign. The sign should be created with [gs] in the first line and the price in the second line.

    What already works:

    onSignChangeEvent, when [gs] is in the first line, the sign becomes it's right format. You know, with [Buy] and so.

    onPlayerInteractEvent with a sign, the player becomes the owner of the region in which the sign stands. He buys the region. So that works.

    The problem:

    As I said, onPlayerInteractEvent with A sign! It doesn't matter which sign it is and what's on the sign. What is the best way to fix that?

    Code:java
    1. double preis;
    2.  
    3. @EventHandler
    4. public void onSignChange(SignChangeEvent e) {
    5. if(e.getLine(0).equalsIgnoreCase("[gs]")) {
    6. preis = Double.parseDouble(e.getLine(1));
    7. e.setLine(0, "[§2Kaufen§r]");
    8. e.setLine(1, "Preis: §f" + e.getLine(1) + "€");
    9. }
    10. }
    11.  
    12. @EventHandler
    13. public void onPlayerInteract(PlayerInteractEvent e) {
    14. if(e.getAction() == (Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType() == Material.SIGN_POST) {
    15. Sign sign = (Sign) e.getClickedBlock().getState();
    16. if(economy.getBalance(e.getPlayer()) >= preis) {
    17. ApplicableRegionSet set = WGBukkit.getRegionManager(Bukkit.getWorld("world")).getApplicableRegions(e.getClickedBlock().getLocation());
    18. economy.withdrawPlayer(e.getPlayer(), preis);
    19. for (ProtectedRegion region : set) {
    20. Bukkit.broadcastMessage("4");
    21. DefaultDomain owners = new DefaultDomain();
    22. owners.addPlayer(e.getPlayer().getName());
    23. region.setOwners(owners);
    24.  
    25. }
    26. sign.setLine(0, "§lGEKAUFT!");
    27. sign.setLine(1, null);
    28. sign.setLine(2, "Neuer Besitzer:");
    29. sign.setLine(3, e.getPlayer().getName());
    30. sign.update();
    31. e.getPlayer().sendMessage("§aDu hast das Grundstück für " + preis + "€ gekauft!");
    32.  
    33. } else {
    34. e.getPlayer().sendMessage("§cDu hast nicht genug Geld um dieses Grundstück zu kaufen.");
    35. }
    36. }
    37. }
     
  2. Offline

    fireblast709

  3. Offline

    mgbeenieboy


    if(e.getAction()==(Action.RIGHT_CLICK_BLOCK)&& e.getClickedBlock().getType()== Material.SIGN_POST){


    It already is in the code, but that doesn't fix the problem that EVERY placed sign_post has the effect, instead of only those which were made with [gs] in the first line.
     
  4. Offline

    fireblast709

    mgbeenieboy that doesn't check for wall signs though ;3. Also, once you got your Sign object, check if line 0 equals "[§2Kaufen§r]" and get the price from parsing the second line.
     
  5. Offline

    mgbeenieboy


    It will never be a wall sign ;D
    But how does the plugin know this sign is a sign made with [gs] in the first line and the price in the second and not a fake?
     
  6. Offline

    fireblast709

    mgbeenieboy why would you bother checking that? But if you must, you could check the SignChangeEvent for "[§2Kaufen§r]" and check if the person who edited the sign has the right permission.
     
  7. Offline

    mgbeenieboy


    The permission would only allow to automaticly change the sign from "[gs], 100" to "[Kaufen], Price: 100€". But if you directly create a sign with "[Kaufen]" the plugin would think it's a valid plot-buy-sign.
     
  8. Offline

    fireblast709

    mgbeenieboy According to your code it contains colour codes, which under normal conditions cannot be typed directly on signs. If you have a plugin that allows this, I refer to the second part of my post.
     
  9. Offline

    mgbeenieboy

    Creating colorful signs is possible on my server, also for normal users.

    I added a permission to create these signs. But they do need the permission anyways. The permission just allows to change the sign from [gs] to [Kaufen] and so. You can still create a sign with [Kaufen] that'll work as if you created the sign with [gs], know what I mean?
     
  10. Offline

    fireblast709

    mgbeenieboy
    Gave you this fix like 4 posts ago :p
     
  11. Offline

    mgbeenieboy


    I answered like 3 times now. This is not the solution, because the permission does not allow to create buy-signs, it allows to let the plugin change the lines of the sign from [gs] to [Kaufen], not more, and that's the problem.
     
  12. Offline

    fireblast709

    mgbeenieboy First check if the line is [Kaufen] (with colours). If it equals, change it to something else and perhaps send a message to the player. Then check if the line equals "[gs]", and change it accordingly.
     
  13. Offline

    mgbeenieboy

    fireblast709 Sorry, I don't understand :confused: Maybe you try explaining what you mean in a code?
     
  14. Offline

    fireblast709

    mgbeenieboy
    Code:
    if(line 0 equals "[Kaufen]")
        nope, not allowed
    else if(line 0 equals "[gs]")
        set line 0 to "[Kaufen]"
     
  15. Offline

    mgbeenieboy

    fuuu... of course. How couldn't I think about that. I hope

    set line 0 to "[Kaufen]"

    does not trigger the signchangeevent ;D

    thank you :)
     
  16. If you are talking about the Essentials buy sign you will need to do one of the following things:
    - Hook into Essentials and try to call an event for sign creation
    - Call a Bukkit event to mimic sign placing
     
  17. Offline

    N00BHUN73R

    adventuretc
    He's not talking about that, He's making a sign in which users can buy worldguard regions.
     
Thread Status:
Not open for further replies.

Share This Page