[Help] WorldGuard API flag

Discussion in 'Plugin Development' started by Cheesepro, Nov 7, 2014.

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

    Cheesepro

    So I was creating a plugin when execute a command, and a small region will be created with particles and only allow the command sender to enter. And everything was great, the region is created, the particles is displayed, but the entry flag is not working... Without further a do, here is the code:

    Code:java
    1. package me.cheesepro.ProtectiveGrenades;
    2.  
    3. import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    4. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    5. import com.sk89q.worldguard.domains.DefaultDomain;
    6. import com.sk89q.worldguard.protection.flags.DefaultFlag;
    7. import com.sk89q.worldguard.protection.flags.StateFlag;
    8. import com.sk89q.worldguard.protection.flags.Flag;
    9. import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
    10. import org.bukkit.plugin.Plugin;
    11. import org.bukkit.*;
    12. import org.bukkit.block.Block;
    13. import org.bukkit.command.Command;
    14. import org.bukkit.command.CommandSender;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import com.sk89q.worldedit.BlockVector;
    19. import org.bukkit.scheduler.BukkitScheduler;
    20.  
    21. /**
    22. * Created by Mark on 06/11/2014.
    23. */
    24. public class Main extends JavaPlugin implements Listener {
    25.  
    26. @Override
    27. public void onEnable() {
    28.  
    29. Bukkit.getPluginManager().registerEvents(this, this);
    30.  
    31. getLogger().info("Plugin Enabled!");
    32. }
    33.  
    34. public void onDisable() {
    35. getLogger().info("Plugin Disabled!");
    36. }
    37.  
    38.  
    39. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    40. if (sender instanceof Player) {
    41. final Player p = (Player) sender;
    42. if(cmd.getLabel().equalsIgnoreCase("shield")){
    43. Location loc1 = new Location(p.getLocation().getWorld(), p.getLocation().getX() + 2, p.getLocation().getY() + 1, p.getLocation().getZ() + 2);
    44. Location loc2 = new Location(p.getLocation().getWorld(), p.getLocation().getX() - 2, p.getLocation().getY(), p.getLocation().getZ() - 2);
    45. final Cuboid cuboid = new Cuboid(loc1, loc2);
    46. final World world = p.getWorld();
    47. final ProtectedCuboidRegion region = new ProtectedCuboidRegion(
    48. "temp_" + p.getName(),
    49. new BlockVector(loc1.getX(), loc1.getY(), loc1.getZ()),
    50. new BlockVector(loc2.getX(), loc2.getY(), loc2.getZ())
    51. );
    52.  
    53. DefaultDomain owners = new DefaultDomain();
    54. owners.addPlayer(getWorldGuard().wrapPlayer(p));
    55.  
    56. region.setOwners(owners);
    57. region.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
    58.  
    59. getWorldGuard().getRegionManager(p.getWorld()).addRegion(region);
    60.  
    61. p.sendMessage(ChatColor.GREEN + "Created shield with ID " + region.getId());
    62.  
    63. final BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    64. final int taskid = scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    65. @Override
    66. public void run() {
    67. for(Block block : cuboid){
    68. world.playEffect(block.getLocation(), Effect.MOBSPAWNER_FLAMES, 10);
    69. }
    70. }
    71. }, 10, 40);
    72.  
    73. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
    74. @Override
    75. public void run() {
    76. Bukkit.getScheduler().cancelTask(taskid);
    77. }
    78. }, 600);
    79.  
    80. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "rg remove " + region.getId() + " -w " + world.getName());
    81.  
    82. }
    83.  
    84. }else{
    85. getLogger().info("Must be in-game Player");
    86. }
    87.  
    88.  
    89. return false;
    90. }
    91.  
    92. private WorldGuardPlugin getWorldGuard() {
    93. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    94.  
    95. if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
    96. return null;
    97. }
    98.  
    99. return (WorldGuardPlugin) plugin;
    100. }
    101.  
    102. private WorldEditPlugin getWorldEdit() {
    103. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    104.  
    105. if (plugin == null || !(plugin instanceof WorldEditPlugin)) {
    106. return null;
    107. }
    108.  
    109. return (WorldEditPlugin) plugin;
    110. }
    111.  
    112.  
    113.  
    114.  
    115.  
    116.  
    117. }
    118.  


    If you know where I got wrong, please do help, Thank you! :D

    Any help?

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

Share This Page