I want to make it so theres a list in the config of block id and when a player places a block if that block is in the list it will block it. heres what im working with: Code (Text): @SuppressWarnings({ "deprecation", "unlikely-arg-type" }) @EventHandler public void onBlockPlace(BlockPlaceEvent e) { if (getConfig().getStringList("restrictedblocks").contains(e.getBlock().getType().getId())) { e.setCancelled(true); e.getPlayer().kickPlayer(ChatColor.DARK_RED + "That block is not allowed on the server!"); for (Player p : Bukkit.getServer().getOnlinePlayers()) { if (p.hasPermission("sp.notify")) { p.sendMessage(ChatColor.RED + e.getPlayer().getName() + " tried to place " + e.getBlock().getType().getData()); } } } } }
First off I would store your blocks in memory instead of reading from config every time this event is called (Optimization) Second, I would also use e.getBlock().getType(). This would let you use the name of the block (from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) instead of a 'magic' deprecated number. Also make sure this listener is registered
knowing md_5 and his love for backwards compatibility the id system probably won't go anywhere though
yeah but spigot 1.13 is coming and I heard item id will be removed when you compile on 1.13 API but if you compile on 1.12 down item id is still usable
Now that you say that I believe it is. (At least would make sense). As for cleaner code, it would be better to load the list from config into an array called 'restrictedblocks' instead of getConfig().getStringList("restrictedblocks")
Can't find in documentation or forums if the config is stored in memory. So I'd still load the list onEnable() to be safe. At worst the performance is equivalent if not better if the config isn't stored in memory.
yeah no wrappers and stuff but be sure to clean the array when the plugin reload as to avoid memory leaks its not that he cant haha but its for the better
well a proof of this is when you modify the values of the config then shut down the server the config.yml stays the same so yeah plugin config is loaded into memory until you do saveConfig()
Well state your problem as we can see your code seems fine what the others commented is how to improve your code. Question What is the problem bothering you
You can all argue about whether to use item IDs or not but ignore the obvious things lmao @OP, don't ignore warnings from your IDE, they are there to help you. You're checking if a list of STRINGS contains a BYTE. See the problem? To fix this, wrapping the byte with String.valueOf should work (although not sure about the implementation of List#contains from config, it likely calls Object#equals) Hope this helps you out Sent from my SM-G903F using Tapatalk
Also if a method is deprecated means theres just a better way to do it, and might be removed in next update? just like setBanned(true), which i dont know how to do now.