Solved Cancelling other events in other plugins not working

Discussion in 'Plugin Development' started by Xp10d3, Jan 25, 2020.

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

    Xp10d3

    Hello. I got some help from another developer to cancel events in other plugins in certain worlds that are specified in the config.yml file, but it doesn't seem to be working. As I went through a portal, the events started firing and after printing the data, everything seemed to be working. The worlds were gotten correctly, and it seems the config section as well (although I'm not sure). I am very frustrated and don't know what's going on. Is there any errors in my code that I don't see?

    Core Class: https://sourceb.in/645a9fab74
    Printed variables: https://sourceb.in/e23a631f5d

    In case sourceb.in can't be accessed in your country here is the class and printed variables:
    Core.java:
    Printed variables:
     
  2. Offline

    caderapee

  3. Offline

    Xp10d3

    Alright. Thanks. I'm just trying to cancel events in specified plugins in specified worlds if that helps :/ What do you mean though by:
    ? Do you mean that the event isn't registered?
     
  4. Offline

    caderapee

    @Xp10d3 I dun see the annotation that turn a method into an event, and the interface event. check the link.

    You can disable others plugin, unregister events, but cancelling events in that way, i dun think you can.

    The only way for me its to override the event in lower priority, or highest, i dun remeber witch one is called first, cancel it, and hope that the developper put the ignoreCancelled annotation to true.
     
  5. Offline

    Xp10d3

    Doesn't work for English :oops: Alright so it is the EventHandler issue? I've added it and registered and will test it later.
    Code:
    @EventHandler
        public void repeat(PlayerPortalEvent event) {
            for (int i = 0; i >= 0; i++) {
                supress();
            }
        }
    
    Code:
        public void onEnable() {
            config = getConfig();
            this.saveDefaultConfig();
            loadConfig();
            this.getCommand("dp").setExecutor(new Commands(this));
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    
     
  6. Offline

    caderapee

  7. Offline

    Xp10d3

    I did that. :) Thanks. I'll take a look at the documentation.
    EDIT: Yes it was firing. I added this in my onEnable in case the event didn't work. I don't mean any offense but are you sure that this was the error?
    Part of my onEnable:
    Code:
            for (int i = 0; i >= 0; i++) {
                supress();
                ConfigurationSection targetPlugin = config.getConfigurationSection("location.world");
    
                for (String key : targetPlugin.getKeys(false)) {
                    List<String> targetWorld = targetPlugin.getStringList(key);
                    System.out.println("Variable i: " + i);
                    System.out.println("TargetPlugin: " + targetPlugin);
                    System.out.println("TargetWorld: " + targetWorld);
                }
            }
    
    @caderapee
     
    Last edited: Jan 25, 2020
  8. Offline

    caderapee

    @Xp10d3
    Oh ok, didnt see.

    You are comparing a object world with a stringList, that cant work. You have to loop the list for retrieve each world name, and compare the player#getWorld#getName with the name in your config
     
  9. Offline

    Xp10d3

    Alright. I know the basics of Java and a bit about looping but looping a list is a bit foreign to me. Before other people yell at me I have done a lot of coding and quite a bit of JavaScript and Discord.js and have taken a few Java lessons so I can get my way around certain stuff.
    EDIT: Nevermind, figured it out. I got this but... I feel dumb, I can't really add any parameters to the Event without causing an error at the
    Code:
     filter(PlayerInteractEvent.class,...
    line but I need to create the variable player in order to do player.getWorld().getName().
    Code:
        @SuppressWarnings("unlikely-arg-type")
        public void supress() {
            ConfigurationSection targetPlugin = config.getConfigurationSection("location.world");
            for (String key : targetPlugin.getKeys(false)) {
                List<String> targetWorld = targetPlugin.getStringList(key);
                if (targetWorld != null) {
                    for (int i = 0; i < targetWorld.size(); i++) {
                        if (targetWorld.contains(player.getWorld())) {
                            filter(PlayerInteractEvent.class, (plugin, event) -> plugin == targetPlugin && event.getPlayer().getWorld().equals(targetWorld));
                        }
                    }
                }
            }
        }
    
     
    Last edited: Jan 25, 2020
  10. Offline

    caderapee

    @Xp10d3 The variable player, you got it with the PlayerPortalEvent. Just add the player object as parameter to your method suppress
     
  11. Offline

    Xp10d3

    Oh lol. Thanks.
     
    Last edited: Jan 26, 2020
Thread Status:
Not open for further replies.

Share This Page