mirror of
https://github.com/encounter/dynmap.git
synced 2026-03-30 11:08:39 -07:00
Compare commits
144 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 278fa36f94 | |||
| 1a2f63bcfb | |||
| 344d9bf1c9 | |||
| 70b27b8034 | |||
| abe7fc8405 | |||
| 4fa62993f4 | |||
| 08a920694b | |||
| 4bdb331eb0 | |||
| cb7c9061e8 | |||
| 29cb155534 | |||
| ada85ed960 | |||
| bfb12aa0f3 | |||
| 3342977a92 | |||
| 07cbd84d44 | |||
| da5e2cf24a | |||
| c6d345d8f1 | |||
| 3a57261120 | |||
| a39f99cab8 | |||
| f0885abea2 | |||
| 2b17cb215b | |||
| 68f0c17f70 | |||
| a20e55beab | |||
| 413542fe61 | |||
| a250732d31 | |||
| 07f2496f2f | |||
| 2f6e52261c | |||
| a117987840 | |||
| cbb8cc061e | |||
| c03365d574 | |||
| 827f18b8e0 | |||
| 1603015631 | |||
| c2d97ba3d5 | |||
| 418b175923 | |||
| fdc14b413d | |||
| e6d509c3e6 | |||
| b10ec3a331 | |||
| 9f8617d81d | |||
| 265e037b74 | |||
| f50e73180c | |||
| aad4b64603 | |||
| aeeb09f600 | |||
| e73e88281c | |||
| fde3d14abd | |||
| 6cf60b3d53 | |||
| 9e29cb8e44 | |||
| fca05e399a | |||
| a6490743ca | |||
| 7da1051d5f | |||
| ddf14b7c3b | |||
| 38a4d869f6 | |||
| 905802e558 | |||
| 30db9c04b6 | |||
| 2401eff676 | |||
| b5700bd462 | |||
| 5d9677b350 | |||
| cf77737f85 | |||
| 8a03a29f0a | |||
| 8031110a59 | |||
| cf0c60d877 | |||
| 0a4761f525 | |||
| ab46d250b1 | |||
| df8013489d | |||
| 133d3078d7 | |||
| 2a056033b8 | |||
| a5428b56f1 | |||
| ff79c2f4fc | |||
| 18462b5caf | |||
| ebfa3eaec1 | |||
| 96673f0fb3 | |||
| fc451fd002 | |||
| 2f1b1789fd | |||
| 01b054e972 | |||
| 5d35205cae | |||
| 58c7d6378c | |||
| d95213e7dd | |||
| 4f5063155e | |||
| 2d4e233005 | |||
| afc0d9bd6b | |||
| 267b423ff1 | |||
| d523ce8a41 | |||
| ee7e6eedc8 | |||
| 4d6d156e9c | |||
| 177310a949 | |||
| 0707953718 | |||
| 8546b2205e | |||
| d154f23bab | |||
| 0b38a4cec8 | |||
| 02aedc9478 | |||
| 3702e07210 | |||
| 6afb0d9b92 | |||
| 1d6cedeeb0 | |||
| a3528e9937 | |||
| bae2a48a83 | |||
| 11b2123f14 | |||
| f93f37deea | |||
| cf5e2e00e6 | |||
| 121c1050ce | |||
| 4f6dd1d778 | |||
| 3ed44ee905 | |||
| 8f9d2c01c2 | |||
| faa1948225 | |||
| 67e0bd2f2c | |||
| 4fc8a53eb0 | |||
| 1c1937c80c | |||
| f24dfd6c3e | |||
| 86b87e78e3 | |||
| 34fe8316c3 | |||
| 387844b9dc | |||
| a493f85bcf | |||
| 1ab7a8ddbf | |||
| bdb2620ca9 | |||
| d8812ce575 | |||
| 6c618fa727 | |||
| a9214502cf | |||
| ef0ad40496 | |||
| 2628559b55 | |||
| 11021720c7 | |||
| de4fdb2b0c | |||
| ecdb50920e | |||
| 50f7382b7a | |||
| 56875a05d4 | |||
| f392eb1344 | |||
| a41e052f51 | |||
| 0e97fedd6b | |||
| 9d97f86b7f | |||
| 516125e87b | |||
| e52234336e | |||
| af10e942a9 | |||
| 1e52061b27 | |||
| b0ca796213 | |||
| cac8527d76 | |||
| 35cf3ed8fa | |||
| 888051d497 | |||
| 559bc0ef55 | |||
| b85bd1dce7 | |||
| 87bbd3023e | |||
| fa80af8e81 | |||
| 0c9057949d | |||
| f95a832cae | |||
| 2e2fbec8f9 | |||
| 63a638f96e | |||
| bcf679b078 | |||
| 5ad4ba285b | |||
| 71185b06d6 |
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -2,7 +2,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.dynmap</groupId>
|
||||
<artifactId>dynmap</artifactId>
|
||||
<version>0.32</version>
|
||||
<name>dynmap</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -120,22 +119,28 @@
|
||||
</releases>
|
||||
<snapshots>
|
||||
</snapshots>
|
||||
<id>spout-repo</id>
|
||||
<url>http://repo.spout.org</url>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<releases>
|
||||
</releases>
|
||||
<snapshots>
|
||||
</snapshots>
|
||||
<id>dynmap-repo</id>
|
||||
<url>http://repo.mikeprimm.com/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nijikokun.bukkit</groupId>
|
||||
<artifactId>Permissions</artifactId>
|
||||
<version>[2.5.4,)</version>
|
||||
<version>3.1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>[1.1-R1-SNAPSHOT,)</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<version>1.3.2-R3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
@@ -144,21 +149,6 @@
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>8.0.1.v20110908</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>8.0.1.v20110908</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
@@ -173,5 +163,21 @@
|
||||
<version>dev-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.tehkode</groupId>
|
||||
<artifactId>PermissionsEx</artifactId>
|
||||
<version>1.19.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.bananaco</groupId>
|
||||
<artifactId>bPermissions</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platymuus.bukkit.permissions</groupId>
|
||||
<artifactId>PermissionsBukkit</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<version>1.3</version>
|
||||
</project>
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
<includes>
|
||||
<include>version.js</include></includes>
|
||||
<filtered>true</filtered></fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory>/dynmap</outputDirectory>
|
||||
<includes>
|
||||
<include>LICENSE</include></includes></fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package org.dynmap.bukkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.dynmap.Log;
|
||||
|
||||
/**
|
||||
* Wrapper for accessing raw light levels for given block
|
||||
*/
|
||||
public class BlockLightLevel {
|
||||
private Method gethandle;
|
||||
private Method getrawlight;
|
||||
private Object enum_sky;
|
||||
private Object enum_block;
|
||||
private boolean ready;
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public BlockLightLevel() {
|
||||
/* Get CraftChunk.getChunkSnapshot(boolean,boolean,boolean) and CraftChunk.getHandle() */
|
||||
try {
|
||||
Class c = Class.forName("org.bukkit.craftbukkit.CraftChunk");
|
||||
gethandle = c.getDeclaredMethod("getHandle", new Class[0]);
|
||||
Class enumskyblock = Class.forName("net.minecraft.server.EnumSkyBlock");
|
||||
Object[] enumvals = enumskyblock.getEnumConstants();
|
||||
for(int i = 0; i < enumvals.length; i++) {
|
||||
String ev = enumvals[i].toString();
|
||||
if(ev.equals("Sky")) {
|
||||
enum_sky = enumvals[i];
|
||||
}
|
||||
else if(ev.equals("Block")) {
|
||||
enum_block = enumvals[i];
|
||||
}
|
||||
}
|
||||
Class cc = Class.forName("net.minecraft.server.Chunk");
|
||||
getrawlight = cc.getDeclaredMethod("a", new Class[] { enumskyblock, int.class, int.class, int.class });
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
}
|
||||
if((gethandle != null) && (enum_sky != null) && (enum_block != null) && (getrawlight != null)) {
|
||||
ready = true;
|
||||
}
|
||||
else {
|
||||
Log.warning("Block raw light level API not available");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
public int getSkyLightLevel(Block b) {
|
||||
try {
|
||||
Object hand = gethandle.invoke(b.getChunk());
|
||||
if(hand != null) {
|
||||
Integer v = (Integer)getrawlight.invoke(hand, enum_sky, b.getX() & 0xF, b.getY() & 0x7F, b.getZ() & 0xF);
|
||||
return v;
|
||||
}
|
||||
} catch (InvocationTargetException itx) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getBlockLightLevel(Block b) {
|
||||
try {
|
||||
Object hand = gethandle.invoke(b.getChunk());
|
||||
if(hand != null) {
|
||||
Integer v = (Integer)getrawlight.invoke(hand, enum_block, b.getX() & 0xF, b.getY() & 0x7F, b.getZ() & 0xF);
|
||||
return v;
|
||||
}
|
||||
} catch (InvocationTargetException itx) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
package org.dynmap.bukkit;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.Log;
|
||||
|
||||
/**
|
||||
* Helper for isolation of bukkit version specific issues
|
||||
*/
|
||||
public class BukkitVersionHelper {
|
||||
private String obc_package; // Package used for org.bukkit.craftbukkit
|
||||
private String nms_package; // Package used for net.minecraft.server
|
||||
private static BukkitVersionHelper helper;
|
||||
private boolean failed;
|
||||
private static final Object[] nullargs = new Object[0];
|
||||
private static final Map nullmap = Collections.emptyMap();
|
||||
/** BiomeBase related helpers */
|
||||
private Class<?> biomebase;
|
||||
private Class<?> biomebasearray;
|
||||
private Field biomebaselist;
|
||||
private Field biomebasetemp;
|
||||
private Field biomebasehumi;
|
||||
private Field biomebaseidstring;
|
||||
private Field biomebaseid;
|
||||
/** CraftWorld */
|
||||
private Class<?> craftworld;
|
||||
private Method cw_gethandle;
|
||||
/** n.m.s.World */
|
||||
private Class<?> nmsworld;
|
||||
private Class<?> chunkprovserver;
|
||||
private Class<?> longhashset;
|
||||
private Field nmsw_chunkproviderserver;
|
||||
private Field cps_unloadqueue;
|
||||
private Method lhs_containskey;
|
||||
/** CraftChunkSnapshot */
|
||||
private Class<?> craftchunksnapshot;
|
||||
private Field ccss_biome;
|
||||
/** CraftChunk */
|
||||
private Class<?> craftchunk;
|
||||
private Method cc_gethandle;
|
||||
/** o.m.s.Chunk */
|
||||
private Class<?> nmschunk;
|
||||
private Method nmsc_removeentities;
|
||||
private Field nmsc_tileentities;
|
||||
/** nbt classes */
|
||||
private Class<?> nbttagcompound;
|
||||
private Class<?> nbttagbyte;
|
||||
private Class<?> nbttagshort;
|
||||
private Class<?> nbttagint;
|
||||
private Class<?> nbttaglong;
|
||||
private Class<?> nbttagfloat;
|
||||
private Class<?> nbttagdouble;
|
||||
private Class<?> nbttagbytearray;
|
||||
private Class<?> nbttagstring;
|
||||
private Class<?> nbttagintarray;
|
||||
private Method compound_get;
|
||||
private Field nbttagbyte_val;
|
||||
private Field nbttagshort_val;
|
||||
private Field nbttagint_val;
|
||||
private Field nbttaglong_val;
|
||||
private Field nbttagfloat_val;
|
||||
private Field nbttagdouble_val;
|
||||
private Field nbttagbytearray_val;
|
||||
private Field nbttagstring_val;
|
||||
private Field nbttagintarray_val;
|
||||
|
||||
/** Tile entity */
|
||||
private Class<?> nms_tileentity;
|
||||
private Method nmst_readnbt;
|
||||
private Field nmst_x;
|
||||
private Field nmst_y;
|
||||
private Field nmst_z;
|
||||
|
||||
public static final BukkitVersionHelper getHelper() {
|
||||
if(helper == null) {
|
||||
helper = new BukkitVersionHelper();
|
||||
}
|
||||
return helper;
|
||||
}
|
||||
|
||||
private BukkitVersionHelper() {
|
||||
failed = false;
|
||||
Server srv = Bukkit.getServer();
|
||||
/* Look up base classname for bukkit server - tells us OBC package */
|
||||
obc_package = Bukkit.getServer().getClass().getPackage().getName();
|
||||
/* Get getHandle() method */
|
||||
try {
|
||||
Method m = srv.getClass().getMethod("getHandle");
|
||||
Object scm = m.invoke(srv); /* And use it to get SCM (nms object) */
|
||||
nms_package = scm.getClass().getPackage().getName();
|
||||
} catch (Exception x) {
|
||||
Log.severe("Error finding net.minecraft.server packages");
|
||||
nms_package = "net.minecraft.server" + obc_package.substring("org.bukkit.craftbukkit".length());
|
||||
failed = true;
|
||||
}
|
||||
|
||||
/* Set up biomebase fields */
|
||||
biomebase = getNMSClass("net.minecraft.server.BiomeBase");
|
||||
biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;");
|
||||
biomebaselist = getField(biomebase, new String[] { "biomes" }, biomebasearray);
|
||||
biomebasetemp = getField(biomebase, new String[] { "temperature", "F" }, float.class);
|
||||
biomebasehumi = getField(biomebase, new String[] { "humidity", "G" }, float.class);
|
||||
biomebaseidstring = getField(biomebase, new String[] { "y" }, String.class);
|
||||
biomebaseid = getField(biomebase, new String[] { "id" }, int.class);
|
||||
/* Craftworld fields */
|
||||
craftworld = getOBCClass("org.bukkit.craftbukkit.CraftWorld");
|
||||
cw_gethandle = getMethod(craftworld, new String[] { "getHandle" }, new Class[0]);
|
||||
/* n.m.s.World */
|
||||
nmsworld = getNMSClass("net.minecraft.server.WorldServer");
|
||||
chunkprovserver = getNMSClass("net.minecraft.server.ChunkProviderServer");
|
||||
longhashset = getOBCClassNoFail("org.bukkit.craftbukkit.util.LongHashSet");
|
||||
if(longhashset != null) {
|
||||
lhs_containskey = getMethod(longhashset, new String[] { "contains" }, new Class[] { int.class, int.class });
|
||||
}
|
||||
else {
|
||||
longhashset = getOBCClass("org.bukkit.craftbukkit.util.LongHashset");
|
||||
lhs_containskey = getMethod(longhashset, new String[] { "containsKey" }, new Class[] { int.class, int.class });
|
||||
}
|
||||
nmsw_chunkproviderserver = getField(nmsworld, new String[] { "chunkProviderServer" }, chunkprovserver);
|
||||
cps_unloadqueue = getFieldNoFail(chunkprovserver, new String[] { "unloadQueue" }, longhashset);
|
||||
if(cps_unloadqueue == null) {
|
||||
Log.info("Unload queue not found - default to unload all chunks");
|
||||
}
|
||||
/* CraftChunkSnapshot */
|
||||
craftchunksnapshot = getOBCClass("org.bukkit.craftbukkit.CraftChunkSnapshot");
|
||||
ccss_biome = getPrivateField(craftchunksnapshot, new String[] { "biome" }, biomebasearray);
|
||||
/** CraftChunk */
|
||||
craftchunk = getOBCClass("org.bukkit.craftbukkit.CraftChunk");
|
||||
cc_gethandle = getMethod(craftchunk, new String[] { "getHandle" }, new Class[0]);
|
||||
/** n.m.s.Chunk */
|
||||
nmschunk = getNMSClass("net.minecraft.server.Chunk");
|
||||
nmsc_removeentities = getMethod(nmschunk, new String[] { "removeEntities" }, new Class[0]);
|
||||
nmsc_tileentities = getField(nmschunk, new String[] { "tileEntities" }, Map.class);
|
||||
/** nbt classes */
|
||||
nbttagcompound = getNMSClass("net.minecraft.server.NBTTagCompound");
|
||||
nbttagbyte = getNMSClass("net.minecraft.server.NBTTagByte");
|
||||
nbttagshort = getNMSClass("net.minecraft.server.NBTTagShort");
|
||||
nbttagint = getNMSClass("net.minecraft.server.NBTTagInt");
|
||||
nbttaglong = getNMSClass("net.minecraft.server.NBTTagLong");
|
||||
nbttagfloat = getNMSClass("net.minecraft.server.NBTTagFloat");
|
||||
nbttagdouble = getNMSClass("net.minecraft.server.NBTTagDouble");
|
||||
nbttagbytearray = getNMSClass("net.minecraft.server.NBTTagByteArray");
|
||||
nbttagstring = getNMSClass("net.minecraft.server.NBTTagString");
|
||||
nbttagintarray = getNMSClass("net.minecraft.server.NBTTagIntArray");
|
||||
compound_get = getMethod(nbttagcompound, new String[] { "get" }, new Class[] { String.class });
|
||||
nbttagbyte_val = getField(nbttagbyte, new String[] { "data" }, byte.class);
|
||||
nbttagshort_val = getField(nbttagshort, new String[] { "data" }, short.class);
|
||||
nbttagint_val = getField(nbttagint, new String[] { "data" }, int.class);
|
||||
nbttaglong_val = getField(nbttaglong, new String[] { "data" }, long.class);
|
||||
nbttagfloat_val = getField(nbttagfloat, new String[] { "data" }, float.class);
|
||||
nbttagdouble_val = getField(nbttagdouble, new String[] { "data" }, double.class);
|
||||
nbttagbytearray_val = getField(nbttagbytearray, new String[] { "data" }, byte[].class);
|
||||
nbttagstring_val = getField(nbttagstring, new String[] { "data" }, String.class);
|
||||
nbttagintarray_val = getField(nbttagintarray, new String[] { "data" }, int[].class);
|
||||
|
||||
/** Tile entity */
|
||||
nms_tileentity = getNMSClass("net.minecraft.server.TileEntity");
|
||||
nmst_readnbt = getMethod(nms_tileentity, new String[] { "b" }, new Class[] { nbttagcompound });
|
||||
nmst_x = getField(nms_tileentity, new String[] { "x" }, int.class);
|
||||
nmst_y = getField(nms_tileentity, new String[] { "y" }, int.class);
|
||||
nmst_z = getField(nms_tileentity, new String[] { "z" }, int.class);
|
||||
|
||||
if(failed)
|
||||
throw new IllegalArgumentException("Error initializing dynmap - bukkit version incompatible!");
|
||||
}
|
||||
|
||||
public Class<?> getOBCClass(String classname) {
|
||||
return getClassByName(classname, "org.bukkit.craftbukkit", obc_package, false);
|
||||
}
|
||||
|
||||
public Class<?> getOBCClassNoFail(String classname) {
|
||||
return getClassByName(classname, "org.bukkit.craftbukkit", obc_package, true);
|
||||
}
|
||||
|
||||
public Class<?> getNMSClass(String classname) {
|
||||
return getClassByName(classname, "net.minecraft.server", nms_package, false);
|
||||
}
|
||||
|
||||
public Class<?> getClassByName(String classname, String base, String mapping, boolean nofail) {
|
||||
String n = classname;
|
||||
int idx = classname.indexOf(base);
|
||||
if(idx >= 0) {
|
||||
n = classname.substring(0, idx) + mapping + classname.substring(idx + base.length());
|
||||
}
|
||||
try {
|
||||
return Class.forName(n);
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
try {
|
||||
return Class.forName(classname);
|
||||
} catch (ClassNotFoundException cnfx2) {
|
||||
if(!nofail) {
|
||||
Log.severe("Cannot find " + classname);
|
||||
failed = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get field
|
||||
*/
|
||||
private Field getField(Class<?> cls, String[] ids, Class<?> type) {
|
||||
return getField(cls, ids, type, false);
|
||||
}
|
||||
private Field getFieldNoFail(Class<?> cls, String[] ids, Class<?> type) {
|
||||
return getField(cls, ids, type, true);
|
||||
}
|
||||
/**
|
||||
* Get field
|
||||
*/
|
||||
private Field getField(Class<?> cls, String[] ids, Class<?> type, boolean nofail) {
|
||||
if((cls == null) || (type == null)) return null;
|
||||
for(String id : ids) {
|
||||
try {
|
||||
Field f = cls.getField(id);
|
||||
if(f.getType().isAssignableFrom(type)) {
|
||||
return f;
|
||||
}
|
||||
} catch (NoSuchFieldException nsfx) {
|
||||
}
|
||||
}
|
||||
if(!nofail) {
|
||||
Log.severe("Unable to find field " + ids[0] + " for " + cls.getName());
|
||||
failed = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get private field
|
||||
*/
|
||||
private Field getPrivateField(Class<?> cls, String[] ids, Class<?> type) {
|
||||
if((cls == null) || (type == null)) return null;
|
||||
for(String id : ids) {
|
||||
try {
|
||||
Field f = cls.getDeclaredField(id);
|
||||
if(f.getType().isAssignableFrom(type)) {
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
}
|
||||
} catch (NoSuchFieldException nsfx) {
|
||||
}
|
||||
}
|
||||
Log.severe("Unable to find field " + ids[0] + " for " + cls.getName());
|
||||
failed = true;
|
||||
return null;
|
||||
}
|
||||
private Object getFieldValue(Object obj, Field field, Object def) {
|
||||
if((obj != null) && (field != null)) {
|
||||
try {
|
||||
return field.get(obj);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
/**
|
||||
* Get method
|
||||
*/
|
||||
private Method getMethod(Class<?> cls, String[] ids, Class[] args) {
|
||||
if(cls == null) return null;
|
||||
for(String id : ids) {
|
||||
try {
|
||||
return cls.getMethod(id, args);
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
}
|
||||
}
|
||||
Log.severe("Unable to find method " + ids[0] + " for " + cls.getName());
|
||||
failed = true;
|
||||
return null;
|
||||
}
|
||||
private Object callMethod(Object obj, Method meth, Object[] args, Object def) {
|
||||
if((obj == null) || (meth == null)) {
|
||||
return def;
|
||||
}
|
||||
try {
|
||||
return meth.invoke(obj, args);
|
||||
} catch (IllegalArgumentException iax) {
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of defined biomebase objects
|
||||
*/
|
||||
public Object[] getBiomeBaseList() {
|
||||
return (Object[]) getFieldValue(biomebase, biomebaselist, new Object[0]);
|
||||
}
|
||||
/** Get temperature from biomebase */
|
||||
public float getBiomeBaseTemperature(Object bb) {
|
||||
return (Float) getFieldValue(bb, biomebasetemp, 0.5F);
|
||||
}
|
||||
/** Get humidity from biomebase */
|
||||
public float getBiomeBaseHumidity(Object bb) {
|
||||
return (Float) getFieldValue(bb, biomebasehumi, 0.5F);
|
||||
}
|
||||
/** Get ID string from biomebase */
|
||||
public String getBiomeBaseIDString(Object bb) {
|
||||
return (String) getFieldValue(bb, biomebaseidstring, null);
|
||||
}
|
||||
/** Get ID from biomebase */
|
||||
public int getBiomeBaseID(Object bb) {
|
||||
return (Integer) getFieldValue(bb, biomebaseid, -1);
|
||||
}
|
||||
|
||||
/* Get net.minecraft.server.world for given world */
|
||||
public Object getNMSWorld(World w) {
|
||||
return callMethod(w, cw_gethandle, nullargs, null);
|
||||
}
|
||||
|
||||
/* Get unload queue for given NMS world */
|
||||
public Object getUnloadQueue(Object nmsworld) {
|
||||
Object cps = getFieldValue(nmsworld, nmsw_chunkproviderserver, null); // Get chunkproviderserver
|
||||
if(cps != null) {
|
||||
return getFieldValue(cps, cps_unloadqueue, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* For testing unload queue for presence of givne chunk */
|
||||
public boolean isInUnloadQueue(Object unloadqueue, int x, int z) {
|
||||
if(unloadqueue != null) {
|
||||
return (Boolean)callMethod(unloadqueue, lhs_containskey, new Object[] { x, z }, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object[] getBiomeBaseFromSnapshot(ChunkSnapshot css) {
|
||||
return (Object[])getFieldValue(css, ccss_biome, null);
|
||||
}
|
||||
public boolean isCraftChunkSnapshot(ChunkSnapshot css) {
|
||||
if(craftchunksnapshot != null) {
|
||||
return craftchunksnapshot.isAssignableFrom(css.getClass());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** Remove entities from given chunk */
|
||||
public void removeEntitiesFromChunk(Chunk c) {
|
||||
Object omsc = callMethod(c, cc_gethandle, nullargs, null);
|
||||
if(omsc != null) {
|
||||
callMethod(omsc, nmsc_removeentities, nullargs, null);
|
||||
}
|
||||
}
|
||||
/** Get tile entities map from chunk */
|
||||
public Map getTileEntitiesForChunk(Chunk c) {
|
||||
Object omsc = callMethod(c, cc_gethandle, nullargs, null);
|
||||
if(omsc != null) {
|
||||
return (Map)getFieldValue(omsc, nmsc_tileentities, nullmap);
|
||||
}
|
||||
return nullmap;
|
||||
}
|
||||
/**
|
||||
* Get X coordinate of tile entity
|
||||
*/
|
||||
public int getTileEntityX(Object te) {
|
||||
return (Integer)getFieldValue(te, nmst_x, 0);
|
||||
}
|
||||
/**
|
||||
* Get Y coordinate of tile entity
|
||||
*/
|
||||
public int getTileEntityY(Object te) {
|
||||
return (Integer)getFieldValue(te, nmst_y, 0);
|
||||
}
|
||||
/**
|
||||
* Get Z coordinate of tile entity
|
||||
*/
|
||||
public int getTileEntityZ(Object te) {
|
||||
return (Integer)getFieldValue(te, nmst_z, 0);
|
||||
}
|
||||
/**
|
||||
* Read tile entity NBT
|
||||
*/
|
||||
public Object readTileEntityNBT(Object te) {
|
||||
if(nbttagcompound == null) return null;
|
||||
Object nbt = null;
|
||||
try {
|
||||
nbt = nbttagcompound.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
if(nbt != null) {
|
||||
callMethod(te, nmst_readnbt, new Object[] { nbt }, null);
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
/**
|
||||
* Get field value from NBT compound
|
||||
*/
|
||||
public Object getFieldValue(Object nbt, String field) {
|
||||
Object val = callMethod(nbt, compound_get, new Object[] { field }, null);
|
||||
if(val == null) return null;
|
||||
Class<?> valcls = val.getClass();
|
||||
if(valcls.equals(nbttagbyte)) {
|
||||
return getFieldValue(val, nbttagbyte_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagshort)) {
|
||||
return getFieldValue(val, nbttagshort_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagint)) {
|
||||
return getFieldValue(val, nbttagint_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttaglong)) {
|
||||
return getFieldValue(val, nbttaglong_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagfloat)) {
|
||||
return getFieldValue(val, nbttagfloat_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagdouble)) {
|
||||
return getFieldValue(val, nbttagdouble_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagbytearray)) {
|
||||
return getFieldValue(val, nbttagbytearray_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagstring)) {
|
||||
return getFieldValue(val, nbttagstring_val, null);
|
||||
}
|
||||
else if(valcls.equals(nbttagintarray)) {
|
||||
return getFieldValue(val, nbttagintarray_val, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.dynmap.DynmapChunk;
|
||||
import org.dynmap.DynmapLocation;
|
||||
import org.dynmap.DynmapWorld;
|
||||
@@ -13,41 +15,85 @@ import org.dynmap.utils.MapChunkCache;
|
||||
|
||||
public class BukkitWorld extends DynmapWorld {
|
||||
private World world;
|
||||
private static BlockLightLevel bll = new BlockLightLevel();
|
||||
private World.Environment env;
|
||||
private boolean skylight;
|
||||
private DynmapLocation spawnloc = new DynmapLocation();
|
||||
|
||||
public BukkitWorld(World w) {
|
||||
super(w.getName(), w.getMaxHeight());
|
||||
|
||||
this(w.getName(), w.getMaxHeight(), w.getSeaLevel(), w.getEnvironment());
|
||||
setWorldLoaded(w);
|
||||
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
|
||||
}
|
||||
public BukkitWorld(String name, int height, int sealevel, World.Environment env) {
|
||||
super(name, height, sealevel);
|
||||
world = null;
|
||||
this.env = env;
|
||||
skylight = (env == World.Environment.NORMAL);
|
||||
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
|
||||
}
|
||||
/**
|
||||
* Set world online
|
||||
* @param w - loaded world
|
||||
*/
|
||||
public void setWorldLoaded(World w) {
|
||||
world = w;
|
||||
env = world.getEnvironment();
|
||||
skylight = (env == World.Environment.NORMAL);
|
||||
}
|
||||
/**
|
||||
* Set world unloaded
|
||||
*/
|
||||
@Override
|
||||
public void setWorldUnloaded() {
|
||||
getSpawnLocation(); /* Remember spawn location before unload */
|
||||
world = null;
|
||||
}
|
||||
/* Test if world is nether */
|
||||
@Override
|
||||
public boolean isNether() {
|
||||
return world.getEnvironment() == World.Environment.NETHER;
|
||||
return env == World.Environment.NETHER;
|
||||
}
|
||||
/* Get world spawn location */
|
||||
@Override
|
||||
public DynmapLocation getSpawnLocation() {
|
||||
DynmapLocation dloc = new DynmapLocation();
|
||||
Location sloc = world.getSpawnLocation();
|
||||
dloc.x = sloc.getBlockX(); dloc.y = sloc.getBlockY();
|
||||
dloc.z = sloc.getBlockZ(); dloc.world = sloc.getWorld().getName();
|
||||
return dloc;
|
||||
if(world != null) {
|
||||
Location sloc = world.getSpawnLocation();
|
||||
spawnloc.x = sloc.getBlockX();
|
||||
spawnloc.y = sloc.getBlockY();
|
||||
spawnloc.z = sloc.getBlockZ();
|
||||
spawnloc.world = normalizeWorldName(sloc.getWorld().getName());
|
||||
}
|
||||
return spawnloc;
|
||||
}
|
||||
/* Get world time */
|
||||
@Override
|
||||
public long getTime() {
|
||||
return world.getTime();
|
||||
if(world != null) {
|
||||
return world.getTime();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* World is storming */
|
||||
@Override
|
||||
public boolean hasStorm() {
|
||||
return world.hasStorm();
|
||||
if(world != null) {
|
||||
return world.hasStorm();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* World is thundering */
|
||||
@Override
|
||||
public boolean isThundering() {
|
||||
return world.isThundering();
|
||||
if(world != null) {
|
||||
return world.isThundering();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* World is loaded */
|
||||
@Override
|
||||
@@ -57,38 +103,58 @@ public class BukkitWorld extends DynmapWorld {
|
||||
/* Get light level of block */
|
||||
@Override
|
||||
public int getLightLevel(int x, int y, int z) {
|
||||
return world.getBlockAt(x, y, z).getLightLevel();
|
||||
if(world != null) {
|
||||
return world.getBlockAt(x, y, z).getLightLevel();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* Get highest Y coord of given location */
|
||||
@Override
|
||||
public int getHighestBlockYAt(int x, int z) {
|
||||
return world.getHighestBlockYAt(x, z);
|
||||
if(world != null) {
|
||||
return world.getHighestBlockYAt(x, z);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* Test if sky light level is requestable */
|
||||
@Override
|
||||
public boolean canGetSkyLightLevel() {
|
||||
return bll.isReady();
|
||||
return skylight && (world != null);
|
||||
}
|
||||
/* Return sky light level */
|
||||
@Override
|
||||
public int getSkyLightLevel(int x, int y, int z) {
|
||||
return bll.getSkyLightLevel(world.getBlockAt(x, y, z));
|
||||
if(world != null) {
|
||||
return world.getBlockAt(x, y, z).getLightFromSky();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get world environment ID (lower case - normal, the_end, nether)
|
||||
*/
|
||||
@Override
|
||||
public String getEnvironment() {
|
||||
return world.getEnvironment().name().toLowerCase();
|
||||
return env.name().toLowerCase();
|
||||
}
|
||||
/**
|
||||
* Get map chunk cache for world
|
||||
*/
|
||||
@Override
|
||||
public MapChunkCache getChunkCache(List<DynmapChunk> chunks) {
|
||||
NewMapChunkCache c = new NewMapChunkCache();
|
||||
c.setChunks(this, chunks);
|
||||
return c;
|
||||
if(isLoaded()) {
|
||||
NewMapChunkCache c = new NewMapChunkCache();
|
||||
c.setChunks(this, chunks);
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -8,15 +8,21 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.dynmap.utils.DynIntHashMap;
|
||||
|
||||
public class SnapshotCache {
|
||||
public static class SnapshotRec {
|
||||
public ChunkSnapshot ss;
|
||||
public DynIntHashMap tileData;
|
||||
};
|
||||
|
||||
private CacheHashMap snapcache;
|
||||
private ReferenceQueue<ChunkSnapshot> refqueue;
|
||||
private ReferenceQueue<SnapshotRec> refqueue;
|
||||
private long cache_attempts;
|
||||
private long cache_success;
|
||||
|
||||
private static class CacheRec {
|
||||
WeakReference<ChunkSnapshot> ref;
|
||||
WeakReference<SnapshotRec> ref;
|
||||
boolean hasbiome;
|
||||
boolean hasrawbiome;
|
||||
boolean hasblockdata;
|
||||
@@ -26,12 +32,12 @@ public class SnapshotCache {
|
||||
@SuppressWarnings("serial")
|
||||
public class CacheHashMap extends LinkedHashMap<String, CacheRec> {
|
||||
private int limit;
|
||||
private IdentityHashMap<WeakReference<ChunkSnapshot>, String> reverselookup;
|
||||
private IdentityHashMap<WeakReference<SnapshotRec>, String> reverselookup;
|
||||
|
||||
public CacheHashMap(int lim) {
|
||||
super(16, (float)0.75, true);
|
||||
limit = lim;
|
||||
reverselookup = new IdentityHashMap<WeakReference<ChunkSnapshot>, String>();
|
||||
reverselookup = new IdentityHashMap<WeakReference<SnapshotRec>, String>();
|
||||
}
|
||||
protected boolean removeEldestEntry(Map.Entry<String, CacheRec> last) {
|
||||
boolean remove = (size() >= limit);
|
||||
@@ -47,7 +53,7 @@ public class SnapshotCache {
|
||||
*/
|
||||
public SnapshotCache(int max_size) {
|
||||
snapcache = new CacheHashMap(max_size);
|
||||
refqueue = new ReferenceQueue<ChunkSnapshot>();
|
||||
refqueue = new ReferenceQueue<SnapshotRec>();
|
||||
}
|
||||
private String getKey(String w, int cx, int cz) {
|
||||
return w + ":" + cx + ":" + cz;
|
||||
@@ -83,11 +89,11 @@ public class SnapshotCache {
|
||||
/**
|
||||
* Look for chunk snapshot in cache
|
||||
*/
|
||||
public ChunkSnapshot getSnapshot(String w, int chunkx, int chunkz,
|
||||
public SnapshotRec getSnapshot(String w, int chunkx, int chunkz,
|
||||
boolean blockdata, boolean biome, boolean biomeraw, boolean highesty) {
|
||||
String key = getKey(w, chunkx, chunkz);
|
||||
processRefQueue();
|
||||
ChunkSnapshot ss = null;
|
||||
SnapshotRec ss = null;
|
||||
CacheRec rec = snapcache.get(key);
|
||||
if(rec != null) {
|
||||
ss = rec.ref.get();
|
||||
@@ -112,7 +118,7 @@ public class SnapshotCache {
|
||||
/**
|
||||
* Add chunk snapshot to cache
|
||||
*/
|
||||
public void putSnapshot(String w, int chunkx, int chunkz, ChunkSnapshot ss,
|
||||
public void putSnapshot(String w, int chunkx, int chunkz, SnapshotRec ss,
|
||||
boolean blockdata, boolean biome, boolean biomeraw, boolean highesty) {
|
||||
String key = getKey(w, chunkx, chunkz);
|
||||
processRefQueue();
|
||||
@@ -121,7 +127,7 @@ public class SnapshotCache {
|
||||
rec.hasbiome = biome;
|
||||
rec.hasrawbiome = biomeraw;
|
||||
rec.hashighesty = highesty;
|
||||
rec.ref = new WeakReference<ChunkSnapshot>(ss, refqueue);
|
||||
rec.ref = new WeakReference<SnapshotRec>(ss, refqueue);
|
||||
CacheRec prevrec = snapcache.put(key, rec);
|
||||
if(prevrec != null) {
|
||||
snapcache.reverselookup.remove(prevrec.ref);
|
||||
@@ -132,7 +138,7 @@ public class SnapshotCache {
|
||||
* Process reference queue
|
||||
*/
|
||||
private void processRefQueue() {
|
||||
Reference<? extends ChunkSnapshot> ref;
|
||||
Reference<? extends SnapshotRec> ref;
|
||||
while((ref = refqueue.poll()) != null) {
|
||||
String k = snapcache.reverselookup.remove(ref);
|
||||
if(k != null) {
|
||||
|
||||
@@ -14,6 +14,9 @@ import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.Log;
|
||||
import org.getspout.spoutapi.block.design.BlockDesign;
|
||||
import org.getspout.spoutapi.block.design.GenericBlockDesign;
|
||||
@@ -31,7 +34,29 @@ import org.getspout.spoutapi.material.MaterialData;
|
||||
public class SpoutPluginBlocks {
|
||||
private Field textXPosField; /* float[][] textXPos */
|
||||
private Field textYPosField; /* float[][] textYPos */
|
||||
|
||||
private HashSet<String> plugins_pending = new HashSet<String>();
|
||||
|
||||
public SpoutPluginBlocks(Plugin plugin) {
|
||||
/* First, see if any spout plugins that need to be enabled */
|
||||
for(Plugin p : plugin.getServer().getPluginManager().getPlugins()) {
|
||||
List<String> dep = p.getDescription().getDepend();
|
||||
if((dep != null) && (dep.contains("Spout"))) {
|
||||
Log.info("Found Spout plugin: " + p.getName());
|
||||
if(p.isEnabled() == false) {
|
||||
plugins_pending.add(p.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return plugins_pending.isEmpty();
|
||||
}
|
||||
|
||||
public void markPluginEnabled(Plugin p) {
|
||||
plugins_pending.remove(p.getName());
|
||||
}
|
||||
|
||||
private boolean initSpoutAccess() {
|
||||
boolean success = false;
|
||||
try {
|
||||
@@ -53,13 +78,31 @@ public class SpoutPluginBlocks {
|
||||
sb.append("block:id=" + blk.getCustomId() + ",allfaces=12049,transparency=TRANSPARENT\n");
|
||||
}
|
||||
|
||||
private static String fixIDString(String id) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int len = id.length();
|
||||
sb.setLength(len);
|
||||
for(int i = 0; i < len; i++) {
|
||||
char c = id.charAt(i);
|
||||
if(Character.isJavaIdentifierStart(c)) {
|
||||
sb.setCharAt(i, c);
|
||||
}
|
||||
else {
|
||||
sb.setCharAt(i, '_');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/* Process spout blocks - return true if something changed */
|
||||
public boolean processSpoutBlocks(File datadir) {
|
||||
public boolean processSpoutBlocks(DynmapPlugin plugin, DynmapCore core) {
|
||||
File datadir = core.getDataFolder();
|
||||
if(textYPosField == null) {
|
||||
if(initSpoutAccess() == false)
|
||||
return false;
|
||||
}
|
||||
HashMap<String, String> texturelist = new HashMap<String, String>();
|
||||
boolean use_existing_texture = core.configuration.getBoolean("spout/use-existing-textures", true);
|
||||
|
||||
int cnt = 0;
|
||||
File f = new File(datadir, "texturepacks/standard/spout");
|
||||
@@ -72,7 +115,7 @@ public class SpoutPluginBlocks {
|
||||
/* Loop through blocks - try to freshen files, if needed */
|
||||
for(CustomBlock b : cb) {
|
||||
BlockDesign bd = b.getBlockDesign();
|
||||
String blkid = bd.getTexturePlugin() + "." + b.getName();
|
||||
String blkid = bd.getTexturePlugin() + "." + fixIDString(b.getName());
|
||||
/* If not GenericCubiodBlockDesign, we don't handle it */
|
||||
if((bd instanceof GenericCuboidBlockDesign) == false) {
|
||||
Log.info("Block " + blkid + " not suppored - only cubiod blocks");
|
||||
@@ -109,53 +152,59 @@ public class SpoutPluginBlocks {
|
||||
String txtid = texturelist.get(txname); /* Get texture */
|
||||
if(txtid == null) { /* Not found yet */
|
||||
File imgfile = new File(f, blkid + ".png");
|
||||
BufferedImage img = null;
|
||||
boolean urlloaded = false;
|
||||
try {
|
||||
URL url = new URL(txname);
|
||||
img = ImageIO.read(url); /* Load skin for player */
|
||||
urlloaded = true;
|
||||
} catch (IOException iox) {
|
||||
if(txname.startsWith("http") == false) { /* Not URL - try file */
|
||||
File tf = new File(txname);
|
||||
if(tf.exists() == false) {
|
||||
/* Horrible hack - try to find temp file (some SpoutMaterials versions) */
|
||||
try {
|
||||
File tmpf = File.createTempFile("dynmap", "test");
|
||||
|
||||
tf = new File(tmpf.getParent(), txname);
|
||||
tmpf.delete();
|
||||
} catch (IOException iox2) {}
|
||||
|
||||
/* If not reusing loaded textures OR not previously loaded */
|
||||
if((!use_existing_texture) || (!imgfile.exists())) {
|
||||
BufferedImage img = null;
|
||||
boolean urlloaded = false;
|
||||
try {
|
||||
URL url = new URL(txname);
|
||||
img = ImageIO.read(url); /* Load skin for player */
|
||||
urlloaded = true;
|
||||
} catch (IOException iox) {
|
||||
if(txname.startsWith("http") == false) { /* Not URL - try file */
|
||||
File tf = new File(txname);
|
||||
if(tf.exists() == false) {
|
||||
/* Horrible hack - try to find temp file (some SpoutMaterials versions) */
|
||||
try {
|
||||
File tmpf = File.createTempFile("dynmap", "test");
|
||||
|
||||
tf = new File(tmpf.getParent(), txname);
|
||||
tmpf.delete();
|
||||
} catch (IOException iox2) {}
|
||||
}
|
||||
if(tf.exists()) {
|
||||
try {
|
||||
img = ImageIO.read(tf);
|
||||
urlloaded = true;
|
||||
} catch (IOException iox3) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(tf.exists()) {
|
||||
try {
|
||||
img = ImageIO.read(tf);
|
||||
urlloaded = true;
|
||||
} catch (IOException iox3) {
|
||||
if(img == null) {
|
||||
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
|
||||
if(imgfile.exists()) {
|
||||
try {
|
||||
img = ImageIO.read(imgfile); /* Load existing */
|
||||
Log.info("Loaded cached texture file for " + blkid);
|
||||
} catch (IOException iox2) {
|
||||
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(img == null) {
|
||||
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
|
||||
if(imgfile.exists()) {
|
||||
try {
|
||||
img = ImageIO.read(imgfile); /* Load existing */
|
||||
Log.info("Loaded cached texture file for " + blkid);
|
||||
} catch (IOException iox2) {
|
||||
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
|
||||
}
|
||||
if(img != null) {
|
||||
try {
|
||||
if(urlloaded)
|
||||
ImageIO.write(img, "png", imgfile);
|
||||
} catch (IOException iox) {
|
||||
Log.severe("Error writing " + blkid + ".png");
|
||||
} finally {
|
||||
img.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(img != null) {
|
||||
try {
|
||||
if(urlloaded)
|
||||
ImageIO.write(img, "png", imgfile);
|
||||
} catch (IOException iox) {
|
||||
Log.severe("Error writing " + blkid + ".png");
|
||||
} finally {
|
||||
img.flush();
|
||||
}
|
||||
if(imgfile.exists()) { /* If exists now, log it */
|
||||
String tfid = "txtid" + texturelist.size();
|
||||
sb.append("texturefile:id=" + tfid + ",filename=spout/" + blkid + ".png,xcount=" + w/sz + ",ycount=" + h/sz + "\n");
|
||||
texturelist.put(txname, tfid);
|
||||
@@ -166,7 +215,7 @@ public class SpoutPluginBlocks {
|
||||
blks.add(b);
|
||||
|
||||
sb.append("block:id=" + b.getCustomId() + ",data=*,bottom=" + txtidx[0] + ",west=" +txtidx[1] + ",south=" + txtidx[2] + ",east=" + txtidx[3] + ",north="+txtidx[4]+",top="+txtidx[5]);
|
||||
if(b.isOpaque() == false)
|
||||
if(b.getBlockId() == Material.GLASS.getId())
|
||||
sb.append(",transparency=TRANSPARENT");
|
||||
sb.append(",txtid=" + txfileid + "\n");
|
||||
cnt++;
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.dynmap.Log;
|
||||
|
||||
public class BukkitPermissions implements PermissionProvider {
|
||||
String name;
|
||||
protected String name;
|
||||
protected Map<String, Boolean> pd;
|
||||
|
||||
public static BukkitPermissions create(String name) {
|
||||
public static BukkitPermissions create(String name, Map<String,Boolean> pd) {
|
||||
try {
|
||||
Class.forName("org.bukkit.permissions.PermissibleBase"); /* See if class exists */
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
return null;
|
||||
}
|
||||
Log.info("Using Bukkit Permissions (superperms) for access control");
|
||||
return new BukkitPermissions(name);
|
||||
Log.info("Web interface permissions only available for online users");
|
||||
return new BukkitPermissions(name, pd);
|
||||
}
|
||||
|
||||
public BukkitPermissions(String name) {
|
||||
public BukkitPermissions(String name, Map<String, Boolean> pd) {
|
||||
this.name = name;
|
||||
this.pd = pd;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,4 +37,33 @@ public class BukkitPermissions implements PermissionProvider {
|
||||
? player.hasPermission(name + "." + permission) || player.hasPermission(name + ".*")
|
||||
: true;
|
||||
}
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
Player p = Bukkit.getPlayerExact(name);
|
||||
HashSet<String> hasperms = null;
|
||||
if (p != null) {
|
||||
hasperms = new HashSet<String>();
|
||||
for(String perm : perms) {
|
||||
if (p.hasPermission(name + "." + perm)) {
|
||||
hasperms.add(perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
Player p = Bukkit.getPlayerExact(player);
|
||||
if (p != null) {
|
||||
return p.hasPermission(name + "." + perm);
|
||||
}
|
||||
else {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(player);
|
||||
if((op != null) && op.isOp()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -13,6 +17,7 @@ public class NijikokunPermissions implements PermissionProvider {
|
||||
String name;
|
||||
PermissionHandler permissions;
|
||||
Plugin plugin;
|
||||
String defworld;
|
||||
|
||||
public static NijikokunPermissions create(Server server, String name) {
|
||||
Plugin permissionsPlugin = server.getPluginManager().getPlugin("Permissions");
|
||||
@@ -20,6 +25,9 @@ public class NijikokunPermissions implements PermissionProvider {
|
||||
return null;
|
||||
|
||||
server.getPluginManager().enablePlugin(permissionsPlugin);
|
||||
if(permissionsPlugin.isEnabled() == false)
|
||||
return null;
|
||||
|
||||
Log.info("Using Permissions " + permissionsPlugin.getDescription().getVersion() + " for access control");
|
||||
return new NijikokunPermissions(permissionsPlugin, name);
|
||||
}
|
||||
@@ -27,6 +35,7 @@ public class NijikokunPermissions implements PermissionProvider {
|
||||
public NijikokunPermissions(Plugin permissionsPlugin, String name) {
|
||||
this.name = name;
|
||||
plugin = permissionsPlugin;
|
||||
defworld = Bukkit.getServer().getWorlds().get(0).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,4 +47,25 @@ public class NijikokunPermissions implements PermissionProvider {
|
||||
? permissions.has(player, name + "." + permission) || permissions.has(player, name + ".*")
|
||||
: true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
if(permissions == null)
|
||||
permissions = ((Permissions)plugin).getHandler();
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
for (String pp : perms) {
|
||||
if (permissions.has(defworld, player, name + "." + pp)) {
|
||||
hasperms.add(pp);
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
if(permissions == null)
|
||||
permissions = ((Permissions)plugin).getHandler();
|
||||
return permissions.has(defworld, player, name + "." + perm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -24,4 +25,12 @@ public class OpPermissions implements PermissionProvider {
|
||||
: true
|
||||
: true;
|
||||
}
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.Log;
|
||||
|
||||
import ru.tehkode.permissions.PermissionManager;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
public class PEXPermissions implements PermissionProvider {
|
||||
String name;
|
||||
PermissionManager pm;
|
||||
|
||||
public static PEXPermissions create(Server server, String name) {
|
||||
Plugin permissionsPlugin = server.getPluginManager().getPlugin("PermissionsEx");
|
||||
if (permissionsPlugin == null)
|
||||
return null;
|
||||
server.getPluginManager().enablePlugin(permissionsPlugin);
|
||||
if(permissionsPlugin.isEnabled() == false)
|
||||
return null;
|
||||
if(PermissionsEx.isAvailable() == false)
|
||||
return null;
|
||||
Log.info("Using PermissionsEx " + permissionsPlugin.getDescription().getVersion() + " for access control");
|
||||
return new PEXPermissions(name);
|
||||
}
|
||||
|
||||
public PEXPermissions(String name) {
|
||||
this.name = name;
|
||||
pm = PermissionsEx.getPermissionManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(CommandSender sender, String permission) {
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
return (player != null) ? pm.has(player, name + "." + permission) : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
PermissionUser pu = pm.getUser(player);
|
||||
if(pu != null) {
|
||||
for (String pp : perms) {
|
||||
if (pu.has(name + "." + pp)) {
|
||||
hasperms.add(pp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
PermissionUser pu = pm.getUser(player);
|
||||
if(pu != null) {
|
||||
return pu.has(name + "." + perm);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.Log;
|
||||
|
||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||
|
||||
public class PermBukkitPermissions extends BukkitPermissions {
|
||||
PermissionsPlugin plugin;
|
||||
Map<String, Boolean> pd;
|
||||
|
||||
public static PermBukkitPermissions create(Server server, String name, Map<String, Boolean> pd) {
|
||||
Plugin permissionsPlugin = server.getPluginManager().getPlugin("PermissionsBukkit");
|
||||
if (permissionsPlugin == null)
|
||||
return null;
|
||||
|
||||
server.getPluginManager().enablePlugin(permissionsPlugin);
|
||||
if(permissionsPlugin.isEnabled() == false)
|
||||
return null;
|
||||
|
||||
Log.info("Using PermissionsBukkit " + permissionsPlugin.getDescription().getVersion() + " for access control");
|
||||
Log.info("Web interface permissions only available for online users");
|
||||
return new PermBukkitPermissions(permissionsPlugin, name, pd);
|
||||
}
|
||||
|
||||
public PermBukkitPermissions(Plugin permissionsPlugin, String name, Map<String, Boolean> pd) {
|
||||
super(name, pd);
|
||||
plugin = (PermissionsPlugin) permissionsPlugin;
|
||||
this.pd = pd;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface PermissionProvider {
|
||||
boolean has(CommandSender sender, String permission);
|
||||
|
||||
Set<String> hasOfflinePermissions(String player, Set<String> perms);
|
||||
|
||||
boolean hasOfflinePermission(String player, String perm);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.dynmap.bukkit.permissions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.Log;
|
||||
|
||||
import de.bananaco.bpermissions.api.User;
|
||||
import de.bananaco.bpermissions.api.WorldManager;
|
||||
|
||||
public class bPermPermissions extends BukkitPermissions {
|
||||
WorldManager wm;
|
||||
|
||||
public static bPermPermissions create(Server server, String name, Map<String,Boolean> pd) {
|
||||
Plugin permissionsPlugin = server.getPluginManager().getPlugin("bPermissions");
|
||||
if (permissionsPlugin == null)
|
||||
return null;
|
||||
server.getPluginManager().enablePlugin(permissionsPlugin);
|
||||
if(permissionsPlugin.isEnabled() == false)
|
||||
return null;
|
||||
|
||||
Log.info("Using bPermissions " + permissionsPlugin.getDescription().getVersion() + " for access control");
|
||||
return new bPermPermissions(name, pd);
|
||||
}
|
||||
|
||||
public bPermPermissions(String name, Map<String,Boolean> pd) {
|
||||
super(name, pd);
|
||||
wm = WorldManager.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> hasOfflinePermissions(String player, Set<String> perms) {
|
||||
HashSet<String> hasperms = new HashSet<String>();
|
||||
User usr = wm.getDefaultWorld().getUser(player);
|
||||
if(usr != null) {
|
||||
try { usr.calculateEffectivePermissions(); } catch (Exception x) {}
|
||||
Map<String,Boolean> p = usr.getMappedPermissions();
|
||||
for (String pp : perms) {
|
||||
String permval = name + "." + pp;
|
||||
Boolean v = p.get(permval);
|
||||
if (v != null) {
|
||||
if(v.booleanValue())
|
||||
hasperms.add(permval);
|
||||
}
|
||||
else {
|
||||
v = pd.get(permval);
|
||||
if((v != null) && v.booleanValue())
|
||||
hasperms.add(permval);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasperms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOfflinePermission(String player, String perm) {
|
||||
boolean rslt;
|
||||
String permval = name + "." + perm;
|
||||
User usr = wm.getDefaultWorld().getUser(player);
|
||||
if(usr != null) {
|
||||
try { usr.calculateEffectivePermissions(); } catch (Exception x) {}
|
||||
if(usr.getMappedPermissions().containsKey(permval)) {
|
||||
rslt = usr.hasPermission(permval);
|
||||
}
|
||||
else {
|
||||
Boolean v = pd.get(permval);
|
||||
if(v != null)
|
||||
rslt = v;
|
||||
else
|
||||
rslt = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rslt = false;
|
||||
}
|
||||
return rslt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
package org.dynmap.herochat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.CustomEventListener;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.bukkit.DynmapPlugin;
|
||||
|
||||
/**
|
||||
* Bukkit specific module - alternate chat handler for interfacing with HeroChat
|
||||
*/
|
||||
public class HeroChatHandler {
|
||||
private static final String DEF_CHANNEL = "Global";
|
||||
private static final List<String> DEF_CHANNELS = Collections
|
||||
.singletonList(DEF_CHANNEL);
|
||||
|
||||
private List<String> hcchannels;
|
||||
private String hcwebinputchannel;
|
||||
private DynmapCore core;
|
||||
private HeroChatChannel hcwebinputchan;
|
||||
|
||||
private class OurPluginListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
Plugin plugin = event.getPlugin();
|
||||
String name = plugin.getDescription().getName();
|
||||
|
||||
if (name.equals("HeroChat")) {
|
||||
activateHeroChat(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reflection-based access wrapper for ChannelChatEvent from HeroChat */
|
||||
private static class HeroChatChannelChatEvent {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Class channelchatevent;
|
||||
private static Method getsource;
|
||||
private static Method getmessage;
|
||||
private static Method issentbyplayer;
|
||||
private static boolean isgood = false;
|
||||
private Event evt;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean initialize() {
|
||||
try {
|
||||
channelchatevent = Class
|
||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelChatEvent");
|
||||
getsource = channelchatevent.getMethod("getSource", new Class[0]);
|
||||
getmessage = channelchatevent.getMethod("getMessage", new Class[0]);
|
||||
issentbyplayer = channelchatevent.getMethod("isSentByPlayer", new Class[0]);
|
||||
isgood = true;
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
}
|
||||
return isgood;
|
||||
}
|
||||
|
||||
public HeroChatChannelChatEvent(Event evt) {
|
||||
this.evt = evt;
|
||||
}
|
||||
|
||||
public static boolean isInstance(Event evt) {
|
||||
return channelchatevent.isInstance(evt);
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
try {
|
||||
return (String) getsource.invoke(evt);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
try {
|
||||
return (String) getmessage.invoke(evt);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSentByPlayer() {
|
||||
try {
|
||||
return (Boolean) issentbyplayer.invoke(evt);
|
||||
} catch (Exception x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reflection-based access wrapper for ChannelEvent from HeroChat */
|
||||
private static class HeroChatChannelEvent {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Class channelevent;
|
||||
private static Method getchannel;
|
||||
private static Method iscancelled;
|
||||
private static boolean isgood = false;
|
||||
private Event evt;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean initialize() {
|
||||
try {
|
||||
channelevent = Class
|
||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelEvent");
|
||||
getchannel = channelevent.getMethod("getChannel", new Class[0]);
|
||||
iscancelled = channelevent.getMethod("isCancelled", new Class[0]);
|
||||
isgood = true;
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
}
|
||||
return isgood;
|
||||
}
|
||||
|
||||
public HeroChatChannelEvent(Event evt) {
|
||||
this.evt = evt;
|
||||
}
|
||||
|
||||
public static boolean isInstance(Event evt) {
|
||||
return channelevent.isInstance(evt);
|
||||
}
|
||||
|
||||
public HeroChatChannel getChannel() {
|
||||
try {
|
||||
Object o;
|
||||
o = getchannel.invoke(evt);
|
||||
if (o != null) {
|
||||
return new HeroChatChannel(o);
|
||||
}
|
||||
} catch (Exception x) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
try {
|
||||
return (Boolean) iscancelled.invoke(evt);
|
||||
} catch (Exception x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reflection-based access wrapper for Channel from HeroChat */
|
||||
private static class HeroChatChannel {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Class channel;
|
||||
private static Method getname;
|
||||
private static Method getnick;
|
||||
private static Method sendmessage;
|
||||
private static boolean isgood = false;
|
||||
private Object chan;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean initialize() {
|
||||
try {
|
||||
channel = Class
|
||||
.forName("com.herocraftonline.dthielke.herochat.channels.Channel");
|
||||
getname = channel.getMethod("getName");
|
||||
getnick = channel.getMethod("getNick", new Class[0]);
|
||||
sendmessage = channel.getMethod("sendMessage", new Class[] {
|
||||
String.class, String.class, String.class, boolean.class } );
|
||||
isgood = true;
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
Log.severe(nsmx);
|
||||
}
|
||||
return isgood;
|
||||
}
|
||||
|
||||
public HeroChatChannel(Object chan) {
|
||||
this.chan = chan;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
try {
|
||||
return (String) getname.invoke(chan);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
try {
|
||||
return (String) getnick.invoke(chan);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(String source, String msg, String format, boolean sentByPlayer) {
|
||||
try {
|
||||
sendmessage.invoke(chan, source, msg, format, sentByPlayer);
|
||||
} catch (Exception x) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class OurEventListener extends CustomEventListener {
|
||||
/**
|
||||
* Handle custom events
|
||||
*/
|
||||
@EventHandler
|
||||
public void onCustomEvent(Event event) {
|
||||
if (HeroChatChannelEvent.isInstance(event)) {
|
||||
HeroChatChannelEvent ce = new HeroChatChannelEvent(event);
|
||||
/* Snoop for our web channel - we'll need it, and we'll see it before it matters,
|
||||
* since anyone that joins the channel will give us an event (and reflection on
|
||||
* the plugin class to get the manager didn't work, due to a dependency on the IRC
|
||||
* plugin that may not be present....)
|
||||
*/
|
||||
HeroChatChannel c = ce.getChannel();
|
||||
if (ce.isCancelled())
|
||||
return;
|
||||
if((hcwebinputchannel != null) && ((hcwebinputchannel.equals(c.getName())) ||
|
||||
(hcwebinputchannel.equals(c.getNick())))) {
|
||||
hcwebinputchan = c;
|
||||
}
|
||||
if (HeroChatChannelChatEvent.isInstance(event)) {
|
||||
HeroChatChannelChatEvent cce = new HeroChatChannelChatEvent(
|
||||
event);
|
||||
/* Match on name or nickname of channel */
|
||||
if (hcchannels.contains(c.getName()) ||
|
||||
hcchannels.contains(c.getNick())) {
|
||||
if(cce.isSentByPlayer()) { /* Player message? */
|
||||
org.bukkit.entity.Player p = DynmapPlugin.plugin.getServer().getPlayer(cce.getSource());
|
||||
if((p != null) && (core.mapManager != null)) {
|
||||
core.mapManager.pushUpdate(new Client.ChatMessage("player",
|
||||
c.getNick(),
|
||||
p.getDisplayName(),
|
||||
cce.getMessage(),
|
||||
p.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HeroChatHandler(ConfigurationNode cfg, DynmapCore core) {
|
||||
/* If we're enabling hero chat support */
|
||||
Log.verboseinfo("HeroChat support configured");
|
||||
this.core = core;
|
||||
/* Now, get the monitored channel list */
|
||||
hcchannels = cfg.getStrings("herochatchannels", DEF_CHANNELS);
|
||||
/* And get channel to send web messages */
|
||||
hcwebinputchannel = cfg.getString("herochatwebchannel", DEF_CHANNEL);
|
||||
Plugin hc = DynmapPlugin.plugin.getServer().getPluginManager().getPlugin("HeroChat");
|
||||
if(hc != null) {
|
||||
activateHeroChat(hc);
|
||||
}
|
||||
else {
|
||||
/* Set up to hear when HeroChat is enabled */
|
||||
DynmapPlugin.plugin.pm.registerEvents(new OurPluginListener(), DynmapPlugin.plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private void activateHeroChat(Plugin herochat) {
|
||||
if (HeroChatChannelChatEvent.initialize() == false) {
|
||||
Log.severe("Cannot load HeroChat chat event class!");
|
||||
return;
|
||||
}
|
||||
if (HeroChatChannel.initialize() == false) {
|
||||
Log.severe("Cannot load HeroChat channel class!");
|
||||
return;
|
||||
}
|
||||
if (HeroChatChannelEvent.initialize() == false) {
|
||||
Log.severe("Cannot load HeroChat channel event class!");
|
||||
return;
|
||||
}
|
||||
/* Register event handler */
|
||||
DynmapPlugin.plugin.pm.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener(), Event.Priority.Monitor, DynmapPlugin.plugin);
|
||||
|
||||
Log.verboseinfo("HeroChat integration active");
|
||||
}
|
||||
/**
|
||||
* Send message from web to appropriate HeroChat channel
|
||||
* @param sender - sender ID
|
||||
* @param message - message
|
||||
* @return true if herochat is handling this, false if not
|
||||
*/
|
||||
public boolean sendWebMessageToHeroChat(String sender, String message) {
|
||||
if(hcwebinputchannel != null) { /* Are we handling them? */
|
||||
if(hcwebinputchan != null) { /* Have we seen it yet? Maybe no if nobody has logged on or
|
||||
* joined it, but then who would see it anyway?
|
||||
*/
|
||||
hcwebinputchan.sendMessage(sender, message, "{default}", false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package org.dynmap.herochat;
|
||||
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
|
||||
import org.dynmap.ChatEvent;
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.Component;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.Event;
|
||||
import org.dynmap.common.DynmapListenerManager;
|
||||
import org.dynmap.common.DynmapListenerManager.EventType;
|
||||
import org.dynmap.common.DynmapPlayer;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class HeroWebChatComponent extends Component {
|
||||
HeroChatHandler handler;
|
||||
public HeroWebChatComponent(final DynmapCore plugin, ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
handler = new HeroChatHandler(configuration, plugin);
|
||||
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
|
||||
@Override
|
||||
public void triggered(ChatEvent t) {
|
||||
if(plugin.getServer().sendWebChatEvent(t.source, t.name, t.message)) {
|
||||
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
|
||||
if (!handler.sendWebMessageToHeroChat(t.name, t.message)) {
|
||||
String msg;
|
||||
String msgfmt = plugin.configuration.getString("webmsgformat", null);
|
||||
if(msgfmt != null) {
|
||||
msgfmt = unescapeString(msgfmt);
|
||||
msg = msgfmt.replace("%playername%", t.name).replace("%message%", t.message);
|
||||
}
|
||||
else {
|
||||
msg = unescapeString(plugin.configuration.getString("webprefix", "\u00A72[WEB] ")) + t.name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + t.message;
|
||||
}
|
||||
plugin.getServer().broadcastMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void triggered(JSONObject t) {
|
||||
s(t, "allowchat", true);
|
||||
}
|
||||
});
|
||||
|
||||
// Also make HeroChat announce joins and quits.
|
||||
core.listenerManager.addListener(EventType.PLAYER_JOIN, new DynmapListenerManager.PlayerEventListener() {
|
||||
@Override
|
||||
public void playerEvent(DynmapPlayer p) {
|
||||
if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
|
||||
core.mapManager.pushUpdate(new Client.PlayerJoinMessage(p.getDisplayName(), p.getName()));
|
||||
}
|
||||
}
|
||||
});
|
||||
core.listenerManager.addListener(EventType.PLAYER_QUIT, new DynmapListenerManager.PlayerEventListener() {
|
||||
@Override
|
||||
public void playerEvent(DynmapPlayer p) {
|
||||
if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
|
||||
core.mapManager.pushUpdate(new Client.PlayerQuitMessage(p.getDisplayName(), p.getName()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user