Solved [HELP] - Trying to Disable a Certain Spawner Type

Discussion in 'Plugin Development' started by Venexor, Jul 15, 2014.

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

    Necrodoom

    pluginsbyjason yes, that's the tool tip name.
    You are checking the material.
     
  2. Offline

    MomsKnife

    Yeah I thought I did that, didn't notice cause I wrote it on the forums here.
     
  3. Offline

    pluginsbyjason

    Well I guess my code is rendered useless then since I wasn't aware of that.
     
  4. Offline

    Necrodoom

    pluginsbyjason it was useless in the first place.
    Well, "fine", but really whole thing is pointless because the block is not actually placed as a skeleton spawner.
     
  5. Well, it would be pretty hard to cancel an event that's not happening. Let us clarify some things before.
    You can't prevent the placement of Skeleton spawners because they cannot be placed. What you're trying to prevent is the UPDATE of a spawner from a non-Skeleton one to a Skeleton one. And, unfortunately, that's being done by a plugin.
    Fortunately, you can do different things with the same goal. Why would you block the "placement" of Skeleton spawners? Oh, yeah, to prevent Skeletons from being spawned by user-set spawners!
    But there's a detail I didn't get. Do you want to stop natural Skeleton spawners from working too, or only user-placed ones? No one knows, because you weren't specific! Yeah!
    What can we do? Shh. What have we done? Tried to stop a skeleton spawner from being placed, despite they lose their damage value upon placement. Good. Attempts to fix the aforementioned (broken) method. Nice. Every single line of code that has been posted here is utterly useless. Because none of them looks at the actual problem from a different angle! You CAN'T place Skeleton spawners! What's the point of preventing something that will never happen? We have to go one step further into the goals of the OP: either preventing user-placed spawners to be updated into Skeleton spawners, or preventing user-set Skeleton spawners from doing their job, which is basically the point of this post.

    Option A: Plugin permissions. Dear OP, have you tried removing your OP (operator, not original poster) permissions before testing the denied SilkSpawners permission? OP usually overrides all permissions, unless the permission default is set to "none" in the plugin.yml. Remove your OP and test the permission again.

    Option B: Are the bad spawners going to be placed by OPs, so we can't take their permission to do so? This option is for you. Instruct your god damned OPs not to use the Skeleton spawners, if the server belongs to you, you have the last say on what people can do, so if some idiot insists to impregnate your worldly world with Skeleton spawners, take their OP because they're too immature to even play online.

    Option C: Are non-OPs going to place the bad spawners too? goto Option A. Permissions still refuse to work? Open a ticket in the plugin thread about some permissions issue, maybe it's a bug within the plugin.

    Option D: Option C failed or taking too long? Last resort: code your way away from the Skeleton spawners. You can either look for block damage value updating events and cancel them if the block is a spawner and the damage value is the Skeleton spawner one, or you can prevent all Skeleton spawners from doing their stuff and replacing them with Sponge/Air when a Skeleton is spawned by a spawner (not recommended, will break naturally generated spawners too, unless that's what you want; and also not sure if that will work, didn't have time to test).

    I'll do some tests on my debug server using the latest SilkSpawners build. I'll post code if possible.
    I'll be back.
     
    xTigerRebornx and Necrodoom like this.
  6. Offline

    MomsKnife

    I've tried this, and my code is fine, but silkspawners handles the placing of spawners, meaning I can't actually cancel the even of them placing the spawner, and I can't cancel the event of the entity spawning.

    Code:java
    1. @EventHandler
    2. public void onSpawn(CreatureSpawnEvent e) {
    3. if (e.getEntityType() == EntityType.WITHER_SKULL) {
    4. if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) {
    5. e.getEntity().remove();
    6. }
    7. }
    8. }
    9. @EventHandler
    10. public void onPlace(BlockPlaceEvent e){
    11. String ItemName = e.getPlayer().getItemInHand().getItemMeta().getDisplayName();
    12. if (ItemName.contains("Skeleton")){
    13. e.setCancelled(true);
    14. e.getPlayer().sendMessage("Skeleton spawners aren't allowed in the nether!");
    15. }
    16. }
     
  7. Okay, it's 4am, I've thought my ass off, but I couldn't get to a good solution before bedtime. So, you can use the following:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onCreatureSpawn(CreatureSpawnEvent e) {
    3. if (e.getSpawnReason() == SpawnReason.SPAWNER && e.getEntityType() == EntityType.SKELETON) {
    4. e.setCancelled(true);
    5. }
    6. }

    This "unspawns" all Skeletons spawned by spawners. I think there's a better solution, but I have to sleep. Tomorrow (later today) I'll work on something less... destructive.
     
  8. Offline

    xTigerRebornx

    bruno.paschoalinoto don't see why he can't just listen for interact w/ skele spawner in hand, and either cancel it or pass it to a way of storing that they are placing a skele spawner and use the storage to detect if they are placing it on BlockPlaceEvent
     
  9. Offline

    Necrodoom

    Or use the existing plugin permissions instead of trying to write a new plugin, so that you dont have to negate an existing, SINGLE, permission.
     
  10. Offline

    xTigerRebornx

    Necrodoom I suggested that, OP said it didn't work, I told him to verify that we wasn't bypassing it w/ OP, he ignored that (or hasn't seen it yet) and others tried to fix it other ways.
     
  11. Remove SilkSpawners. Users are no longer able to place Skeleton spawners. Success.

    Or use the damn permission and stop random programming.
     
  12. Offline

    Necrodoom

  13. Offline

    MomsKnife

  14. xTigerRebornx I was doing that like RIGHT NOW since I couldn't sleep. I tried everything you said, nothing worked. And I posted that code because the title clearly says disabling a type of spawner and not preventing the placement of a type of spawner, so I wanted to cover both situations, preferably the most likely one (aka title) first.
    Anyway, this code blocks the actual placement of Skeleton spawners SilkSpawners implements.

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onClick(PlayerInteractEvent evt) {
    3. ItemStack i = evt.getPlayer().getItemInHand();
    4. if (evt.getAction() == Action.RIGHT_CLICK_BLOCK && i.getType() == Material.MOB_SPAWNER && i.getItemMeta().hasDisplayName()) {
    5. if (i.getItemMeta().getDisplayName().contains("Skeleton")) {
    6. i.setType(Material.COOKIE);
    7. i.setAmount(1);
    8. evt.getPlayer().sendMessage(ChatColor.DARK_RED + "Nope. Have a cookie instead.");
    9. }
    10. }
    11. }
     
    Venexor likes this.
  15. Offline

    Venexor

    I appreciate all the responses from all the users however I resorted to a different method on fixing it. Instead of giving default users the permission, " silkspawners.place.* " and also adding " -silkspawners.place.skeleton ", I removed them and just added all the different permissions like so: http://prntscr.com/43wxjy

    I knew about this method but I wanted to find a way to program it instead of doing it permission-wise for the experience and to reduce redundancy in my permissions file.

    I apologize for everyone not being able to sleep due to this. I checked the notifications of bukkit.org just now so I wasn't ignoring, just didn't see it.

    The thread will now be marked as solved. Thanks!
     
  16. Alrighty then. I'm glad you solved your problem. :D
     
Thread Status:
Not open for further replies.

Share This Page