mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-03 06:57:33 +01:00
Convert godmode over to using entity metadata
Remove old CommandBook-has-GodComponent checks (mostly) Cleaned up some trailing whitespace
This commit is contained in:
parent
16ce56c1ad
commit
3d50486dac
@ -22,11 +22,10 @@
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.commandbook.CommandBook;
|
||||
import com.sk89q.commandbook.GodComponent;
|
||||
import com.sk89q.util.yaml.YAMLFormat;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
import org.bukkit.World;
|
||||
@ -34,6 +33,8 @@
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
/**
|
||||
* Represents the global configuration and also delegates configuration
|
||||
@ -44,6 +45,8 @@
|
||||
*/
|
||||
public class ConfigurationManager {
|
||||
|
||||
public static final String GOD_METADATA_KEY = "god";
|
||||
|
||||
private static final String CONFIG_HEADER = "#\r\n" +
|
||||
"# WorldGuard's main configuration file\r\n" +
|
||||
"#\r\n" +
|
||||
@ -80,22 +83,14 @@ public class ConfigurationManager {
|
||||
*/
|
||||
private YAMLProcessor config;
|
||||
|
||||
/**
|
||||
* List of people with god mode.
|
||||
*/
|
||||
@Deprecated
|
||||
private Set<String> hasGodMode = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* List of people who can breathe underwater.
|
||||
*/
|
||||
private Set<String> hasAmphibious = new HashSet<String>();
|
||||
|
||||
private boolean hasCommandBookGodMode = false;
|
||||
|
||||
public boolean useRegionsScheduler;
|
||||
public boolean activityHaltToggle = false;
|
||||
public boolean autoGodMode;
|
||||
@Deprecated public boolean autoGodMode = false;
|
||||
public boolean usePlayerMove;
|
||||
|
||||
/**
|
||||
@ -133,12 +128,8 @@ public void load() {
|
||||
}
|
||||
|
||||
config.removeProperty("suppress-tick-sync-warnings");
|
||||
useRegionsScheduler = config.getBoolean(
|
||||
"regions.use-scheduler", true);
|
||||
autoGodMode = config.getBoolean(
|
||||
"auto-invincible", config.getBoolean("auto-invincible-permission", false));
|
||||
usePlayerMove = config.getBoolean(
|
||||
"use-player-move-event", true);
|
||||
useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
|
||||
usePlayerMove = config.getBoolean("use-player-move-event", true);
|
||||
|
||||
useSqlDatabase = config.getBoolean(
|
||||
"regions.sql.use", false);
|
||||
@ -199,8 +190,6 @@ public void forgetPlayer(LocalPlayer player) {
|
||||
bl.forgetPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
hasGodMode.remove(player.getName());
|
||||
hasAmphibious.remove(player.getName());
|
||||
}
|
||||
|
||||
@ -211,7 +200,9 @@ public void forgetPlayer(LocalPlayer player) {
|
||||
*/
|
||||
@Deprecated
|
||||
public void enableGodMode(Player player) {
|
||||
hasGodMode.add(player.getName());
|
||||
if (!hasGodMode(player)) {
|
||||
player.setMetadata(GOD_METADATA_KEY, new FixedMetadataValue(plugin, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +212,7 @@ public void enableGodMode(Player player) {
|
||||
*/
|
||||
@Deprecated
|
||||
public void disableGodMode(Player player) {
|
||||
hasGodMode.remove(player.getName());
|
||||
player.removeMetadata(GOD_METADATA_KEY, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -231,13 +222,20 @@ public void disableGodMode(Player player) {
|
||||
* @return Whether the player has godmode through WorldGuard or CommandBook
|
||||
*/
|
||||
public boolean hasGodMode(Player player) {
|
||||
if (hasCommandBookGodMode) {
|
||||
GodComponent god = CommandBook.inst().getComponentManager().getComponent(GodComponent.class);
|
||||
if (god != null) {
|
||||
return god.hasGodMode(player);
|
||||
List<MetadataValue> values = player.getMetadata(GOD_METADATA_KEY);
|
||||
switch (values.size()) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
return values.get(0).asBoolean();
|
||||
default:
|
||||
for (MetadataValue val : values) {
|
||||
if (val.asBoolean()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return hasGodMode.contains(player.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,18 +266,12 @@ public boolean hasAmphibiousMode(Player player) {
|
||||
return hasAmphibious.contains(player.getName());
|
||||
}
|
||||
|
||||
public void updateCommandBookGodMode() {
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||
Class.forName("com.sk89q.commandbook.GodComponent");
|
||||
hasCommandBookGodMode = true;
|
||||
return;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {}
|
||||
hasCommandBookGodMode = false;
|
||||
}
|
||||
|
||||
public boolean hasCommandBookGodMode() {
|
||||
return hasCommandBookGodMode;
|
||||
try {
|
||||
Class.forName("com.sk89q.commandbook.GodComponent");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public void run() {
|
||||
reg.register(GeneralCommands.class);
|
||||
}
|
||||
}
|
||||
}, 0L);
|
||||
}, 1L);
|
||||
|
||||
// Need to create the plugins/WorldGuard folder
|
||||
getDataFolder().mkdirs();
|
||||
@ -153,7 +153,6 @@ public void run() {
|
||||
(new WorldGuardEntityListener(this)).registerEvents();
|
||||
(new WorldGuardWeatherListener(this)).registerEvents();
|
||||
(new WorldGuardVehicleListener(this)).registerEvents();
|
||||
(new WorldGuardServerListener(this)).registerEvents();
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
|
||||
@ -165,16 +164,6 @@ public void run() {
|
||||
worldListener.initWorld(world);
|
||||
}
|
||||
worldListener.registerEvents();
|
||||
|
||||
if (!configuration.hasCommandBookGodMode()) {
|
||||
// Check god mode for existing players, if any
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (inGroup(player, "wg-invincible") ||
|
||||
(configuration.autoGodMode && hasPermission(player, "worldguard.auto-invincible"))) {
|
||||
configuration.enableGodMode(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,38 +0,0 @@
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class WorldGuardServerListener implements Listener {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardServerListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
pm.registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user