mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 03:25:24 +01:00
Progress.
This commit is contained in:
parent
41a71d6185
commit
5657ee6c90
@ -32,6 +32,7 @@
|
||||
<attribute name="WorldGuard-Version" value="${version}"/>
|
||||
<attribute name="Class-Path" value="WorldEdit.jar"/>
|
||||
</manifest>
|
||||
<copy tofile="${build.dir}/plugin.yml" file="plugin.yml"/>
|
||||
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf"/>
|
||||
</target>
|
||||
|
||||
@ -53,14 +54,16 @@
|
||||
</copy>
|
||||
<copy tofile="${release.dir}/worldguard.updatr" file="worldguard.updatr"/>
|
||||
<replace file="${release.dir}/worldguard.updatr" token="%version%" value="${version}"/>
|
||||
<copy tofile="${release.dir}/plugin.yml" file="plugin.yml"/>
|
||||
<replace file="${release.dir}/plugin.yml" token="WGVERSIONMACRO" value="${version}"/>
|
||||
<copy file="worldguard.properties" todir="${release.dir}"/>
|
||||
<copy tofile="${release.dir}/WorldGuard.jar" file="${dist.dir}/WorldGuard.jar"/>
|
||||
<zip destfile="${release.dir}/worldguard-${version}.zip" basedir="${release.dir}" excludes="*.zip"/>
|
||||
<zip destfile="${release.dir}/worldguard-${version}.zip" basedir="${release.dir}" excludes="*.zip plugin.yml"/>
|
||||
<mkdir dir="${release.dir}/src"/>
|
||||
<copy todir="${release.dir}/src">
|
||||
<fileset dir="${src.dir}"/>
|
||||
</copy>
|
||||
<zip destfile="${release.dir}/worldguard-${version}-source.zip" basedir="${release.dir}" excludes="*.zip"/>
|
||||
<zip destfile="${release.dir}/worldguard-${version}-src.zip" basedir="${release.dir}" excludes="*.zip plugin.yml"/>
|
||||
</target>
|
||||
|
||||
<!-- Clean the output -->
|
||||
|
41
config.yml
Normal file
41
config.yml
Normal file
@ -0,0 +1,41 @@
|
||||
summary-on-start: false
|
||||
protection:
|
||||
enforce-single-session: true
|
||||
item-drop-blacklist: []
|
||||
item-durability: false
|
||||
simulation:
|
||||
classic-water: false
|
||||
sponge:
|
||||
enable: true
|
||||
radius: 3
|
||||
physics:
|
||||
no-physics-gravel: false
|
||||
no-physics-sand: false
|
||||
allow-portal-anywhere: false
|
||||
disable-water-damage-blocks: []
|
||||
ignition:
|
||||
block-tnt: false
|
||||
block-lighter: false
|
||||
fire:
|
||||
disable-fire-spread: false
|
||||
disable-fire-spread-blocks: []
|
||||
disable-lava-fire-spread: true
|
||||
lava-spread-blocks: []
|
||||
mobs:
|
||||
block-creeper-explosions: false
|
||||
spawn:
|
||||
login-protection: 3
|
||||
spawn-protection: 0
|
||||
kick-on-death: false
|
||||
exact-respawn: false
|
||||
teleport-to-home-on-death: false
|
||||
player-damage:
|
||||
disable-fall-damage: false
|
||||
disable-lava-damage: false
|
||||
disable-fire-damage: false
|
||||
disable-water-damage: false
|
||||
disable-suffocation-damage: false
|
||||
teleport-on-suffocation: false
|
||||
regions:
|
||||
enable: true
|
||||
wand: 287
|
3
plugin.yml
Normal file
3
plugin.yml
Normal file
@ -0,0 +1,3 @@
|
||||
name: WorldGuard
|
||||
main: com.sk89q.worldguard.bukkit.WorldGuardPlugin
|
||||
version: WGVERSIONMACRO
|
@ -1,418 +0,0 @@
|
||||
// $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.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Blacklist {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* List of entries by block ID.
|
||||
*/
|
||||
private Map<Integer,List<BlacklistEntry>> blacklist
|
||||
= new HashMap<Integer,List<BlacklistEntry>>();
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private BlacklistLogger blacklistLogger = new BlacklistLogger();
|
||||
|
||||
/**
|
||||
* Blacklist contains on-acquire events.
|
||||
*/
|
||||
private boolean hasOnAcquire;
|
||||
|
||||
/**
|
||||
* Returns whether the list is empty.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return blacklist.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entries for an item or list.
|
||||
*/
|
||||
public List<BlacklistEntry> getEntries(int id) {
|
||||
return blacklist.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logger.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BlacklistLogger getLogger() {
|
||||
return blacklistLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block destruction. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroy(final Block block, final Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDestroy(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block break. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onBreak(final Block block, final Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onBreak(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on left click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroyWith(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDestroyWith(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on place. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onPlace(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onPlace(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onRightClick(Block block, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onRightClick(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item use. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onUse(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onUse(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentUse(Block block, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onSilentUse(block, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on drop. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDrop(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onDrop(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onAcquire(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onAcquire(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentAcquire(int item, Player player) {
|
||||
List<BlacklistEntry> entries = getEntries(item);
|
||||
if (entries == null) {
|
||||
return true;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (BlacklistEntry entry : entries) {
|
||||
if (!entry.onSilentAcquire(item, player)) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the blacklist.
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(File file) throws IOException {
|
||||
FileReader input = null;
|
||||
Map<Integer,List<BlacklistEntry>> blacklist =
|
||||
new HashMap<Integer,List<BlacklistEntry>>();
|
||||
|
||||
try {
|
||||
input = new FileReader(file);
|
||||
BufferedReader buff = new BufferedReader(input);
|
||||
|
||||
hasOnAcquire = false;
|
||||
|
||||
String line;
|
||||
List<BlacklistEntry> currentEntries = null;
|
||||
while ((line = buff.readLine()) != null) {
|
||||
line = line.trim();
|
||||
|
||||
// Blank line
|
||||
if (line.length() == 0) {
|
||||
continue;
|
||||
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.matches("^\\[.*\\]$")) {
|
||||
String[] items = line.substring(1, line.length() - 1).split(",");
|
||||
currentEntries = new ArrayList<BlacklistEntry>();
|
||||
|
||||
for (String item : items) {
|
||||
int id = 0;
|
||||
|
||||
try {
|
||||
id = Integer.parseInt(item.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
id = etc.getDataSource().getItem(item.trim());
|
||||
if (id == 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
|
||||
+ item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BlacklistEntry entry = new BlacklistEntry(this);
|
||||
if (blacklist.containsKey(id)) {
|
||||
blacklist.get(id).add(entry);
|
||||
} else {
|
||||
List<BlacklistEntry> entries = new ArrayList<BlacklistEntry>();
|
||||
entries.add(entry);
|
||||
blacklist.put(id, entries);
|
||||
}
|
||||
currentEntries.add(entry);
|
||||
}
|
||||
} else if (currentEntries != null) {
|
||||
String[] parts = line.split("=");
|
||||
|
||||
if (parts.length == 1) {
|
||||
logger.log(Level.WARNING, "Found option with no value "
|
||||
+ file.getName() + " for '" + line + "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean unknownOption = false;
|
||||
|
||||
for (BlacklistEntry entry : currentEntries) {
|
||||
if (parts[0].equalsIgnoreCase("ignore-groups")) {
|
||||
entry.setIgnoreGroups(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-destroy")) {
|
||||
entry.setDestroyActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-break")) {
|
||||
entry.setBreakActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-left")
|
||||
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
|
||||
entry.setDestroyWithActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-place")) {
|
||||
entry.setPlaceActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-use")) {
|
||||
entry.setUseActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-right-click")) {
|
||||
entry.setRightClickActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-drop")) {
|
||||
entry.setDropActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("on-acquire")) {
|
||||
hasOnAcquire = true;
|
||||
entry.setAcquireActions(parts[1].split(","));
|
||||
} else if (parts[0].equalsIgnoreCase("message")) {
|
||||
entry.setMessage(parts[1].trim());
|
||||
} else if (parts[0].equalsIgnoreCase("comment")) {
|
||||
entry.setComment(parts[1].trim());
|
||||
} else {
|
||||
unknownOption = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownOption) {
|
||||
logger.log(Level.WARNING, "Unknown option '" + parts[0]
|
||||
+ "' in " + file.getName() + " for '" + line + "'");
|
||||
}
|
||||
} else {
|
||||
logger.log(Level.WARNING, "Found option with no heading "
|
||||
+ file.getName() + " for '" + line + "'");
|
||||
}
|
||||
}
|
||||
|
||||
this.blacklist = blacklist;
|
||||
} finally {
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist contains on-acquire events.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasOnAcquire() {
|
||||
return hasOnAcquire;
|
||||
}
|
||||
}
|
@ -1,746 +0,0 @@
|
||||
// $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.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistEntry {
|
||||
/**
|
||||
* Used to prevent spamming.
|
||||
*/
|
||||
private static Map<String,BlacklistTrackedEvent> lastAffected =
|
||||
new HashMap<String,BlacklistTrackedEvent>();
|
||||
/**
|
||||
* Parent blacklist entry.
|
||||
*/
|
||||
private Blacklist blacklist;
|
||||
/**
|
||||
* List of groups to not affect.
|
||||
*/
|
||||
private Set<String> ignoreGroups;
|
||||
/**
|
||||
* List of actions to perform on destruction.
|
||||
*/
|
||||
private String[] destroyActions;
|
||||
/**
|
||||
* List of actions to perform on break.
|
||||
*/
|
||||
private String[] breakActions;
|
||||
/**
|
||||
* List of actions to perform on left click.
|
||||
*/
|
||||
private String[] destroyWithActions;
|
||||
/**
|
||||
* List of actions to perform on block placement.
|
||||
*/
|
||||
private String[] placeActions;
|
||||
/**
|
||||
* List of actions to perform on item use.
|
||||
*/
|
||||
private String[] useActions;
|
||||
/**
|
||||
* List of actions to perform on right click upon.
|
||||
*/
|
||||
private String[] rightClickActions;
|
||||
/**
|
||||
* List of actions to perform on drop.
|
||||
*/
|
||||
private String[] dropActions;
|
||||
/**
|
||||
* List of actions to perform on drop.
|
||||
*/
|
||||
private String[] acquireActions;
|
||||
/**
|
||||
* Message for users.
|
||||
*/
|
||||
private String message;
|
||||
/**
|
||||
* Comment for administrators.
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Used to ignore messages.
|
||||
*/
|
||||
private static ActionHandler silentHandler = new ActionHandler() {
|
||||
public void log(String itemName) {}
|
||||
public void kick(String itemName) {}
|
||||
public void ban(String itemName) {}
|
||||
public void notifyAdmins(String itemName) {}
|
||||
public void tell(String itemName) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param blacklist
|
||||
*/
|
||||
public BlacklistEntry(Blacklist blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ignoreGroups
|
||||
*/
|
||||
public String[] getIgnoreGroups() {
|
||||
return ignoreGroups.toArray(new String[ignoreGroups.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ignoreGroups the ignoreGroups to set
|
||||
*/
|
||||
public void setIgnoreGroups(String[] ignoreGroups) {
|
||||
Set<String> ignoreGroupsSet = new HashSet<String>();
|
||||
for (String group : ignoreGroups) {
|
||||
ignoreGroupsSet.add(group.toLowerCase());
|
||||
}
|
||||
this.ignoreGroups = ignoreGroupsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDestroyActions() {
|
||||
return destroyActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setDestroyActions(String[] actions) {
|
||||
this.destroyActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getBreakActions() {
|
||||
return breakActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setBreakActions(String[] actions) {
|
||||
this.breakActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDestroyWithActions() {
|
||||
return destroyWithActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
*/
|
||||
public void setDestroyWithActions(String[] actions) {
|
||||
this.destroyWithActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getPlaceActions() {
|
||||
return placeActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setPlaceActions(String[] actions) {
|
||||
this.placeActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getUseActions() {
|
||||
return useActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setUseActions(String[] actions) {
|
||||
this.useActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getRightClickActions() {
|
||||
return rightClickActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setRightClickActions(String[] actions) {
|
||||
this.rightClickActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getDropActions() {
|
||||
return dropActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setDropActions(String[] actions) {
|
||||
this.dropActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getAcquireActions() {
|
||||
return acquireActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actions
|
||||
*/
|
||||
public void setAcquireActions(String[] actions) {
|
||||
this.acquireActions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to set
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment
|
||||
*/
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comment the comment to set
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this player should be ignored.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean shouldIgnore(Player player) {
|
||||
if (ignoreGroups == null) {
|
||||
return false;
|
||||
}
|
||||
for (String group : player.getGroups()) {
|
||||
if (ignoreGroups.contains(group.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Announces a message to all administrators.
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
public void notifyAdmins(String str) {
|
||||
for (Player player : etc.getServer().getPlayerList()) {
|
||||
if (player.canUseCommand("/wprotectalerts")
|
||||
|| player.canUseCommand("/worldguardnotify")) {
|
||||
player.sendMessage(Colors.LightGray + "WG: " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ban a player.
|
||||
*
|
||||
* @param player
|
||||
* @param msg
|
||||
*/
|
||||
public void banPlayer(Player player, String msg) {
|
||||
etc.getServer().ban(player.getName());
|
||||
etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[]{
|
||||
player.getUser(), player.getUser(), msg
|
||||
});
|
||||
player.kick(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block destruction. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroy(final Block block, final Player player) {
|
||||
if (destroyActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDestroyAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You are not allowed to destroy " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You are not allowed to destroy " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (destroy) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You are not allowed to destroy " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, destroyActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block break. Returns true to let the action pass
|
||||
* through.
|
||||
*
|
||||
* @param block
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onBreak(final Block block, final Player player) {
|
||||
if (breakActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logBreakAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You are not allowed to break " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You are not allowed to break " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (break) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You are not allowed to break " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, breakActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on left click. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDestroyWith(final int item, final Player player) {
|
||||
if (destroyWithActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDestroyWithAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't destroy with " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't destroy with " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (destroy w/) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You can't destroy with " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, destroyWithActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on block placement. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onPlace(final int item, final Player player) {
|
||||
if (placeActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logPlaceAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't place " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't place " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (place) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You can't place " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, placeActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on use. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onUse(final int item, final Player player) {
|
||||
if (useActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logUseAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't use " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't use " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (use) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to use " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, useActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onRightClick(final Block block, final Player player) {
|
||||
if (useActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logRightClickAttempt(player, block, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't use " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't use " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (use) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to use " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(block.getType(), player, useActions, handler, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click upon. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentUse(final Block block, final Player player) {
|
||||
if (useActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return process(block.getType(), player, useActions, silentHandler, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item drop. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onDrop(final int item, final Player player) {
|
||||
if (dropActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logDropAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't drop " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't drop " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (drop) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to drop " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, dropActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onAcquire(final int item, final Player player) {
|
||||
if (acquireActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlacklistEntry entry = this;
|
||||
|
||||
ActionHandler handler = new ActionHandler() {
|
||||
public void log(String itemName) {
|
||||
blacklist.getLogger().logAcquireAttempt(player, item, comment);
|
||||
}
|
||||
public void kick(String itemName) {
|
||||
player.kick("You can't acquire " + itemName);
|
||||
}
|
||||
public void ban(String itemName) {
|
||||
entry.banPlayer(player, "Banned: You can't acquire " + itemName);
|
||||
}
|
||||
public void notifyAdmins(String itemName) {
|
||||
entry.notifyAdmins(player.getName() + " (acquire) " + itemName
|
||||
+ (comment != null ? " (" + comment + ")" : "") + ".");
|
||||
}
|
||||
public void tell(String itemName) {
|
||||
player.sendMessage(Colors.Yellow + "You're not allowed to acquire " + itemName + ".");
|
||||
}
|
||||
};
|
||||
|
||||
return process(item, player, acquireActions, handler, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item acquire. Returns true to let the action pass through.
|
||||
*
|
||||
* @param item
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean onSilentAcquire(final int item, final Player player) {
|
||||
if (acquireActions == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return process(item, player, acquireActions, silentHandler, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to handle the actions.
|
||||
*
|
||||
* @param id
|
||||
* @param player
|
||||
* @param actions
|
||||
* @param handler
|
||||
* @param allowRepeat
|
||||
* @param silent
|
||||
* @return
|
||||
*/
|
||||
private boolean process(int id, Player player, String[] actions,
|
||||
ActionHandler handler, boolean allowRepeat, boolean silent) {
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = player.getName();
|
||||
long now = System.currentTimeMillis();
|
||||
boolean repeating = false;
|
||||
|
||||
// Check to see whether this event is being repeated
|
||||
BlacklistTrackedEvent tracked = lastAffected.get(name);
|
||||
if (tracked != null) {
|
||||
if (tracked.getId() == id && tracked.getTime() > now - 3000) {
|
||||
repeating = true;
|
||||
} else {
|
||||
tracked.setTime(now);
|
||||
tracked.setId(id);
|
||||
}
|
||||
} else {
|
||||
lastAffected.put(name, new BlacklistTrackedEvent(id, now));
|
||||
}
|
||||
|
||||
boolean ret = true;
|
||||
|
||||
for (String action : actions) {
|
||||
// Deny
|
||||
if (action.equalsIgnoreCase("deny")) {
|
||||
if (silent) {
|
||||
return false;
|
||||
}
|
||||
ret = false;
|
||||
|
||||
// Kick
|
||||
} else if (action.equalsIgnoreCase("kick")) {
|
||||
if (this.message != null) {
|
||||
player.kick(String.format(this.message,
|
||||
etc.getDataSource().getItem(id)));
|
||||
} else {
|
||||
handler.kick(etc.getDataSource().getItem(id));
|
||||
}
|
||||
|
||||
// Ban
|
||||
} else if (action.equalsIgnoreCase("ban")) {
|
||||
handler.ban(etc.getDataSource().getItem(id));
|
||||
if (this.message != null) {
|
||||
banPlayer(player, "Banned: " + String.format(this.message,
|
||||
etc.getDataSource().getItem(id)));
|
||||
} else {
|
||||
handler.ban(etc.getDataSource().getItem(id));
|
||||
}
|
||||
|
||||
} else if (!repeating || allowRepeat) {
|
||||
// Notify
|
||||
if (action.equalsIgnoreCase("notify")) {
|
||||
handler.notifyAdmins(etc.getDataSource().getItem(id));
|
||||
|
||||
// Log
|
||||
} else if (action.equalsIgnoreCase("log")) {
|
||||
handler.log(etc.getDataSource().getItem(id));
|
||||
|
||||
// Tell
|
||||
} else if (action.equalsIgnoreCase("tell")) {
|
||||
if (this.message != null) {
|
||||
player.sendMessage(Colors.Yellow +
|
||||
String.format(message, etc.getDataSource().getItem(id))
|
||||
+ ".");
|
||||
} else {
|
||||
handler.tell(etc.getDataSource().getItem(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget a player.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void forgetPlayer(Player player) {
|
||||
lastAffected.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all players.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void forgetAllPlayers() {
|
||||
lastAffected.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called for actions.
|
||||
*/
|
||||
private static interface ActionHandler {
|
||||
public void log(String itemName);
|
||||
public void kick(String itemName);
|
||||
public void ban(String itemName);
|
||||
public void notifyAdmins(String itemName);
|
||||
public void tell(String itemName);
|
||||
}
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
// $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.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistLogger implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* List of logger handlers.
|
||||
*/
|
||||
private Set<BlacklistLoggerHandler> handlers
|
||||
= new HashSet<BlacklistLoggerHandler>();
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void addHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void removeHandler(BlacklistLoggerHandler handler) {
|
||||
handlers.remove(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public void clearHandlers() {
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDestroyAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logBreakAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logUseAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logRightClickAttempt(Player player, Block block, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logRightClickAttempt(player, block, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDestroyWithAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a place attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logPlaceAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logPlaceAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logDropAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.logAcquireAttempt(player, item, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
for (BlacklistLoggerHandler handler : handlers) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for loggers for the blacklist.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface BlacklistLoggerHandler {
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Log a use attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logUseAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log a place attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logPlaceAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logRightClickAttempt(Player player, Block block, String comment);
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment);
|
||||
/**
|
||||
* Close the logger.
|
||||
*/
|
||||
public void close();
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlacklistTrackedEvent {
|
||||
private int id;
|
||||
private long time;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param time
|
||||
*/
|
||||
public BlacklistTrackedEvent(int id, long time) {
|
||||
this.id = id;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time
|
||||
*/
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the time to set
|
||||
*/
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to destroy " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to break " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logRightClickAttempt(Player player, Block block, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to right click " + getFriendlyItemName(block.getType())
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an attempt to destroy with an item.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to destroy with " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block creation attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logPlaceAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to place " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a use attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logUseAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to use " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to drop " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||
+ " tried to acquire " + getFriendlyItemName(item)
|
||||
+ (comment != null ? " (" + comment + ")" : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
return etc.getDataSource().getItem(id) + " (#" + id + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
// $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.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
/**
|
||||
* DSN.
|
||||
*/
|
||||
private String dsn;
|
||||
/**
|
||||
* Username.
|
||||
*/
|
||||
private String user;
|
||||
/**
|
||||
* Password.
|
||||
*/
|
||||
private String pass;
|
||||
/**
|
||||
* Table.
|
||||
*/
|
||||
private String table;
|
||||
/**
|
||||
* Database connection.
|
||||
*/
|
||||
private Connection conn;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param dsn
|
||||
* @param user
|
||||
* @param pass
|
||||
*/
|
||||
public DatabaseLoggerHandler(String dsn, String user, String pass, String table) {
|
||||
this.dsn = dsn;
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database connection.
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private Connection getConnection() throws SQLException {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
conn = DriverManager.getConnection(dsn, user, pass);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event to the database.
|
||||
*
|
||||
* @param event
|
||||
* @param name
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param item
|
||||
* @param comment
|
||||
*/
|
||||
private void logEvent(String event, String name, int x, int y, int z, int item,
|
||||
String comment) {
|
||||
try {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"INSERT INTO " + table
|
||||
+ "(event, player, x, y, z, item, time, comment) VALUES "
|
||||
+ "(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
stmt.setString(1, event);
|
||||
stmt.setString(2, name);
|
||||
stmt.setInt(3, x);
|
||||
stmt.setInt(4, y);
|
||||
stmt.setInt(5, z);
|
||||
stmt.setInt(6, item);
|
||||
stmt.setInt(7, (int)(System.currentTimeMillis() / 1000));
|
||||
stmt.setString(8, comment);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logger.log(Level.SEVERE, "Failed to log blacklist event to database: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
logEvent("DESTROY", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
logEvent("BREAK", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logRightClickAttempt(Player player, Block block, String comment) {
|
||||
logEvent("RIGHT_CLICK", player.getName(),
|
||||
block.getX(), block.getY(), block.getZ(), block.getType(),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Right a left click attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
logEvent("DESTROY_WITH", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a place attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logPlaceAttempt(Player player, int item, String comment) {
|
||||
logEvent("PLACE", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a use attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logUseAttempt(Player player, int item, String comment) {
|
||||
logEvent("USE", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
logEvent("DROP", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an aquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
logEvent("AQUIRE", player.getName(),
|
||||
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()), item, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,326 +0,0 @@
|
||||
// $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.io.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Iterator;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FileLoggerHandler implements BlacklistLoggerHandler {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Regex for patterns in the path.
|
||||
*/
|
||||
private static Pattern pattern = Pattern.compile("%.");
|
||||
/**
|
||||
* Date format.
|
||||
*/
|
||||
private static SimpleDateFormat dateFormat =
|
||||
new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
* Number of files to keep open at a time.
|
||||
*/
|
||||
private int cacheSize = 10;
|
||||
/**
|
||||
* Path pattern.
|
||||
*/
|
||||
private String pathPattern;
|
||||
/**
|
||||
* Cache of writers.
|
||||
*/
|
||||
private TreeMap<String,FileLoggerWriter> writers =
|
||||
new TreeMap<String,FileLoggerWriter>();
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param pathPattern
|
||||
*/
|
||||
public FileLoggerHandler(String pathPattern) {
|
||||
this.pathPattern = pathPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param pathPattern
|
||||
* @param cacheSize
|
||||
*/
|
||||
public FileLoggerHandler(String pathPattern, int cacheSize) {
|
||||
if (cacheSize < 1) {
|
||||
throw new IllegalArgumentException("Cache size cannot be less than 1");
|
||||
}
|
||||
this.pathPattern = pathPattern;
|
||||
this.cacheSize = cacheSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the path.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String buildPath(String playerName) {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
|
||||
Matcher m = pattern.matcher(pathPattern);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
// Pattern replacements
|
||||
while (m.find()) {
|
||||
String group = m.group();
|
||||
String rep = "?";
|
||||
|
||||
if (group.matches("%%")) {
|
||||
rep = "%";
|
||||
} else if (group.matches("%u")) {
|
||||
rep = playerName.toLowerCase().replaceAll("[^A-Za-z0-9_]", "_");
|
||||
if (rep.length() > 32) { // Actual max length is 16
|
||||
rep = rep.substring(0, 32);
|
||||
}
|
||||
|
||||
// Date and time
|
||||
} else if (group.matches("%Y")) {
|
||||
rep = String.valueOf(calendar.get(Calendar.YEAR));
|
||||
} else if (group.matches("%m")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.MONTH));
|
||||
} else if (group.matches("%d")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));
|
||||
} else if (group.matches("%W")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.WEEK_OF_YEAR));
|
||||
} else if (group.matches("%H")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY));
|
||||
} else if (group.matches("%h")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.HOUR));
|
||||
} else if (group.matches("%i")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.MINUTE));
|
||||
} else if (group.matches("%s")) {
|
||||
rep = String.format("%02d", calendar.get(Calendar.SECOND));
|
||||
}
|
||||
|
||||
m.appendReplacement(buffer, rep);
|
||||
}
|
||||
|
||||
m.appendTail(buffer);
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
private void log(Player player, String message, String comment) {
|
||||
String path = buildPath(player.getName());
|
||||
try {
|
||||
String date = dateFormat.format(new Date());
|
||||
String line = "[" + date + "] " + player.getName() + ": " + message
|
||||
+ (comment != null ? " (" + comment + ")" : "") + "\r\n";
|
||||
|
||||
FileLoggerWriter writer = writers.get(path);
|
||||
|
||||
// Writer already exists!
|
||||
if (writer != null) {
|
||||
try {
|
||||
BufferedWriter out = writer.getWriter();
|
||||
out.write(line);
|
||||
out.flush();
|
||||
writer.updateLastUse();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
// Failed initial rewrite... let's re-open
|
||||
}
|
||||
}
|
||||
|
||||
// Make parent directory
|
||||
File file = new File(path);
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null && !parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
FileWriter stream = new FileWriter(path, true);
|
||||
BufferedWriter out = new BufferedWriter(stream);
|
||||
out.write(line);
|
||||
out.flush();
|
||||
writer = new FileLoggerWriter(path, out);
|
||||
writers.put(path, writer);
|
||||
|
||||
// Check to make sure our cache doesn't get too big!
|
||||
if (writers.size() > cacheSize) {
|
||||
Iterator<Map.Entry<String,FileLoggerWriter>> it =
|
||||
writers.entrySet().iterator();
|
||||
|
||||
// Remove some entries
|
||||
for (; it.hasNext(); ) {
|
||||
Map.Entry<String,FileLoggerWriter> entry = it.next();
|
||||
try {
|
||||
entry.getValue().getWriter().close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
it.remove();
|
||||
|
||||
// Trimmed enough
|
||||
if (writers.size() <= cacheSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Failed to log blacklist event to '"
|
||||
+ path + "': " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinates of a block in text form for the log.
|
||||
*
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
private String getCoordinates(Block block) {
|
||||
return "@" + block.getX() + "," + block.getY() + "," + block.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block destroy attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logDestroyAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to destroy " + getFriendlyItemName(block.getType())
|
||||
+ " " + getCoordinates(block),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block break attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logBreakAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to break " + getFriendlyItemName(block.getType())
|
||||
+ " " + getCoordinates(block),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a right click on attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param block
|
||||
*/
|
||||
public void logRightClickAttempt(Player player, Block block, String comment) {
|
||||
log(player, "Tried to right click " + getFriendlyItemName(block.getType())
|
||||
+ " " + getCoordinates(block),
|
||||
comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an attempt to destroy with an item.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDestroyWithAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to destroy with " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block creation attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logPlaceAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to place " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a block use attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logUseAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to use " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a drop attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logDropAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to drop " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an acquire attempt.
|
||||
*
|
||||
* @param player
|
||||
* @param item
|
||||
*/
|
||||
public void logAcquireAttempt(Player player, int item, String comment) {
|
||||
log(player, "Tried to acquire " + getFriendlyItemName(item), comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's friendly name with its ID.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private static String getFriendlyItemName(int id) {
|
||||
return etc.getDataSource().getItem(id) + " (#" + id + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Close handles.
|
||||
*/
|
||||
public void close() {
|
||||
for (Map.Entry<String,FileLoggerWriter> entry : writers.entrySet()) {
|
||||
try {
|
||||
entry.getValue().getWriter().close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
writers.clear();
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
// $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.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
|
||||
/**
|
||||
* Path.
|
||||
*/
|
||||
public String path;
|
||||
/**
|
||||
* Writer.
|
||||
*/
|
||||
private BufferedWriter writer;
|
||||
/**
|
||||
* Last use.
|
||||
*/
|
||||
private long lastUse;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param writer
|
||||
*/
|
||||
public FileLoggerWriter(String path, BufferedWriter writer) {
|
||||
this.path = path;
|
||||
this.writer = writer;
|
||||
lastUse = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* File path.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the writer
|
||||
*/
|
||||
public BufferedWriter getWriter() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastUse
|
||||
*/
|
||||
public long getLastUse() {
|
||||
return lastUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update last use time.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void updateLastUse() {
|
||||
lastUse = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison function.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
public int compareTo(FileLoggerWriter other) {
|
||||
if (lastUse > other.lastUse) {
|
||||
return 1;
|
||||
} else if (lastUse < other.lastUse) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Inventory related functions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ItemArrayUtil {
|
||||
/**
|
||||
* Set the contents of an ItemArray.
|
||||
*
|
||||
* @param itemArray
|
||||
* @param contents
|
||||
*/
|
||||
public static void setContents(ItemArray<?> itemArray, Item[] contents) {
|
||||
int size = itemArray.getContentsSize();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (contents[i] == null) {
|
||||
itemArray.removeItem(i);
|
||||
} else {
|
||||
itemArray.setSlot(contents[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
// $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.jar.Manifest;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.net.URL;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Entry point for the plugin for hey0's mod.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldGuard extends Plugin {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
/**
|
||||
* Listener for the plugin system.
|
||||
*/
|
||||
private WorldGuardListener listener;
|
||||
|
||||
/**
|
||||
* Initialize the plugin.
|
||||
*/
|
||||
public WorldGuard() {
|
||||
try {
|
||||
listener = new WorldGuardListener(this);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
logger.severe("*** WORLDGUARD FAILED TO LOAD. ALL PROTECTION IS DISABLED!");
|
||||
logger.severe("*** YOUR SERVER WILL BE SAVED AND STOPPED TO PREVENT DAMAGE TO YOUR WORLD. DISABLE WORLDGUARD OR CORRECT THE PROBLEM.");
|
||||
logger.severe("*** WorldEdit must be placed into the plugins/ directory");
|
||||
etc.getServer().useConsoleCommand("stop");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> missingFeatures = new ArrayList<String>();
|
||||
|
||||
registerHook("COMMAND", PluginListener.Priority.MEDIUM);
|
||||
registerHook("SERVERCOMMAND", PluginListener.Priority.MEDIUM);
|
||||
registerHook("EXPLODE", PluginListener.Priority.HIGH);
|
||||
registerHook("IGNITE", PluginListener.Priority.HIGH);
|
||||
registerHook("FLOW", PluginListener.Priority.HIGH);
|
||||
registerHook("LOGINCHECK", PluginListener.Priority.HIGH);
|
||||
registerHook("LOGIN", PluginListener.Priority.MEDIUM);
|
||||
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
|
||||
registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL);
|
||||
registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH);
|
||||
registerHook("BLOCK_PLACE", PluginListener.Priority.HIGH);
|
||||
registerHook("DISCONNECT", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_USE", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH);
|
||||
registerHook("SIGN_CHANGE", PluginListener.Priority.HIGH);
|
||||
registerHook("OPEN_INVENTORY", PluginListener.Priority.HIGH);
|
||||
registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM);
|
||||
registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM);
|
||||
registerHook("DAMAGE", PluginListener.Priority.MEDIUM);
|
||||
registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM);
|
||||
registerHook("BLOCK_RIGHTCLICKED", PluginListener.Priority.MEDIUM);
|
||||
|
||||
if (missingFeatures.size() > 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "
|
||||
+ concatMissingFeatures(missingFeatures) + ".");
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: Your version of hMod appears to"
|
||||
+ " support all features.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally registers a hook.
|
||||
*
|
||||
* @param name
|
||||
* @param priority
|
||||
* @return where the hook was registered correctly
|
||||
*/
|
||||
public boolean registerHook(String name, PluginListener.Priority priority) {
|
||||
try {
|
||||
PluginLoader.Hook hook = PluginLoader.Hook.valueOf(name);
|
||||
etc.getLoader().addListener(hook, listener, this, priority);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void enable() {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log(Level.INFO, "WorldGuard version " + getVersion() + " loaded");
|
||||
listener.loadConfiguration();
|
||||
|
||||
etc.getInstance().addCommand("/stopfire", "Globally stop fire spread");
|
||||
etc.getInstance().addCommand("/allowfire", "Globally re-enable fire spread");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the plugin.
|
||||
*/
|
||||
@Override
|
||||
public void disable() {
|
||||
try {
|
||||
listener.disable();
|
||||
BlacklistEntry.forgetAllPlayers();
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
|
||||
etc.getInstance().removeCommand("/stopfire");
|
||||
etc.getInstance().removeCommand("/allowfire");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldGuard version.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getVersion() {
|
||||
try {
|
||||
String classContainer = WorldGuard.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().toString();
|
||||
URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
|
||||
Manifest manifest = new Manifest(manifestUrl.openStream());
|
||||
Attributes attrib = manifest.getMainAttributes();
|
||||
String ver = (String)attrib.getValue("WorldGuard-Version");
|
||||
return ver != null ? ver : "(unavailable)";
|
||||
} catch (IOException e) {
|
||||
return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins a string from an array of strings.
|
||||
*
|
||||
* @param str
|
||||
* @param delimiter
|
||||
* @return
|
||||
*/
|
||||
private static String concatMissingFeatures(List<String> str) {
|
||||
if (str.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int size = str.size();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("(1) ");
|
||||
buffer.append(str.get(0));
|
||||
for (int i = 1; i < size; i++) {
|
||||
if (i == size - 1) {
|
||||
buffer.append(" or ");
|
||||
buffer.append("(");
|
||||
buffer.append(i + 1);
|
||||
buffer.append(") ");
|
||||
buffer.append(str.get(i));
|
||||
} else {
|
||||
buffer.append(", ");
|
||||
buffer.append("(");
|
||||
buffer.append(i + 1);
|
||||
buffer.append(") ");
|
||||
buffer.append(str.get(i));
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldguard;
|
||||
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public abstract class LocalPlayer {
|
||||
/**
|
||||
* Get a player's name.
|
||||
@ -35,6 +38,34 @@ public abstract class LocalPlayer {
|
||||
*/
|
||||
public abstract boolean hasGroup(String group);
|
||||
|
||||
/**
|
||||
* Get the player's position.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract Vector getPosition();
|
||||
|
||||
/**
|
||||
* Kick the player.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void kick(String msg);
|
||||
|
||||
/**
|
||||
* Ban the player.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void ban(String msg);
|
||||
|
||||
/**
|
||||
* Get the player's list of groups.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract List<String> getGroups();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof LocalPlayer)) {
|
||||
|
@ -17,12 +17,20 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
public class HMPlayer extends LocalPlayer {
|
||||
public class BukkitPlayer extends LocalPlayer {
|
||||
private Player player;
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public HMPlayer(Player player) {
|
||||
public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ -33,6 +41,28 @@ public String getName() {
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(String group) {
|
||||
return player.isInGroup(group);
|
||||
return plugin.inGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getPosition() {
|
||||
Location loc = player.getLocation();
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(String msg) {
|
||||
player.kickPlayer(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ban(String msg) {
|
||||
player.kickPlayer(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups() {
|
||||
return plugin.getGroups(player);
|
||||
}
|
||||
|
||||
}
|
53
src/com/sk89q/worldguard/bukkit/BukkitUtil.java
Normal file
53
src/com/sk89q/worldguard/bukkit/BukkitUtil.java
Normal file
@ -0,0 +1,53 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class BukkitUtil {
|
||||
private BukkitUtil() {
|
||||
}
|
||||
|
||||
public static BlockVector toVector(Block block) {
|
||||
return new BlockVector(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
public static Vector toVector(Location loc) {
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public static Vector toVector(org.bukkit.util.Vector vector) {
|
||||
return new Vector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static Player matchSinglePlayer(Server server, String name) {
|
||||
List<Player> players = server.matchPlayer(name);
|
||||
if (players.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
@ -19,6 +20,8 @@
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Sends all logger messages to a player.
|
||||
@ -56,7 +59,7 @@ public void flush() {
|
||||
* Publish a log record.
|
||||
*/
|
||||
public void publish(LogRecord record) {
|
||||
player.sendMessage(Colors.LightGray + record.getLevel().getName() + ": "
|
||||
+ Colors.White + record.getMessage());
|
||||
player.sendMessage(ChatColor.GRAY + record.getLevel().getName() + ": "
|
||||
+ ChatColor.WHITE + record.getMessage());
|
||||
}
|
||||
}
|
284
src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java
Normal file
284
src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java
Normal file
@ -0,0 +1,284 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
public class WorldGuardBlockListener extends BlockListener {
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldGuardBlockListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is damaged (or broken)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (plugin.useRegions) {
|
||||
Vector pt = BukkitUtil.toVector(event.getBlock());
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!plugin.hasPermission(player, "/regionbypass")
|
||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block flows (water/lava)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
World world = event.getBlock().getWorld();
|
||||
Block blockFrom = event.getFromBlock();
|
||||
Block blockTo = event.getBlock();
|
||||
|
||||
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
|
||||
boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
|
||||
|
||||
if (plugin.simulateSponge && isWater) {
|
||||
int ox = blockTo.getX();
|
||||
int oy = blockTo.getY();
|
||||
int oz = blockTo.getZ();
|
||||
|
||||
for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
|
||||
for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
|
||||
for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
|
||||
if (world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz) == 19) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.classicWater && isWater) {
|
||||
int blockBelow = world.getBlockTypeIdAt(blockFrom.getX(), blockFrom.getY() - 1, blockFrom.getZ());
|
||||
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
|
||||
world.getBlockAt(blockFrom.getX(), blockFrom.getY(), blockFrom.getZ()).setTypeId(9);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.allowedLavaSpreadOver != null && isLava) {
|
||||
int targetId = world.getBlockTypeIdAt(
|
||||
blockTo.getX(), blockTo.getY() - 1, blockTo.getZ());
|
||||
if (!plugin.allowedLavaSpreadOver.contains(targetId)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
IgniteCause cause = event.getCause();
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = block.getWorld();
|
||||
boolean isFireSpread = cause == IgniteCause.SLOW_SPREAD
|
||||
|| cause == IgniteCause.SPREAD;
|
||||
|
||||
if (plugin.preventLavaFire && cause == IgniteCause.LAVA) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.disableAllFire) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.blockLighter && cause == IgniteCause.FLINT_AND_STEEL) {
|
||||
event.setCancelled(!plugin.hasPermission(player, "/uselighter")
|
||||
&& !plugin.hasPermission(player, "/lighter"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.stopFireSpread && isFireSpread) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.fireNoSpreadBlocks.size() > 0 && isFireSpread) {
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
if (plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y - 1, z))
|
||||
|| plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x + 1, y, z))
|
||||
|| plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x - 1, y, z))
|
||||
|| plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y, z - 1))
|
||||
|| plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y, z + 1))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.useRegions && player != null && !plugin.hasPermission(player, "/regionbypass")) {
|
||||
Vector pt = toVector(block);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (cause == IgniteCause.FLINT_AND_STEEL
|
||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.FLINT_AND_STEEL
|
||||
&& !plugin.regionManager.getApplicableRegions(pt).allowsLighter()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
int id = event.getChangedTypeId();
|
||||
|
||||
if (id == 13 && plugin.noPhysicsGravel) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 12 && plugin.noPhysicsSand) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 90 && plugin.allowPortalAnywhere) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block blockPlaced = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
World world = blockPlaced.getWorld();
|
||||
|
||||
if (plugin.useRegions) {
|
||||
Vector pt = new Vector(blockPlaced.getX(),
|
||||
blockPlaced.getY(), blockPlaced.getZ());
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!plugin.hasPermission(player, "/regionbypass")
|
||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.simulateSponge && blockPlaced.getTypeId() == 19) {
|
||||
int ox = blockPlaced.getX();
|
||||
int oy = blockPlaced.getY();
|
||||
int oz = blockPlaced.getZ();
|
||||
|
||||
for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
|
||||
for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
|
||||
for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
|
||||
int id = world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz);
|
||||
if (id == 8 || id == 9) {
|
||||
world.getBlockAt(ox + cx, oy + cy, oz + cz)
|
||||
.setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (plugin.useRegions && event.getItemInHand().getTypeId() == plugin.regionWand) {
|
||||
Vector pt = toVector(event.getBlock());
|
||||
ApplicableRegionSet app = plugin.regionManager.getApplicableRegions(pt);
|
||||
List<String> regions = plugin.regionManager.getApplicableRegionsIDs(pt);
|
||||
|
||||
if (regions.size() > 0) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Can you build? "
|
||||
+ (app.canBuild(plugin.wrapPlayer(player)) ? "Yes" : "No"));
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
|
||||
str.append(it.next());
|
||||
if (it.hasNext()) {
|
||||
str.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
111
src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java
Normal file
111
src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java
Normal file
@ -0,0 +1,111 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
public class WorldGuardEntityListener extends EntityListener {
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
|
||||
Entity defender = event.getEntity();
|
||||
DamageCause type = event.getCause();
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player)defender;
|
||||
|
||||
if (plugin.invinciblePlayers.contains(player.getName())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.disableFallDamage && type == DamageCause.FALL) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.disableLavaDamage && type == DamageCause.LAVA) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.disableFireDamage && (type == DamageCause.FIRE
|
||||
|| type == DamageCause.FIRE_TICK)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.disableWaterDamage && type == DamageCause.DROWNING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == DamageCause.DROWNING
|
||||
&& plugin.amphibiousPlayers.contains(player.getName())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
if (defender instanceof Player) {
|
||||
Player player = (Player)defender;
|
||||
|
||||
if (plugin.invinciblePlayers.contains(player.getName())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker != null && attacker instanceof Player) {
|
||||
if (plugin.useRegions) {
|
||||
Vector pt = toVector(defender.getLocation());
|
||||
|
||||
if (!plugin.regionManager.getApplicableRegions(pt).allowsPvP()) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
625
src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java
Normal file
625
src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java
Normal file
@ -0,0 +1,625 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditAPI;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditNotInstalled;
|
||||
import com.sk89q.worldguard.*;
|
||||
import com.sk89q.worldguard.domains.*;
|
||||
import com.sk89q.worldguard.protection.*;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to a Player
|
||||
*/
|
||||
public class WorldGuardPlayerListener extends PlayerListener {
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldGuardPlugin plugin;
|
||||
/**
|
||||
* Group pattern used to specify groups for the region command.
|
||||
*/
|
||||
private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
|
||||
|
||||
private static int CMD_LIST_SIZE = 9;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player joins a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (plugin.stopFireSpread) {
|
||||
player.sendMessage(ChatColor.YELLOW
|
||||
+ "Fire spread is currently globally disabled.");
|
||||
}
|
||||
|
||||
if (plugin.loginProtection > 0 || plugin.spawnProtection > 0
|
||||
|| plugin.kickOnDeath || plugin.teleportToHome || plugin.exactRespawn) {
|
||||
plugin.recentLogins.put(player.getName(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (plugin.inGroup(player, "wg-invincible")) {
|
||||
plugin.invinciblePlayers.add(player.getName());
|
||||
}
|
||||
|
||||
if (plugin.inGroup(player, "wg-amphibious")) {
|
||||
plugin.amphibiousPlayers.add(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player leaves a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
plugin.invinciblePlayers.remove(player.getName());
|
||||
plugin.amphibiousPlayers.remove(player.getName());
|
||||
plugin.recentLogins.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses an item
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerItem(PlayerItemEvent event) {
|
||||
if (plugin.useRegions && event.isBlock()) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlockClicked();
|
||||
Vector pt = toVector(block);
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (!plugin.hasPermission(player, "/regionbypass")
|
||||
&& !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
|
||||
player.sendMessage(ChatColor.DARK_RED
|
||||
+ "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to log in to the server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (plugin.enforceOneSession) {
|
||||
String name = player.getName();
|
||||
|
||||
for (Player pl : plugin.getServer().getOnlinePlayers()) {
|
||||
if (pl.getName().equalsIgnoreCase(name)) {
|
||||
pl.kickPlayer("Logged in from another location.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to use a command
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
if (handleCommand(event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to use a command
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public boolean handleCommand(PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String[] split = event.getMessage().split(" ");
|
||||
|
||||
if (split[0].equalsIgnoreCase("/stopfire") &&
|
||||
plugin.hasPermission(player, "/stopfire")) {
|
||||
if (!plugin.stopFireSpread) {
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "Fire spread has been globally disabled by " + player.getName() + ".");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally disabled.");
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("/allowfire")
|
||||
&& plugin.hasPermission(player, "/stopfire")) {
|
||||
if (plugin.stopFireSpread) {
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "Fire spread has been globally re-enabled by " + player.getName() + ".");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally enabled.");
|
||||
}
|
||||
|
||||
plugin.stopFireSpread = false;
|
||||
} else if (split[0].equalsIgnoreCase("/god")
|
||||
&& plugin.hasPermission(player, "/god")) {
|
||||
// Allow setting other people invincible
|
||||
if (split.length > 1) {
|
||||
if (!plugin.hasPermission(player, "/godother")) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to make others invincible.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player other = matchSinglePlayer(plugin.getServer(), split[1]);
|
||||
if (other == null) {
|
||||
player.sendMessage(ChatColor.RED + "Player not found.");
|
||||
} else {
|
||||
if (!plugin.invinciblePlayers.contains(other.getName())) {
|
||||
plugin.invinciblePlayers.add(other.getName());
|
||||
player.sendMessage(ChatColor.YELLOW + other.getName() + " is now invincible!");
|
||||
other.sendMessage(ChatColor.YELLOW + player.getName() + " has made you invincible!");
|
||||
} else {
|
||||
plugin.invinciblePlayers.remove(other.getName());
|
||||
player.sendMessage(ChatColor.YELLOW + other.getName() + " is no longer invincible.");
|
||||
other.sendMessage(ChatColor.YELLOW + player.getName() + " has taken away your invincibility.");
|
||||
}
|
||||
}
|
||||
// Invincibility for one's self
|
||||
} else {
|
||||
if (!plugin.invinciblePlayers.contains(player.getName())) {
|
||||
plugin.invinciblePlayers.add(player.getName());
|
||||
player.sendMessage(ChatColor.YELLOW + "You are now invincible!");
|
||||
} else {
|
||||
plugin.invinciblePlayers.remove(player.getName());
|
||||
player.sendMessage(ChatColor.YELLOW + "You are no longer invincible.");
|
||||
}
|
||||
}
|
||||
} else if ((split[0].equalsIgnoreCase("/stack")
|
||||
|| split[0].equalsIgnoreCase("/;"))
|
||||
&& plugin.hasPermission(player, "/stack")) {
|
||||
ItemStack[] items = player.getInventory().getContents();
|
||||
int len = items.length;
|
||||
|
||||
int affected = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
ItemStack item = items[i];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item == null || item.getAmount() <= 0
|
||||
|| ItemType.shouldNotStack(item.getTypeId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore buckets
|
||||
if (item.getTypeId() >= 325 && item.getTypeId() <= 327) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.getAmount() < 64) {
|
||||
int needed = 64 - item.getAmount(); // Number of needed items until 64
|
||||
|
||||
// Find another stack of the same type
|
||||
for (int j = i + 1; j < len; j++) {
|
||||
ItemStack item2 = items[j];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item2 == null || item2.getAmount() <= 0
|
||||
|| ItemType.shouldNotStack(item.getTypeId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Same type?
|
||||
if (item2.getTypeId() == item.getTypeId()) {
|
||||
// This stack won't fit in the parent stack
|
||||
if (item2.getAmount() > needed) {
|
||||
item.setAmount(64);
|
||||
item2.setAmount(item2.getAmount() - needed);
|
||||
break;
|
||||
// This stack will
|
||||
} else {
|
||||
items[j] = null;
|
||||
item.setAmount(item.getAmount() + item2.getAmount());
|
||||
needed = 64 - item.getAmount();
|
||||
}
|
||||
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (affected > 0) {
|
||||
player.getInventory().setContents(items);
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Items compacted into stacks!");
|
||||
} else if (split[0].equalsIgnoreCase("/rg")
|
||||
|| split[0].equalsIgnoreCase("/region")) {
|
||||
if (split.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg <define|flag|delete|info|add|remove|list|save|load> ...");
|
||||
return true;
|
||||
}
|
||||
|
||||
String action = split[1];
|
||||
String[] args = new String[split.length - 1];
|
||||
System.arraycopy(split, 1, args, 0, split.length - 1);
|
||||
|
||||
handleRegionCommand(player, action, args);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a region command.
|
||||
*
|
||||
* @param player
|
||||
* @param action
|
||||
* @param args
|
||||
*/
|
||||
private void handleRegionCommand(Player player, String action, String[] args) {
|
||||
if (action.equalsIgnoreCase("define")
|
||||
&& canUseRegionCommand(player, "/regiondefine")) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg define <id> [owner1 [owner2 [owners...]]]");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = args[1].toLowerCase();
|
||||
Plugin wePlugin = plugin.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin == null) {
|
||||
player.sendMessage(ChatColor.RED + "WorldEdit must be installed and enabled as a plugin.");
|
||||
return;
|
||||
}
|
||||
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin)wePlugin;
|
||||
WorldEditAPI api = worldEdit.getAPI();
|
||||
|
||||
LocalSession session = api.getSession(player);
|
||||
Region weRegion = session.getRegion();
|
||||
|
||||
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
|
||||
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(min, max);
|
||||
if (args.length >= 3) {
|
||||
region.setOwners(parseDomainString(args, 2));
|
||||
}
|
||||
plugin.regionManager.addRegion(id, region);
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
|
||||
} catch (IncompleteRegionException e) {
|
||||
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("flag")
|
||||
&& canUseRegionCommand(player, "/regiondefine")) {
|
||||
if (args.length < 4) {
|
||||
player.sendMessage(ChatColor.RED + "/rg flag <id> <build|pvp|tnt|lighter> <none|allow|deny>");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = args[1].toLowerCase();
|
||||
String flagStr = args[2];
|
||||
String stateStr = args[3];
|
||||
ProtectedRegion region = plugin.regionManager.getRegion(id);
|
||||
|
||||
if (region == null) {
|
||||
player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
AreaFlags.State state = null;
|
||||
|
||||
if (stateStr.equalsIgnoreCase("allow")) {
|
||||
state = AreaFlags.State.ALLOW;
|
||||
} else if (stateStr.equalsIgnoreCase("deny")) {
|
||||
state = AreaFlags.State.DENY;
|
||||
} else if (stateStr.equalsIgnoreCase("none")) {
|
||||
state = AreaFlags.State.NONE;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Acceptable states: allow, deny, none");
|
||||
return;
|
||||
}
|
||||
|
||||
AreaFlags flags = region.getFlags();
|
||||
|
||||
if (flagStr.equalsIgnoreCase("build")) {
|
||||
flags.allowBuild = state;
|
||||
} else if (flagStr.equalsIgnoreCase("pvp")) {
|
||||
flags.allowPvP = state;
|
||||
} else if (flagStr.equalsIgnoreCase("tnt")) {
|
||||
flags.allowTNT = state;
|
||||
} else if (flagStr.equalsIgnoreCase("lighter")) {
|
||||
flags.allowLighter = state;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Acceptable flags: build, pvp, tnt, lighter");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("info")
|
||||
&& canUseRegionCommand(player, "/regioninfo")) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg info <id>");
|
||||
return;
|
||||
}
|
||||
|
||||
String id = args[1].toLowerCase();
|
||||
if (!plugin.regionManager.hasRegion(id)) {
|
||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||
+ id + "' doesn't exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
ProtectedRegion region = plugin.regionManager.getRegion(id);
|
||||
AreaFlags flags = region.getFlags();
|
||||
DefaultDomain domain = region.getOwners();
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Region ID: " + id);
|
||||
player.sendMessage(ChatColor.GRAY + "Type: " + region.getClass().getCanonicalName());
|
||||
player.sendMessage(ChatColor.BLUE + "Build: " + flags.allowBuild.name());
|
||||
player.sendMessage(ChatColor.BLUE + "PvP: " + flags.allowPvP.name());
|
||||
player.sendMessage(ChatColor.BLUE + "TNT: " + flags.allowTNT.name());
|
||||
player.sendMessage(ChatColor.BLUE + "Lighter: " + flags.allowLighter.name());
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "Players: " + domain.toPlayersString());
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "Groups: " + domain.toGroupsString());
|
||||
} else if (action.equalsIgnoreCase("add")
|
||||
&& canUseRegionCommand(player, "/regiondefine")) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg add <id>");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = args[1].toLowerCase();
|
||||
if (!plugin.regionManager.hasRegion(id)) {
|
||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||
+ id + "' doesn't exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
addToDomain(plugin.regionManager.getRegion(id).getOwners(), args, 1);
|
||||
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("remove")
|
||||
&& canUseRegionCommand(player, "/regiondefine")) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg remove <id>");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = args[1].toLowerCase();
|
||||
if (!plugin.regionManager.hasRegion(id)) {
|
||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||
+ id + "' doesn't exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
removeFromDomain(plugin.regionManager.getRegion(id).getOwners(), args, 1);
|
||||
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region updated!");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("list")
|
||||
&& canUseRegionCommand(player, "/regionlist")) {
|
||||
int page = 0;
|
||||
|
||||
if (args.length >= 2) {
|
||||
try {
|
||||
page = Math.max(0, Integer.parseInt(args[1]) - 1);
|
||||
} catch (NumberFormatException e) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,ProtectedRegion> regions = plugin.regionManager.getRegions();
|
||||
int size = regions.size();
|
||||
int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
|
||||
|
||||
String[] regionIDList = new String[size];
|
||||
int index = 0;
|
||||
for (String id : regions.keySet()) {
|
||||
regionIDList[index] = id;
|
||||
index++;
|
||||
}
|
||||
Arrays.sort(regionIDList);
|
||||
|
||||
|
||||
player.sendMessage(ChatColor.RED + "Regions (page "
|
||||
+ (page + 1) + " of " + pages + "):");
|
||||
|
||||
if (page < pages) {
|
||||
for (int i = page * CMD_LIST_SIZE; i < page * CMD_LIST_SIZE + CMD_LIST_SIZE; i++) {
|
||||
if (i >= size) break;
|
||||
player.sendMessage(ChatColor.YELLOW.toString() + (i + 1) + ". " + regionIDList[i]);
|
||||
}
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("delete")
|
||||
&& canUseRegionCommand(player, "/regiondelete")) {
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "/rg delete <id>");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = args[1].toLowerCase();
|
||||
if (!plugin.regionManager.hasRegion(id)) {
|
||||
player.sendMessage(ChatColor.RED + "A region with ID '"
|
||||
+ id + "' doesn't exist.");
|
||||
return;
|
||||
}
|
||||
plugin.regionManager.removeRegion(id);
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region removed!");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("save")
|
||||
&& canUseRegionCommand(player, "/regionsave")) {
|
||||
try {
|
||||
plugin.regionLoader.save(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to save: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else if (action.equalsIgnoreCase("load")
|
||||
&& canUseRegionCommand(player, "/regionload")) {
|
||||
try {
|
||||
plugin.regionLoader.load(plugin.regionManager);
|
||||
player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Region database failed to load: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "/rg <define|flag|delete|info|add|remove|list|save|load> ...");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the command or /region.
|
||||
*
|
||||
* @param player
|
||||
* @param cmd
|
||||
* @return
|
||||
*/
|
||||
private boolean canUseRegionCommand(Player player, String cmd) {
|
||||
return plugin.hasPermission(player, "/region")
|
||||
|| plugin.hasPermission(player, cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a group/player DefaultDomain specification for areas.
|
||||
*
|
||||
* @param domain
|
||||
* @param split
|
||||
* @param startIndex
|
||||
*/
|
||||
private static void addToDomain(DefaultDomain domain,
|
||||
String[] split, int startIndex) {
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.addGroup(m.group(1));
|
||||
} else {
|
||||
domain.addPlayer(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a group/player DefaultDomain specification for areas.
|
||||
*
|
||||
* @param domain
|
||||
* @param split
|
||||
* @param startIndex
|
||||
*/
|
||||
private static void removeFromDomain(DefaultDomain domain,
|
||||
String[] split, int startIndex) {
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.removeGroup(m.group(1));
|
||||
} else {
|
||||
domain.removePlayer(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a group/player DefaultDomain specification for areas.
|
||||
*
|
||||
* @param split
|
||||
* @param startIndex
|
||||
* @return
|
||||
*/
|
||||
private static DefaultDomain parseDomainString(String[] split, int startIndex) {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
||||
for (int i = startIndex; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
Matcher m = groupPattern.matcher(s);
|
||||
if (m.matches()) {
|
||||
domain.addGroup(m.group(1));
|
||||
} else {
|
||||
domain.addPlayer(s);
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
}
|
280
src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
Normal file
280
src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
Normal file
@ -0,0 +1,280 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import com.sk89q.worldguard.protection.CSVDatabase;
|
||||
import com.sk89q.worldguard.protection.FlatRegionManager;
|
||||
import com.sk89q.worldguard.protection.ProtectionDatabase;
|
||||
import com.sk89q.worldguard.protection.RegionManager;
|
||||
|
||||
/**
|
||||
* Plugin for Bukkit.
|
||||
*
|
||||
* @author sk89qs
|
||||
*/
|
||||
public class WorldGuardPlugin extends JavaPlugin {
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
private final WorldGuardPlayerListener playerListener =
|
||||
new WorldGuardPlayerListener(this);
|
||||
private final WorldGuardBlockListener blockListener =
|
||||
new WorldGuardBlockListener(this);
|
||||
private final WorldGuardEntityListener entityListener =
|
||||
new WorldGuardEntityListener(this);
|
||||
|
||||
RegionManager regionManager = new FlatRegionManager();
|
||||
ProtectionDatabase regionLoader =
|
||||
new CSVDatabase(new File("worldguard-regions.txt"));
|
||||
|
||||
Set<String> invinciblePlayers = new HashSet<String>();
|
||||
Set<String> amphibiousPlayers = new HashSet<String>();
|
||||
Map<String,Long> recentLogins = new HashMap<String,Long>();
|
||||
Map<String,Long> lastSpawn = new HashMap<String,Long>();
|
||||
|
||||
boolean stopFireSpread = false;
|
||||
|
||||
boolean useRegions = false;
|
||||
boolean enforceOneSession;
|
||||
boolean blockCreepers;
|
||||
boolean blockTNT;
|
||||
boolean blockLighter;
|
||||
boolean preventLavaFire;
|
||||
boolean disableAllFire;
|
||||
boolean simulateSponge;
|
||||
int spongeRadius;
|
||||
Set<Integer> fireNoSpreadBlocks;
|
||||
Set<Integer> allowedLavaSpreadOver;
|
||||
Set<Integer> itemDropBlacklist;
|
||||
Set<Integer> preventWaterDamage;
|
||||
boolean classicWater;
|
||||
boolean noPhysicsGravel;
|
||||
boolean noPhysicsSand;
|
||||
boolean allowPortalAnywhere;
|
||||
boolean disableFallDamage;
|
||||
boolean disableLavaDamage;
|
||||
boolean disableFireDamage;
|
||||
boolean disableWaterDamage;
|
||||
boolean disableSuffocationDamage;
|
||||
boolean teleportOnSuffocation;
|
||||
int loginProtection;
|
||||
int spawnProtection;
|
||||
boolean teleportToHome;
|
||||
boolean exactRespawn;
|
||||
boolean kickOnDeath;
|
||||
int regionWand = 287;
|
||||
|
||||
public WorldGuardPlugin(PluginLoader pluginLoader, Server instance,
|
||||
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||
|
||||
logger.info("WorldGuard " + desc.getVersion() + " loaded.");
|
||||
loadConfiguration();
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
//loadConfiguration();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
|
||||
playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND,
|
||||
playerListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED,
|
||||
blockListener, Priority.Normal, this);
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED,
|
||||
blockListener, Priority.Normal, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration
|
||||
*/
|
||||
public void loadConfiguration() {
|
||||
Configuration config = getConfiguration();
|
||||
|
||||
try {
|
||||
regionLoader.load();
|
||||
regionManager.setRegions(regionLoader.getRegions());
|
||||
} catch (IOException e) {
|
||||
logger.warning("WorldGuard: Failed to load regions: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
recentLogins.clear();
|
||||
|
||||
// Load basic options
|
||||
enforceOneSession = config.getBoolean("protection.enforce-single-session", true);
|
||||
|
||||
blockCreepers = config.getBoolean("mobs.block-creeper-explosions", false);
|
||||
|
||||
blockTNT = config.getBoolean("ignition.block-tnt", false);
|
||||
blockLighter = config.getBoolean("ignition.block-lighter", false);
|
||||
|
||||
preventLavaFire = config.getBoolean("fire.disable-lava-fire-spread", true);
|
||||
disableAllFire = config.getBoolean("fire.disable-fire-spread", false);
|
||||
preventWaterDamage = new HashSet<Integer>(config.getIntList("physics.disable-water-damage-blocks", null));
|
||||
itemDropBlacklist = new HashSet<Integer>(config.getIntList("protection.item-drop-blacklist", null));
|
||||
fireNoSpreadBlocks = new HashSet<Integer>(config.getIntList("fire.disable-fire-spread", null));
|
||||
allowedLavaSpreadOver = new HashSet<Integer>(config.getIntList("fire.lava-spread-blocks", null));
|
||||
|
||||
classicWater = config.getBoolean("simulation.classic-water", false);
|
||||
simulateSponge = config.getBoolean("simulation.sponge.enable", true);
|
||||
spongeRadius = Math.max(1, config.getInt("simulation.sponge.radius", 3)) - 1;
|
||||
|
||||
noPhysicsGravel = config.getBoolean("physics.no-physics-gravel", false);
|
||||
noPhysicsSand = config.getBoolean("physics.no-physics-sand", false);
|
||||
allowPortalAnywhere = config.getBoolean("physics.allow-portal-anywhere", false);
|
||||
|
||||
disableFallDamage = config.getBoolean("player-damage.disable-fall-damage", false);
|
||||
disableLavaDamage = config.getBoolean("player-damage.disable-lava-damage", false);
|
||||
disableFireDamage = config.getBoolean("player-damage.disable-fire-damage", false);
|
||||
disableWaterDamage = config.getBoolean("player-damage.disable-water-damage", false);
|
||||
disableSuffocationDamage = config.getBoolean("player-damage.disable-suffocation-damage", false);
|
||||
teleportOnSuffocation = config.getBoolean("player-damage.teleport-on-suffocation", false);
|
||||
|
||||
loginProtection = config.getInt("spawn.login-protection", 3);
|
||||
spawnProtection = config.getInt("spawn.spawn-protection", 0);
|
||||
kickOnDeath = config.getBoolean("spawn.kick-on-death", false);
|
||||
teleportToHome = config.getBoolean("spawn.teleport-to-home-on-death", false);
|
||||
exactRespawn = config.getBoolean("spawn.exact-respawn", false);
|
||||
|
||||
useRegions = config.getBoolean("regions.enable", true);
|
||||
regionWand = config.getInt("regions.wand", 287);
|
||||
|
||||
/*
|
||||
// Console log configuration
|
||||
boolean logConsole = properties.getBoolean("log-console", true);
|
||||
|
||||
// Database log configuration
|
||||
boolean logDatabase = properties.getBoolean("log-database", false);
|
||||
String dsn = properties.getString("log-database-dsn", "jdbc:mysql://localhost:3306/minecraft");
|
||||
String user = properties.getString("log-database-user", "root");
|
||||
String pass = properties.getString("log-database-pass", "");
|
||||
String table = properties.getString("log-database-table", "blacklist_events");
|
||||
|
||||
// File log configuration
|
||||
boolean logFile = properties.getBoolean("log-file", false);
|
||||
String logFilePattern = properties.getString("log-file-path", "worldguard/logs/%Y-%m-%d.log");
|
||||
int logFileCacheSize = Math.max(1, properties.getInt("log-file-open-files", 10));
|
||||
|
||||
// Load the blacklist
|
||||
try {
|
||||
// If there was an existing blacklist, close loggers
|
||||
if (blacklist != null) {
|
||||
blacklist.getLogger().close();
|
||||
}
|
||||
|
||||
// First load the blacklist data from worldguard-blacklist.txt
|
||||
Blacklist blist = new Blacklist();
|
||||
blist.load(new File("worldguard-blacklist.txt"));
|
||||
|
||||
// If the blacklist is empty, then set the field to null
|
||||
// and save some resources
|
||||
if (blist.isEmpty()) {
|
||||
this.blacklist = null;
|
||||
} else {
|
||||
this.blacklist = blist;
|
||||
logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
|
||||
|
||||
BlacklistLogger blacklistLogger = blist.getLogger();
|
||||
|
||||
if (logDatabase) {
|
||||
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table));
|
||||
}
|
||||
|
||||
if (logConsole) {
|
||||
blacklistLogger.addHandler(new ConsoleLoggerHandler());
|
||||
}
|
||||
|
||||
if (logFile) {
|
||||
FileLoggerHandler handler =
|
||||
new FileLoggerHandler(logFilePattern, logFileCacheSize);
|
||||
blacklistLogger.addHandler(handler);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
|
||||
+ e.getMessage());
|
||||
}*/
|
||||
|
||||
// Print an overview of settings
|
||||
if (config.getBoolean("summary-on-start", true)) {
|
||||
logger.log(Level.INFO, enforceOneSession ? "WorldGuard: Single session is enforced."
|
||||
: "WorldGuard: Single session is NOT ENFORCED.");
|
||||
logger.log(Level.INFO, blockTNT ? "WorldGuard: TNT ignition is blocked."
|
||||
: "WorldGuard: TNT ignition is PERMITTED.");
|
||||
logger.log(Level.INFO, blockLighter ? "WorldGuard: Lighters are blocked."
|
||||
: "WorldGuard: Lighters are PERMITTED.");
|
||||
logger.log(Level.INFO, preventLavaFire ? "WorldGuard: Lava fire is blocked."
|
||||
: "WorldGuard: Lava fire is PERMITTED.");
|
||||
if (disableAllFire) {
|
||||
logger.log(Level.INFO, "WorldGuard: All fire spread is disabled.");
|
||||
} else {
|
||||
if (fireNoSpreadBlocks != null) {
|
||||
logger.log(Level.INFO, "WorldGuard: Fire spread is limited to "
|
||||
+ fireNoSpreadBlocks.size() + " block types.");
|
||||
} else {
|
||||
logger.log(Level.INFO, "WorldGuard: Fire spread is UNRESTRICTED.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean inGroup(Player player, String group) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean hasPermission(Player player, String hasPermission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> getGroups(Player player) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
BukkitPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(this, player);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user