2010-09-28 10:12:34 +02:00
|
|
|
// $Id$
|
|
|
|
/*
|
2010-11-04 00:46:47 +01:00
|
|
|
* WorldEditLibrary
|
2010-09-28 10:12:34 +02:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-21 01:15:20 +02:00
|
|
|
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
2010-11-04 00:46:47 +01:00
|
|
|
import java.util.Map;
|
2010-10-12 22:51:25 +02:00
|
|
|
import java.util.HashSet;
|
2010-11-04 01:05:05 +01:00
|
|
|
import java.util.jar.Manifest;
|
|
|
|
import java.util.jar.Attributes;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2010-09-28 10:12:34 +02:00
|
|
|
|
2010-09-30 08:41:05 +02:00
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* Entry point for the plugin for hey0's mod.
|
|
|
|
*
|
2010-09-30 08:41:05 +02:00
|
|
|
* @author sk89q
|
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
public class WorldEdit extends Plugin {
|
2010-11-04 01:05:05 +01:00
|
|
|
/**
|
|
|
|
* Logger.
|
|
|
|
*/
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
2010-10-14 20:59:45 +02:00
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* WorldEditLibrary's properties file.
|
2010-10-14 20:59:45 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
private PropertiesFile properties;
|
2010-10-14 20:59:45 +02:00
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* WorldEditLibrary instance.
|
2010-10-14 20:59:45 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
private static final WorldEditLibrary worldEdit =
|
|
|
|
WorldEditLibrary.setup(new HmodServerInterface());
|
2010-10-12 22:51:25 +02:00
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* Listener for the plugin system.
|
2010-10-12 22:51:25 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
private static final HmodWorldEditListener listener =
|
|
|
|
new HmodWorldEditListener();
|
2010-10-03 01:28:02 +02:00
|
|
|
|
2010-10-12 22:51:25 +02:00
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* Initializes the plugin.
|
2010-10-21 01:15:20 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
@Override
|
|
|
|
public void initialize() {
|
|
|
|
PluginLoader loader = etc.getLoader();
|
2010-10-03 01:28:02 +02:00
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
|
|
|
|
PluginListener.Priority.MEDIUM);
|
|
|
|
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
|
|
|
|
PluginListener.Priority.MEDIUM);
|
|
|
|
loader.addListener(PluginLoader.Hook.COMMAND, listener, this,
|
|
|
|
PluginListener.Priority.MEDIUM);
|
|
|
|
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
|
|
|
|
PluginListener.Priority.MEDIUM);
|
|
|
|
loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
|
|
|
|
PluginListener.Priority.MEDIUM);
|
2010-11-04 01:05:05 +01:00
|
|
|
|
|
|
|
logger.log(Level.INFO, "WorldEdit version " + getWorldEditVersion() + " loaded.");
|
2010-10-14 20:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* Enables the plugin.
|
2010-10-14 20:59:45 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
@Override
|
|
|
|
public void enable() {
|
|
|
|
if (properties == null) {
|
|
|
|
properties = new PropertiesFile("worldedit.properties");
|
2010-09-30 08:41:05 +02:00
|
|
|
} else {
|
2010-11-04 00:46:47 +01:00
|
|
|
properties.load();
|
2010-09-30 08:41:05 +02:00
|
|
|
}
|
2010-10-03 19:44:52 +02:00
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
// Get allowed blocks
|
|
|
|
HashSet<Integer> allowedBlocks = new HashSet<Integer>();
|
|
|
|
for (String b : properties.getString("allowed-blocks",
|
|
|
|
WorldEditLibrary.getDefaultAllowedBlocks()).split(",")) {
|
2010-10-03 19:44:52 +02:00
|
|
|
try {
|
2010-11-04 00:46:47 +01:00
|
|
|
allowedBlocks.add(Integer.parseInt(b));
|
|
|
|
} catch (NumberFormatException e) {
|
2010-10-03 19:44:52 +02:00
|
|
|
}
|
2010-10-13 06:41:06 +02:00
|
|
|
}
|
2010-11-04 00:46:47 +01:00
|
|
|
worldEdit.setAllowedBlocks(allowedBlocks);
|
|
|
|
|
|
|
|
worldEdit.setDefaultChangeLimit(
|
|
|
|
Math.max(-1, properties.getInt("max-blocks-changed", -1)));
|
2010-10-13 06:41:06 +02:00
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
String snapshotsDir = properties.getString("snapshots-dir", "");
|
|
|
|
if (!snapshotsDir.trim().equals("")) {
|
|
|
|
worldEdit.setSnapshotRepository(new SnapshotRepository(snapshotsDir));
|
2010-10-13 06:41:06 +02:00
|
|
|
}
|
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
String shellSaveType = properties.getString("shell-save-type", "").trim();
|
|
|
|
worldEdit.setShellSaveType(shellSaveType.equals("") ? null : shellSaveType);
|
2010-10-12 22:51:25 +02:00
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
for (Map.Entry<String,String> entry : worldEdit.getCommands().entrySet()) {
|
|
|
|
etc.getInstance().addCommand(entry.getKey(), entry.getValue());
|
2010-10-12 22:51:25 +02:00
|
|
|
}
|
2010-10-21 01:15:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-04 00:46:47 +01:00
|
|
|
* Disables the plugin.
|
2010-10-21 01:15:20 +02:00
|
|
|
*/
|
2010-11-04 00:46:47 +01:00
|
|
|
@Override
|
|
|
|
public void disable() {
|
|
|
|
for (String key : worldEdit.getCommands().keySet()) {
|
|
|
|
etc.getInstance().removeCommand(key);
|
|
|
|
}
|
2010-10-28 19:27:30 +02:00
|
|
|
|
2010-11-04 00:46:47 +01:00
|
|
|
worldEdit.clearSessions();
|
2010-10-28 19:27:30 +02:00
|
|
|
}
|
2010-11-04 01:05:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the WorldEdit version.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private String getWorldEditVersion() {
|
|
|
|
try {
|
|
|
|
String classContainer = WorldEdit.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("WorldEdit-Version");
|
|
|
|
return ver != null ? ver : "(unavailable)";
|
|
|
|
} catch (IOException e) {
|
|
|
|
return "(unknown)";
|
|
|
|
}
|
|
|
|
}
|
2010-09-28 10:12:34 +02:00
|
|
|
}
|