[WorldEdit API] Save that area that was set and protect it

Discussion in 'Plugin Development' started by PlayerNerd, Jan 5, 2015.

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

    PlayerNerd

    I´m creating a minigame plugin and i don´t have any ideia of how can i set the area of the minigame in the world and protect and save it.
    How can i save the area that was set for the minigame and how can i protect it with the WorldEdit API??
    (When the server reload, the area of minigame still in tha same place).
     
  2. Offline

    nj2miami

    Are you asking how would you interface with WorldEdit to define/capture the region by using its (hard to use) API? That is a very complex task. Are you up for it? Show some code of where you are at.
     
  3. Offline

    PlayerNerd

    @nj2miami I never used the api, so i don´t have a code, but i really wanna try to learn and make it.
     
  4. Offline

    xMakerx

    @PlayerNerd

    Hi, I've created a few minigame plugins for my server. If you would like the regions to be protected, I'd recommend you get the latest WorldGuard and use it in your plugin. What I mainly do is create an Arena class that takes a ProtectedCuboidRegion. You can get a player's selection by doing this:

    Code:
    Selection sel = worldEdit.getSelection(player);
    With that selection you can create a new ProtectedCuboidRegion like this:
    Code:
    ProtectedCuboidRegion region = new ProtectedCuboidRegion("ARENA_NAME", sel.getNativeMinimumPoint().toBlockVector(), sel.getNativeMaximumPoint().toBlockVector());
    You would then pass that to your arena. That should get you on the right path. I've included some links below to help you even further. Good luck on your plugin!

    ProtectedCuboidRegion API Reference page: http://docs.sk89q.com/worldguard/ap...protection/regions/ProtectedCuboidRegion.html

    Information on using the WorldGuard API: http://wiki.sk89q.com/wiki/WorldGuard/Regions/API

    Information on using the WorldEdit API: http://www.sk89q.com/2013/03/worldedit-selections-for-bukkit-plugins/
     
    Europia79 likes this.
  5. Offline

    PlayerNerd

    @xMakerx But when the server restarts Will it stay save? And i need make a certains regions to get points in minigame, can i make the WorldGuard doesn´t show it in /rg list??
     
    Last edited: Jan 6, 2015
  6. Offline

    xMakerx

    @PlayerNerd

    You have to manually save the region(s) yourself in a FileConfiguration or YamlConfiguration. You get the minimum and maximum points, save them, and load them when the server restarts.
     
  7. Offline

    PlayerNerd

    @xMakerx I use this code when i create the arena, it creates but the region doesn´t work.

    Code:
    ProtectedCuboidRegion region = new ProtectedCuboidRegion(args[2],
                                            s.getNativeMinimumPoint().toBlockVector(), s.getNativeMaximumPoint().toBlockVector());
                                   
                                    StateFlag flag = DefaultFlag.BUILD;
                                    region.setFlag(flag, State.DENY);
                                    StateFlag flag2 = DefaultFlag.TNT;
                                    region.setFlag(flag2, State.DENY);
                                    StateFlag flag3 = DefaultFlag.PVP;
                                    region.setFlag(flag3, State.DENY);
    Can i make it doesn´t appear in the list of regions??
     
  8. Offline

    xMakerx

    @PlayerNerd

    I don't think you can make it so it doesn't appear in the list of regions. Is the region not denying the flags correctly?
    Here's an example that you should try:

    Code:
            HashMap<Flag<?>, Object> flags = new HashMap<Flag<?>, Object>();
            flags.put(DefaultFlag.BUILD, State.DENY);
            flags.put(DefaultFlag.CREEPER_EXPLOSION, State.DENY);
            flags.put(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, State.DENY);
            flags.put(DefaultFlag.PVP, State.ALLOW);
            flags.put(DefaultFlag.USE, State.ALLOW);
            flags.put(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE, State.DENY);
            flags.put(DefaultFlag.DESTROY_VEHICLE, State.DENY);
            region.setFlags(flags);
     
  9. Offline

    PlayerNerd

    @xMakerx Nothing. When i use /rg list it don´t show nothing, i think that the region isn´t save.
     
  10. Offline

    xMakerx

    You have to add the region manually like this:

    Code:
    WGBukkit.getRegionManager(world).addRegion(region);
     
  11. Offline

    PlayerNerd

    @xMakerx How can i use the flag blocked-cmds in API??
     
  12. Offline

    xMakerx

    @PlayerNerd

    I don't understand what you mean. The flag example I gave you lets you setup flags. If you mean toggling flags with commands, you would just modify the flags after a command is executed.
     
  13. Offline

    PlayerNerd

    @xMakerx Okay. Is possible detect when the player pass by a specific region??
     
  14. Offline

    xMakerx

    Yup. Here's a thread that should help you out: http://bukkit.org/threads/check-if-a-player-is-in-a-certain-region.287693/. Do not use a PlayerMoveEvent, though, it's very expensive, try using a BukkitRunnable and test after a while. Just to make it a little cheaper on resources, try only iterating over players in the world of your minigame(s) region(s).
     
  15. Offline

    PlayerNerd

  16. Offline

    xMakerx

    You're welcome.
     
  17. Offline

    PlayerNerd

    @xMakerx Could you give me an example??
     
  18. Offline

    xMakerx

    @PlayerNerd

    I really don't want to code a brand new example, so just work from this I used for my other plugin:

    Code:
        public void startOutpostListening() {
            int delayTime = 5;
            new BukkitRunnable() {
                @SuppressWarnings("deprecation")
                public void run() {
                    if(stopCustomEvents) this.cancel();
                    Player[] players = main.getServer().getOnlinePlayers();
                    for(Player player : players) {
                        Location location = player.getLocation();
                        ApplicableRegionSet regions = worldGuard.getRegionManager(player.getWorld()).getApplicableRegions(location);
                        if(regions.size() > 0) {
                            Outpost outpost = getOutpostFromRegion(regions);
                            if(outpost != null) {
                                main.getServer().getPluginManager().callEvent(new OutpostEnterEvent(outpost, player));
                                playersInOutposts.put(player, outpost);
                            }
                        }
                        if(playersInOutposts.containsKey(player)) {
                            Outpost outpost = playersInOutposts.get(player);
                            if(outpost != null) {
                                main.getServer().getPluginManager().callEvent(new OutpostLeaveEvent(outpost, player));
                                playersInOutposts.remove(player);
                            }
                        }
                    }
                }
            }.runTaskTimer(main, (20 * delayTime), (20 * delayTime));
        }
     
  19. Offline

    PlayerNerd

  20. Offline

    xMakerx

    Sure. This method has a BukkitRunnable that runs every 5 seconds and checks every player online's location and sees if they're inside of an Outpost region since this is for my Outpost plugin. Which for what you're making you'd probably have to iterate through each region in the ApplicableRegionSet to see if a player is in your minigame region. Back to what my example is. On line 12 I call another custom method I made which just iterates through the regions and sees if there is an outpost at a certain region, if so, it calls a custom event that a player entered an outpost region and places a player and outpost pair into a HashMap, which is used to see if the player has left a region later on. Next, on line 12, this is what is suppose to happen if there isn't an outpost in that region, but the if statement is out of place, just act like I put it on line 23 as an else if XD. So, it if finds that a player is not in an outpost region anymore and it sees that there is a player and outpost pair for that player in the HashMap it knows that they have exited an outpost region, so it removes them from the HashMap and calls another custom event that a player has left an outpost.

    Let me know if you have any other questions. I hope I explained that well enough.
     
  21. Offline

    Europia79

    @PlayerNerd

    If you want to code a minigame, then you could always use the BattleArena Framework:
    http://dev.bukkit.org/bukkit-plugins/battlearena2/

    Making a minigame with BattleArena is easy:

    Just make your Arena class:
    Code:java
    1. import mc.alk.arena.objects.arenas.Arena;
    2.  
    3. public class ExampleArena extends Arena {
    4.  
    5. ExamplePlugin plugin;
    6.  
    7. @Persist
    8. Map<Integer, Location> bases = new HashMap<Integer, Location>(); // key = teamID
    9.  
    10. public ExampleArena(ExamplePlugin reference) {
    11. plugin = reference;
    12. }
    13.  
    14. @ArenaEventHandler
    15. public void onMatchStartEvent(MatchStartEvent e) { }
    16.  
    17. @Override
    18. public void onStart() { }
    19.  
    20. @Override
    21. public void onFinish() { }
    22.  
    23. @ArenaEventHandler
    24. public void onBlockBreakEvent(BlockBreakEvent e) { }
    25.  
    26. }


    Then just register your arena class with BattleArena:
    Code:java
    1. public class ExamplePlugin extends JavaPlugin {
    2.  
    3. ExampleArenaFactory factory;
    4.  
    5. @Override
    6. public void onEnable() {
    7.  
    8. saveDefaultConfig();
    9. loadDefaultConfig();
    10.  
    11. factory = new ExampleArenaFactory(this);
    12. BattleArena.registerCompetition(this, "ExampleArenaName", "example_cmd", factory, new ExampleExecutor());
    13.  
    14. }
    15.  
    16. @Override
    17. public void onDisable() {
    18. factory.disableArenas();
    19. }
    20. }


    Making Commands is easier & cleaner too. Take a look at one of mine:
    Code:java
    1.  
    2. package mc.euro.demolition.commands;
    3.  
    4. import mc.euro.demolition.BombPlugin;
    5. import java.util.List;
    6. import java.util.Set;
    7. import mc.alk.arena.BattleArena;
    8. import mc.alk.arena.executors.CustomCommandExecutor;
    9. import mc.alk.arena.executors.MCCommand;
    10. import mc.alk.arena.objects.arenas.Arena;
    11. import mc.alk.arena.util.SerializerUtil;
    12. import mc.alk.tracker.objects.PlayerStat;
    13. import mc.alk.tracker.objects.Stat;
    14. import mc.alk.tracker.objects.StatType;
    15. import mc.euro.demolition.BombArena;
    16. import mc.euro.demolition.debug.DebugOff;
    17. import mc.euro.demolition.debug.DebugOn;
    18. import mc.euro.demolition.util.BaseType;
    19. import org.bukkit.Bukkit;
    20. import org.bukkit.ChatColor;
    21. import org.bukkit.Location;
    22. import org.bukkit.Material;
    23. import org.bukkit.OfflinePlayer;
    24. import org.bukkit.Sound;
    25. import org.bukkit.command.CommandSender;
    26. import org.bukkit.command.ConsoleCommandSender;
    27. import org.bukkit.entity.Player;
    28. import org.bukkit.inventory.ItemStack;
    29. import org.bukkit.scheduler.BukkitRunnable;
    30.  
    31. /**
    32.  * All the /bomb commands and subcommands.
    33.  * @author Nikolai
    34.  */
    35. public class BombExecutor extends CustomCommandExecutor {
    36.  
    37. BombPlugin plugin;
    38.  
    39. public BombExecutor() {
    40. plugin = (BombPlugin) Bukkit.getServer().getPluginManager().getPlugin("BombArena");
    41. }
    42.  
    43. @MCCommand(cmds={"addbase"}, perm="bombarena.addbase", usage="addbase <arena>")
    44. public boolean addbase(Player sender, Arena a) {
    45. if (!(a instanceof BombArena)) {
    46. sender.sendMessage("Arena must be a valid BombArena.");
    47. return false;
    48. }
    49. BombArena arena = (BombArena) a;
    50. Location loc = sender.getLocation();
    51. Location base_loc = plugin.getExactLocation(loc);
    52.  
    53. if (base_loc == null) {
    54. sender.sendMessage("addbase command failed to find a BaseBlock near your location.");
    55. sender.sendMessage("Please set 2 BaseBlocks in the arena (1 for each team).");
    56. sender.sendMessage("If you have already set BaseBlocks, then stand closer and re-run the command.");
    57. return true;
    58. }
    59. if (arena.getBases().contains(base_loc)) {
    60. sender.sendMessage("Arena: " + a.getName() + " already contains that base");
    61. return true;
    62. }
    63. arena.addBase(base_loc);
    64. BattleArena.saveArenas(plugin);
    65. sender.sendMessage("Base added to arena: " + a.getName());
    66. return true;
    67. }
    68.  
    69. @MCCommand(cmds={"setbase"}, perm="bombarena.setbase", usage="setbase <arena> <teamID>")
    70. public boolean setbase(Player sender, Arena arena, Integer i) {
    71. if (i < 1 || i > 2) {
    72. sender.sendMessage("Bomb arenas can only have 2 teams: 1 or 2");
    73. return true;
    74. }
    75. // path {arenaName}.{index}
    76. String path = arena.getName() + "." + i.toString();
    77. Location loc = sender.getLocation();
    78. Location base_loc = plugin.getExactLocation(loc);
    79. if (base_loc == null) {
    80. sender.sendMessage("setbase command failed to find a BaseBlock near your location.");
    81. sender.sendMessage("Please set 2 BaseBlocks in the arena (1 for each team).");
    82. sender.sendMessage("If you have already set BaseBlocks, then stand closer and re-run the command.");
    83. return true;
    84. }
    85. String sloc = SerializerUtil.getLocString(base_loc);
    86. plugin.basesYml.set(path, sloc);
    87. plugin.basesYml.saveConfig();
    88. sender.sendMessage("Base " + i + " is now set for arena: " + arena.getName());
    89. return true;
    90.  
    91. }
    92.  
    93. @MCCommand(cmds={"spawnbomb"}, perm="bombarena.spawnbomb", usage="spawnbomb <arena>")
    94. public boolean spawnbomb(Player sender, String a) {
    95. plugin.debug.log("arena = " + a);
    96. Arena arena =(BombArena) BattleArena.getArena(a);
    97. if (arena == null) return false;
    98. Material bomb = plugin.getBombBlock();
    99. int matchTime = arena.getParams().getMatchTime();
    100.  
    101. plugin.debug.log("spawnbomb() MatchTime = " + matchTime);
    102.  
    103. String selectArena = "aa select " + arena.getName();
    104.  
    105. if (plugin.getServer().dispatchCommand(sender, selectArena)
    106. && plugin.getServer().dispatchCommand(sender,
    107. Command.addspawn(bomb.name(), matchTime))) {
    108. sender.sendMessage("The bomb spawn for " + arena.getName() + " has been set!");
    109. return true;
    110. }
    111. sender.sendMessage("The spawnbomb command has failed.");
    112. return false;
    113. }
    114.  
    115. @MCCommand(cmds={"stats"}, perm="bomb.stats", usage="stats")
    116. public boolean stats(CommandSender sender) {
    117. if (sender instanceof ConsoleCommandSender) {
    118. sender.sendMessage("Invalid command syntax: Please specify a player name");
    119. sender.sendMessage("./bomb stats <player>");
    120. sender.sendMessage("or /bomb stats top X");
    121. return true;
    122. }
    123. stats(sender, plugin.getServer().getOfflinePlayer(sender.getName()));
    124. return true;
    125. }
    126.  
    127. @MCCommand(cmds={"stats"}, perm="bomb.stats.other", usage="stats <player>")
    128. public boolean stats(CommandSender sender, OfflinePlayer p) {
    129. if (!plugin.ti.isEnabled()) {
    130. plugin.getLogger().warning("BattleTracker not found or turned off.");
    131. sender.sendMessage("BombArena statistics are not being tracked.");
    132. return true;
    133. }
    134. PlayerStat ps = plugin.ti.tracker.getPlayerRecord(p);
    135. int wins = ps.getWins();
    136. int ties = ps.getTies();
    137. int losses = ps.getLosses();
    138. int total = wins + losses;
    139. int percentage = (total == 0) ? 0 : (int) (wins * 100.00) / total;
    140. String intro = (sender.getName().equalsIgnoreCase(p.getName())) ?
    141. "You have" : p.getName() + " has";
    142. sender.sendMessage(intro + " successfully destroyed the other teams base "
    143. + wins + " times out of " + total + " attempts. ("
    144. + percentage +"%)");
    145. sender.sendMessage(intro + " defused the bomb " + ties + " times.");
    146. return true;
    147. }
    148.  
    149. /**
    150.   * Shows bomb arena stats for the command sender.
    151.   * Example Usage: /bomb stats top 5
    152.   */
    153. @MCCommand(cmds={"stats"}, subCmds={"top"}, perm="bomb.stats.top", usage="stats top X")
    154. public boolean stats(CommandSender cs, Integer n) {
    155. if (!plugin.ti.isEnabled()) {
    156. plugin.getLogger().warning(ChatColor.AQUA + "BattleTracker not found or turned off.");
    157. cs.sendMessage(ChatColor.YELLOW + "Bomb Arena statistics are not being tracked.");
    158. return true;
    159. }
    160.  
    161. List<Stat> planted = plugin.ti.getTopXWins(n);
    162. cs.sendMessage(ChatColor.AQUA + "Number of Bombs Planted");
    163. cs.sendMessage(ChatColor.YELLOW + "-----------------------");
    164. int i = 1;
    165. for (Stat w : planted) {
    166. if (w.getName().equalsIgnoreCase(plugin.getFakeName())) {
    167. continue;
    168. }
    169. int total = w.getWins() + w.getLosses();
    170. int percentage = (total == 0) ? 0 : (int) (w.getWins() * 100.00) / total;
    171. cs.sendMessage("" + i + " " + w.getName() + " "
    172. + w.getWins() + " out of " + total + " (" + percentage + "%)");
    173. i = i + 1;
    174. }
    175.  
    176. List<Stat> defused = plugin.ti.getTopX(StatType.TIES, n);
    177. cs.sendMessage(ChatColor.AQUA + "Number of Bombs Defused");
    178. cs.sendMessage(ChatColor.YELLOW + "-----------------------");
    179. i = 1;
    180. for (Stat d : defused) {
    181. if (d.getName().equalsIgnoreCase(plugin.getFakeName())) continue;
    182. cs.sendMessage("" + i + " " + d.getName() + " " + d.getTies());
    183. i = i + 1;
    184. }
    185.  
    186. return true;
    187. }
    188.  
    189. @MCCommand(cmds={"setconfig"}, subCmds={"bombblock"},
    190. perm="bombarena.setconfig", usage="setconfig BombBlock <handItem>")
    191. public boolean setBombBlock(Player p) {
    192. ItemStack hand = p.getInventory().getItemInHand();
    193. if (hand == null) {
    194. p.sendMessage("There is nothing in your hand.");
    195. return false;
    196. }
    197. plugin.setBombBlock(hand.getType());
    198. p.sendMessage("BombBlock has been set to " + hand.getType());
    199. p.sendMessage("All of your arenas have been automatically "
    200. + "updated with the new BombBlock.");
    201. return true;
    202. }
    203.  
    204. @MCCommand(cmds={"setconfig"}, subCmds={"baseblock"}, perm="bombarena.setconfig",
    205. usage="setconfig BaseBlock <handItem>")
    206. public boolean setBaseBlock(Player p) {
    207. ItemStack hand = p.getInventory().getItemInHand();
    208. if (hand == null) {
    209. p.sendMessage("There is nothing in your hand.");
    210. return false;
    211. }
    212. if (!BaseType.containsKey(hand.getType().name())) {
    213. p.sendMessage("That is not a valid BaseBlock in your hand!");
    214. return true;
    215. }
    216. p.sendMessage("BaseBlock has been set to " + hand.getType().name());
    217. plugin.setBaseBlock(hand.getType());
    218. return true;
    219. }
    220.  
    221. @MCCommand(cmds={"setconfig"}, subCmds={"databasetable"},
    222. perm="bombarena.setconfig", usage="setconfig DatabaseTable <name>")
    223. public boolean setDatabaseTable(CommandSender sender, String table) {
    224. plugin.setDatabaseTable(table);
    225. sender.sendMessage("DatabaseTable has been set to " + table);
    226. return true;
    227. }
    228.  
    229. @MCCommand(cmds={"setconfig"}, subCmds={"fakename"},
    230. perm="bombarena.setconfig", usage="setconfig FakeName <new name>")
    231. public boolean setFakeName(CommandSender sender, String[] name) {
    232. // name[] = "setconfig fakename args[2] args[3]"
    233. if (name.length <= 3) {
    234. sender.sendMessage("FakeName must have at least one space in order "
    235. + "to distinguish it from a real player in the database.");
    236. return false;
    237. }
    238. StringBuilder sb = new StringBuilder();
    239. for (int index = 2; index < name.length; index++) {
    240. sb.append(name[index]).append(" ");
    241. }
    242. String newName = sb.toString().trim();
    243. plugin.setFakeName(newName);
    244. sender.sendMessage("FakeName has been set to " + newName);
    245. return true;
    246. }
    247.  
    248. @MCCommand(cmds={"setconfig"}, subCmds={"changefakename"},
    249. perm="bombarena.setconfig", usage="setconfig ChangeFakeName <name>")
    250. public boolean setChangeFakeName(CommandSender sender, String name) {
    251. sender.sendMessage("This option has not been implemented.");
    252. return true;
    253. }
    254. @MCCommand(cmds={"setconfig"}, perm="bombarena.setconfig", usage="setconfig <option> <integer>")
    255. public boolean setconfig(CommandSender sender, String option, Integer value) {
    256. Set<String> keys = plugin.getConfig().getKeys(false);
    257. for (String key : keys) {
    258. if (option.equalsIgnoreCase(key)) {
    259. plugin.getConfig().set(key, value);
    260. sender.sendMessage("" + key + " has been set to " + value);
    261. plugin.saveConfig();
    262. plugin.loadDefaultConfig();
    263. return true;
    264. }
    265. }
    266. sender.sendMessage("Valid options: " + keys.toString());
    267. return false;
    268. }
    269.  
    270. @MCCommand(cmds={"listconfig"}, perm="bombarena.setconfig", usage="listconfig")
    271. public boolean listconfig(CommandSender sender) {
    272. sender.sendMessage("Config options: " + plugin.getConfig().getKeys(false).toString());
    273. return true;
    274. }
    275.  
    276. @MCCommand(cmds={"setconfig"}, subCmds={"debug"},
    277. perm="bombarena.setconfig", usage="setconfig debug <true/false>")
    278. public boolean setDebug(CommandSender sender, boolean b) {
    279. plugin.getConfig().set("Debug", (boolean) b);
    280. plugin.saveConfig();
    281. sender.sendMessage("config.yml option 'Debug' has been set to " + b);
    282. plugin.loadDefaultConfig();
    283. return true;
    284. }
    285.  
    286. /**
    287.   * Toggles debug mode ON / OFF.
    288.   * Usage: /bomb debug
    289.   */
    290. @MCCommand(cmds={"debug"}, perm="bombarena.debug", usage="debug")
    291. public boolean toggleDebug(CommandSender sender) {
    292. if (plugin.debug instanceof DebugOn) {
    293. plugin.debug = new DebugOff(plugin);
    294. plugin.getConfig().set("Debug", false);
    295. plugin.saveConfig();
    296. sender.sendMessage("Debugging mode for the BombArena has been turned off.");
    297. return true;
    298. } else if (plugin.debug instanceof DebugOff) {
    299. plugin.debug = new DebugOn(plugin);
    300. plugin.getConfig().set("Debug", true);
    301. plugin.saveConfig();
    302. sender.sendMessage("Debugging mode for the BombArena has been turned on.");
    303. return true;
    304. }
    305. return false;
    306. }
    307.  
    308. @MCCommand(cmds={"getname"}, perm="bombarena.setconfig", usage="getname <handItem>")
    309. public boolean getBlockName(Player p) {
    310. String name = p.getItemInHand().getType().name();
    311. p.sendMessage("You are holding " + name);
    312. return true;
    313. }
    314.  
    315. @MCCommand(cmds={"dropItemNaturally"}, op=true)
    316. public boolean dropItemNaturally(Player player) {
    317. Location location = player.getLocation();
    318. ItemStack item = new ItemStack(plugin.getBombBlock());
    319. player.getLocation().getWorld().dropItemNaturally(location, item);
    320. return true;
    321. }
    322.  
    323. @MCCommand(cmds={"dropItem"}, op=true)
    324. public boolean dropItem(Player player) {
    325. Location location = player.getLocation();
    326. ItemStack item = new ItemStack(plugin.getBombBlock());
    327. player.getLocation().getWorld().dropItem(location, item);
    328. return true;
    329. }
    330.  
    331. @MCCommand(cmds={"soundlist"}, op=true)
    332. public boolean soundList(CommandSender sender, Integer page) {
    333. int size = Sound.values().length;
    334. int pages = size / 10;
    335. int start = page * 10;
    336. int end = start + 10;
    337. end = (end > size) ? size : end;
    338. for (int index = start; index < end; index = index + 1) {
    339. String s = Sound.values()[index].name().toLowerCase();
    340. sender.sendMessage("" + index + ". " + s);
    341. }
    342. sender.sendMessage("Page " + page + " of " + pages);
    343. return true;
    344. }
    345.  
    346. @MCCommand(cmds={"sound"}, op=true)
    347. public boolean sound(final Player player, String sound) {
    348. final Sound SOUND;
    349. final float volume = 1.0f;
    350. final float pitch = 1.0f;
    351. try {
    352. SOUND = Sound.valueOf(sound.toUpperCase());
    353. } catch (IllegalArgumentException ex) {
    354. return false;
    355. }
    356. final Location loc = player.getLocation();
    357. new BukkitRunnable() {
    358. int i = 6;
    359. @Override
    360. public void run() {
    361. i = i - 1;
    362. if (i <= 0) {
    363. cancel();
    364. return;
    365. }
    366. player.playSound(loc, SOUND, volume, pitch);
    367. }
    368.  
    369. }.runTaskTimer(plugin, 0L, 20L);
    370. return true;
    371. }
    372.  
    373.  
    374. }


    Basically, BattleArena allows you to focus on the rules of your minigame (which are the events inside your Arena class)... And you don't have to worry about stuff like saving and resetting regions... BattleArena takes care of this for you (and a whole bunch of other stuff too).
     
  22. Offline

    PlayerNerd

    @xMakerx Do i put the code in a new class??
     
  23. Offline

    xMakerx

    My code was just an example, I don't recommend you use it because it's more for my plugin. However, you should use the following line of code to check if a player is in a region.

    Code:
    ApplicableRegionSet regions = worldGuard.getRegionManager(player.getWorld()).getApplicableRegions(location);
    You would iterate through that and check if any of your Arenas has that region. Just so you know, the ApplicableRegionSet holds instances of the ProtectedRegion class, so iteration would be like this:

    Code:
    for(ProtectedRegion region : regions) {}
    
    OR
    
    for(int i = 0; i < regions.size(); i++) {}
     
  24. Offline

    PlayerNerd

    @xMakerx Like it??

    Code:
    ApplicableRegionSet regions = WGBukkit.getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation());
                                        for(ProtectedRegion region : regions)
                                        {
                                            if(region.contains((int) p.getLocation().getX(),(int) p.getLocation().getY(),(int) p.getLocation().getZ()))
                                            {
                                               
                                            }
                                        }
     
  25. Offline

    xMakerx

    I don't think that if statement will work. I recommend you iterate through your Arenas and check if the regions are equal to eachother, or you can check if the region names are the same.
     
Thread Status:
Not open for further replies.

Share This Page