Fix runtime errors
This commit is contained in:
1 parent
7f72e0b28b
commit
9ae6fbd4c1
3 files changed
+30
-25
No files matched your search
+1
-1
Submodule libs/GxUI-OG updated: ebd8df041e...cbcf14f0ab.
@@ -1,18 +1,27 @@
|
||||
package plugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import me.realized.duels.api.Duels;
|
||||
|
||||
// Extending this class is standard bukkit boilerplate for any plugin, or else the server software won't load the
|
||||
// classes.
|
||||
public class DuelEnhancerOG extends JavaPlugin {
|
||||
|
||||
// Container for Duels API.
|
||||
private Duels duelsAPI;
|
||||
|
||||
// What to do when the plugin is run by the server.
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
// Register the Duels plugin instance.
|
||||
this.duelsAPI = (Duels) Bukkit.getServer().getPluginManager().getPlugin("Duels");
|
||||
|
||||
// Register the Event Listener class.
|
||||
this.getServer().getPluginManager().registerEvents(new Listeners(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new Listeners(duelsAPI), this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
package plugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -15,16 +14,14 @@ import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
|
||||
// Declare instance of class as static so multiple players can use it.
|
||||
private static Listeners instance;
|
||||
// Container to store the received Duels API instance.
|
||||
Duels duelsAPI;
|
||||
|
||||
// Initialize Duels API.
|
||||
private static Duels api = (Duels) Bukkit.getServer().getPluginManager().getPlugin("Duels-OG");
|
||||
// Class constructor.
|
||||
public Listeners(Duels duelsAPI) {
|
||||
|
||||
// Return instance of class as static so multiple players can use it.
|
||||
public static Listeners getInstance() {
|
||||
|
||||
return instance;
|
||||
// Assign the received Duels API instance to the container.
|
||||
this.duelsAPI = duelsAPI;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,27 +29,26 @@ public class Listeners implements Listener {
|
||||
@EventHandler
|
||||
public void onSurvivalMode(PlayerGameModeChangeEvent event) {
|
||||
|
||||
// Store player as object for multiple references.
|
||||
Player player = event.getPlayer();
|
||||
final Player player = event.getPlayer();
|
||||
final boolean condition = duelsAPI.getSpectateManager().isSpectating(player)
|
||||
&& player.getGameMode() == GameMode.SURVIVAL;
|
||||
|
||||
// If the player was put in survival (presumably by WorldGuard), do this...
|
||||
// Use Duels API to tell if the player whose game mode has changed is spectating
|
||||
// a duel.
|
||||
if (api.getSpectateManager().isSpectating(player)) {
|
||||
if (!condition) {
|
||||
|
||||
// If the player was put in survival (presumably by WorldGuard), do this...
|
||||
if (player.getGameMode() == GameMode.SURVIVAL) {
|
||||
|
||||
// Inform the player that they will stop spectating the match.
|
||||
UtilitiesOG.trueogMessage(player,
|
||||
"<gray>[<dark_green>True<red>OG<gray>] <gold>Out of bounds! Your Duel spectating session has ended.");
|
||||
|
||||
// Stop the player from spectating the match.
|
||||
api.getSpectateManager().stopSpectating(player);
|
||||
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Inform the player that they will stop spectating the match.
|
||||
UtilitiesOG.trueogMessage(player,
|
||||
"<gray>[<dark_green>True<red>OG<gray>] <gold>Out of bounds! Your Duel spectating session has ended.");
|
||||
|
||||
// Stop the player from spectating the match.
|
||||
duelsAPI.getSpectateManager().stopSpectating(player);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user