mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Updated WE for the new Minecraft update.
This commit is contained in:
parent
4b8b77a6d5
commit
bb0aa3cb91
88
src/MinecraftServerInterface.java
Normal file
88
src/MinecraftServerInterface.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* 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.Random;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import sun.reflect.ReflectionFactory;
|
||||||
|
import com.sk89q.worldedit.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class MinecraftServerInterface {
|
||||||
|
/**
|
||||||
|
* Logger.
|
||||||
|
*/
|
||||||
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
|
/**
|
||||||
|
* Random generator.
|
||||||
|
*/
|
||||||
|
private static Random random = new Random();
|
||||||
|
/**
|
||||||
|
* Proxy for the tree generator.
|
||||||
|
*/
|
||||||
|
private static MinecraftSetBlockProxy proxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a tree at a location.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean generateTree(EditSession editSession, Vector pt) {
|
||||||
|
if (proxy == null) {
|
||||||
|
try {
|
||||||
|
proxy = createNoConstructor(MinecraftSetBlockProxy.class);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.log(Level.WARNING, "setBlock() proxy class failed to construct",
|
||||||
|
t);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proxy.setEditSession(editSession);
|
||||||
|
|
||||||
|
bj treeGen = new hd();
|
||||||
|
return treeGen.a(proxy, random,
|
||||||
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a class without calling its constructor.
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* @param clazz
|
||||||
|
* @return
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
private static <T> T createNoConstructor(Class<T> clazz) throws Throwable {
|
||||||
|
try {
|
||||||
|
ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
|
||||||
|
Constructor objectConstructor = Object.class.getDeclaredConstructor();
|
||||||
|
Constructor c = factory.newConstructorForSerialization(
|
||||||
|
clazz, objectConstructor
|
||||||
|
);
|
||||||
|
return clazz.cast(c.newInstance());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class MinecraftSetBlockProxy extends eo {
|
public class MinecraftSetBlockProxy extends ep {
|
||||||
/**
|
/**
|
||||||
* Edit session.
|
* Edit session.
|
||||||
*/
|
*/
|
||||||
|
@ -20,12 +20,9 @@
|
|||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.lang.reflect.*;
|
|
||||||
import sun.reflect.ReflectionFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -40,10 +37,6 @@ public class ServerInterface {
|
|||||||
* Random generator.
|
* Random generator.
|
||||||
*/
|
*/
|
||||||
private static Random random = new Random();
|
private static Random random = new Random();
|
||||||
/**
|
|
||||||
* Proxy for the tree generator.
|
|
||||||
*/
|
|
||||||
private static MinecraftSetBlockProxy proxy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set block type.
|
* Set block type.
|
||||||
@ -258,21 +251,14 @@ public class ServerInterface {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean generateTree(EditSession editSession, Vector pt) {
|
public static boolean generateTree(EditSession editSession, Vector pt) {
|
||||||
if (proxy == null) {
|
|
||||||
try {
|
try {
|
||||||
proxy = createNoConstructor(MinecraftSetBlockProxy.class);
|
return MinecraftServerInterface.generateTree(editSession, pt);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.log(Level.WARNING, "setBlock() proxy class failed to construct",
|
logger.severe("Failed to create tree (do you need to update WorldEdit due to a Minecraft update?): "
|
||||||
t);
|
+ t.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxy.setEditSession(editSession);
|
|
||||||
|
|
||||||
bj treeGen = new hc();
|
|
||||||
return treeGen.a(proxy, random,
|
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop an item.
|
* Drop an item.
|
||||||
@ -361,25 +347,4 @@ public class ServerInterface {
|
|||||||
dropItem(pt, type);
|
dropItem(pt, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate a class without calling its constructor.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @param clazz
|
|
||||||
* @return
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
private static <T> T createNoConstructor(Class<T> clazz) throws Throwable {
|
|
||||||
try {
|
|
||||||
ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
|
|
||||||
Constructor objectConstructor = Object.class.getDeclaredConstructor();
|
|
||||||
Constructor c = factory.newConstructorForSerialization(
|
|
||||||
clazz, objectConstructor
|
|
||||||
);
|
|
||||||
return clazz.cast(c.newInstance());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user