mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Initial go at dynmap destinations
This commit is contained in:
parent
5be6ea2766
commit
0209099e15
14
pom.xml
14
pom.xml
@ -20,6 +20,11 @@
|
||||
<id>Bukkit Official</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/public</url>
|
||||
</repository>
|
||||
<!-- I've been told they'll have a repo this weekend :D
|
||||
<repository>
|
||||
<id>DynMap</id>
|
||||
<url>TBD</url>
|
||||
</repository> -->
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
@ -221,6 +226,15 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of CommandHandler Dependency -->
|
||||
<!-- Start DynMap Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
<artifactId>DynmapCore</artifactId>
|
||||
<version>0.34.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End DynMap Dependency -->
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -32,6 +32,7 @@ import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
|
||||
import com.onarandombox.MultiverseCore.plugins.DynmapConnector;
|
||||
import com.onarandombox.MultiverseCore.utils.*;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
|
||||
@ -71,6 +72,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private AnchorManager anchorManager = new AnchorManager(this);
|
||||
// TODO please let's make this non-static
|
||||
private MultiverseCoreConfiguration config;
|
||||
private DynmapConnector dynmapConnecter;
|
||||
|
||||
/**
|
||||
* This method is used to find out who is teleporting a player.
|
||||
@ -258,6 +260,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.setSpout();
|
||||
this.log(Level.INFO, "Spout integration enabled.");
|
||||
}
|
||||
|
||||
// Check to see if Dynmap was already loaded:
|
||||
if (this.getServer().getPluginManager().getPlugin("dynmap") != null) {
|
||||
this.getDynmap();
|
||||
this.log(Level.INFO, "Dynmap integration enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeDestinationFactory() {
|
||||
@ -866,4 +874,20 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public static MultiverseCoreConfiguration getStaticConfig() {
|
||||
return MultiverseCoreConfiguration.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if dynmap was detected.
|
||||
* @return True if dynmap was detected.
|
||||
*/
|
||||
public boolean isDynmapLoaded() {
|
||||
return !(this.dynmapConnecter == null);
|
||||
}
|
||||
|
||||
public DynmapConnector getDynmap() {
|
||||
return this.dynmapConnecter;
|
||||
}
|
||||
|
||||
public void setDynmap() {
|
||||
this.dynmapConnecter = new DynmapConnector(this.getServer().getPluginManager().getPlugin("dynmap"), this);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.onarandombox.MultiverseCore.plugins;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.plugins.destination.DynmapMarkerDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.markers.Marker;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Non-Intrusive Connector class.
|
||||
*/
|
||||
public class DynmapConnector {
|
||||
|
||||
private DynmapCore plugin;
|
||||
private MultiverseCore core;
|
||||
|
||||
/**
|
||||
* This class should only ever get initialized ONCE!
|
||||
*/
|
||||
public DynmapConnector(Plugin dynmapCore, MultiverseCore core) {
|
||||
this.plugin = (DynmapCore) dynmapCore;
|
||||
this.core = core;
|
||||
this.addDestinationToManager();
|
||||
}
|
||||
|
||||
private void addDestinationToManager() {
|
||||
this.core.getDestFactory().registerDestinationType(DynmapMarkerDestination.class, "dm");
|
||||
}
|
||||
|
||||
public Location getLocation(String markerSet, String marker) {
|
||||
MarkerSet set = this.plugin.getMarkerAPI().getMarkerSet(markerSet);
|
||||
if (set == null) {
|
||||
return null;
|
||||
}
|
||||
// Try to find it by the ID
|
||||
Marker m = set.findMarker(marker);
|
||||
if (m != null) {
|
||||
return this.getLocationFromMarker(m);
|
||||
}
|
||||
// Try to find it by the label
|
||||
m = set.findMarkerByLabel(marker);
|
||||
if (m != null) {
|
||||
return this.getLocationFromMarker(m);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Location getLocationFromMarker(Marker m) {
|
||||
return new Location(this.core.getServer().getWorld(m.getWorld()), m.getX(), m.getY(), m.getZ());
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package com.onarandombox.MultiverseCore.plugins.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.plugins.DynmapConnector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DynmapMarkerDestination implements MVDestination{
|
||||
private MultiverseCore plugin;
|
||||
private Location location;
|
||||
private DynmapConnector dynmap;
|
||||
private boolean isValid;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "dm";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
if (!this.plugin.isDynmapLoaded()) {
|
||||
return false;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: a:set:name
|
||||
if (!(parsed.size() == 3)) {
|
||||
return false;
|
||||
}
|
||||
// If it's not a Dynmap type
|
||||
return parsed.get(0).equalsIgnoreCase("dm");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity entity) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
if (!this.plugin.isDynmapLoaded()) {
|
||||
return;
|
||||
}
|
||||
this.dynmap = this.plugin.getDynmap();
|
||||
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 3)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.dynmap.getLocation(parsed.get(1), parsed.get(2));
|
||||
if (this.location == null) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.isValid = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Dynmap Marker";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s: %s", this.getType(), this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return String.format("multiverse.access.", this.location.getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user