Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3122

[API Request] PlayerWeatherChangeEvent

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • None

      I find myself in a unique situation. I have the need to intercept a request to setPlayerWeather(). I need to do this because the setPlayerWeather method sends a packet to the player in order to to only change the weather for themself. My plugin also works by sending packets to users and if any other plugin calls this method, setPlayerWeather, the packets my plugin sends are overriden.

      The current implementation is in the EntityPlayer class as shown below:

       

      public void setPlayerWeather(WeatherType type, boolean plugin)
      {
           if ((!plugin) && (weather != null)) {
             return;
          }
          
          if (plugin) {
             weather = type;
          }
          
         /* EVENT CALL GOES HERE */
      
          if (type == WeatherType.DOWNFALL) {
             playerConnection.sendPacket(new PacketPlayOutGameStateChange(2, 0.0F));
          } else {
            playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F));
           }
      }

       

      This can be implemented by adding the following code to the marked spot in the method above.

       

      PlayerWeatherChangeEvent weather = new PlayerWeatherChangeEvent(/* Data goes here (Player, weather state, etc)*/);
      Bukkit.getServer().getPluginManager().callEvent(weather);
      if (weather.isCancelled()) {
           return;
      }
      

      The PlayerWeatherChangeEvent would need to be created as a new class in the API and store data such as the target player and WeatherType requested.

       

      Thank you for reading, I hope you consider implementing this.

            Unassigned Unassigned
            TheKraken7 Daniel Scalzi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: