mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-18 15:17:36 +01:00
Added /reload WorldGuard command; adjusted wg-invincible so that it won't console spam every time someone joins.
This commit is contained in:
parent
6b57e58d63
commit
3f8bac582c
64
src/LoggerToChatHandler.java
Normal file
64
src/LoggerToChatHandler.java
Normal file
@ -0,0 +1,64 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Sends all logger messages to a player.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LoggerToChatHandler extends Handler {
|
||||
/**
|
||||
* Player.
|
||||
*/
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public LoggerToChatHandler(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the handler.
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the output.
|
||||
*/
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a log record.
|
||||
*/
|
||||
public void publish(LogRecord record) {
|
||||
player.sendMessage(Colors.LightGray + record.getLevel().getName() + ": "
|
||||
+ Colors.White + record.getMessage());
|
||||
}
|
||||
}
|
@ -93,7 +93,8 @@ public class WorldGuardListener extends PluginListener {
|
||||
private int spawnProtection;
|
||||
private boolean kickOnDeath;
|
||||
private Blacklist blacklist;
|
||||
private boolean hasAmphibious;
|
||||
private boolean hasAmphibiousGroup;
|
||||
private boolean hasInvincibleGroup;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
@ -252,7 +253,15 @@ public void loadConfiguration() {
|
||||
}
|
||||
}
|
||||
|
||||
hasAmphibious = etc.getDataSource().getGroup("wg-amphibious") != null;
|
||||
hasAmphibiousGroup = etc.getDataSource().getGroup("wg-amphibious") != null;
|
||||
if (!hasAmphibiousGroup) {
|
||||
logger.log(Level.INFO, "Ignore the error about wg-amphibious.");
|
||||
}
|
||||
|
||||
hasInvincibleGroup = etc.getDataSource().getGroup("wg-invincible") != null;
|
||||
if (!hasInvincibleGroup) {
|
||||
logger.log(Level.INFO, "Ignore the error about wg-invincible.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,7 +299,7 @@ public void onLogin(Player player) {
|
||||
recentLogins.put(player.getName(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (player.isInGroup("wg-invincible")) {
|
||||
if (hasInvincibleGroup && player.isInGroup("wg-invincible")) {
|
||||
invinciblePlayers.add(player.getName());
|
||||
}
|
||||
}
|
||||
@ -414,6 +423,27 @@ public boolean onCommand(Player player, String[] split) {
|
||||
player.sendMessage(Colors.Yellow + "Items compacted into stacks!");
|
||||
|
||||
return true;
|
||||
} else if (split[0].equalsIgnoreCase("/reload")
|
||||
&& player.canUseCommand("/reload")
|
||||
&& split.length > 1) {
|
||||
if (split[1].equalsIgnoreCase("WorldGuard")) {
|
||||
LoggerToChatHandler handler = new LoggerToChatHandler(player);
|
||||
handler.setLevel(Level.ALL);
|
||||
Logger minecraftLogger = Logger.getLogger("Minecraft");
|
||||
minecraftLogger.addHandler(handler);
|
||||
|
||||
try {
|
||||
loadConfiguration();
|
||||
player.sendMessage("WorldGuard configuration reloaded.");
|
||||
} catch (Throwable t) {
|
||||
player.sendMessage("Error while reloading: "
|
||||
+ t.getMessage());
|
||||
} finally {
|
||||
minecraftLogger.removeHandler(handler);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -976,7 +1006,7 @@ public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasAmphibious && type == PluginLoader.DamageType.WATER
|
||||
if (hasAmphibiousGroup && type == PluginLoader.DamageType.WATER
|
||||
&& player.isInGroup("wg-amphibious")) {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user