Permalink
Browse files

It Livvvveeeeeesssssssssss!!!

  • Loading branch information...
FernFerret committed Aug 21, 2011
1 parent e3e3596 commit 8404619e56deb33ee99d9446adde696135d66a27
View
@@ -24,10 +24,10 @@
/world
# Mac filesystem dust
-/.DS_Store
+.DS_Store
# intellij
*.iml
*.ipr
*.iws
-.idea/
+.idea/
@@ -1,188 +0,0 @@
-package com.onarandombox.MultiverseSignPortals;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-
-import org.bukkit.ChatColor;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.block.BlockState;
-import org.bukkit.block.Sign;
-import org.bukkit.entity.Player;
-import org.bukkit.event.player.PlayerListener;
-import org.bukkit.event.player.PlayerMoveEvent;
-import org.bukkit.util.Vector;
-
-import com.onarandombox.MultiverseCore.MVPlayerSession;
-import com.onarandombox.MultiverseCore.MVTeleport;
-
-public class MVSPPlayerListener extends PlayerListener {
-
- private final MultiverseSignPortals plugin;
-
- protected MVSPPlayerListener(MultiverseSignPortals plugin) {
- this.plugin = plugin;
- }
-
- public void onPlayerMove(PlayerMoveEvent event) {
- if (event.isCancelled())
- return;
-
- final Player p = event.getPlayer();
- Location loc = p.getLocation();
- World w = p.getWorld();
-
- /**
- * Check the Player has actually moved a block to prevent unneeded calculations... This is to prevent huge performance drops on high player count servers.
- */
- //MVPlayerSession ps = this.plugin.core.getPlayerSession(p);
- //if (ps.loc.getBlockX() == loc.getBlockX() && ps.loc.getBlockY() == loc.getBlockY() && ps.loc.getBlockZ() == loc.getBlockZ()) {
- // return;
- //}
-
- int locX = loc.getBlockX();
- int locY = loc.getBlockY();
- int locZ = loc.getBlockZ();
-
- Block b = p.getWorld().getBlockAt(locX, locY, locZ);
- if (!b.getType().equals(Material.PORTAL))
- return;
-
- // Possibly a tidier way of setting these base values up, but hey...
- int lowLocX = loc.getBlockX();
- int highLocX = loc.getBlockX();
- int lowLocY = loc.getBlockY();
- int highLocY = loc.getBlockY();
- int lowLocZ = loc.getBlockZ();
- int highLocZ = loc.getBlockZ();
-
- while (w.getBlockAt(lowLocX, lowLocY - 1, lowLocZ).getType().equals(Material.PORTAL))
- --lowLocY;
- while (w.getBlockAt(lowLocX - 1, lowLocY, lowLocZ).getType().equals(Material.PORTAL))
- --lowLocX;
- while (w.getBlockAt(lowLocX, lowLocY, lowLocZ - 1).getType().equals(Material.PORTAL))
- --lowLocZ;
- while (w.getBlockAt(highLocX, highLocY + 1, highLocZ).getType().equals(Material.PORTAL))
- ++highLocY;
- while (w.getBlockAt(highLocX + 1, highLocY, highLocZ).getType().equals(Material.PORTAL))
- ++highLocX;
- while (w.getBlockAt(highLocX, highLocY, highLocZ + 1).getType().equals(Material.PORTAL))
- ++highLocZ;
-
- // Grab whether the Portal is along the X Axis.
- boolean orientX = w.getBlockAt(lowLocX + 1, lowLocY, lowLocZ).getType().equals(Material.PORTAL);
-
- // Set Vectors for the Highest and Lowest Possible points of the portal.
- Vector lowPoint, highPoint;
- if (orientX) {
- lowPoint = new Vector(lowLocX - 1, lowLocY - 1, lowLocZ);
- highPoint = new Vector(highLocX + 1, highLocY + 1, highLocZ);
- } else {
- lowPoint = new Vector(lowLocX, lowLocY - 1, lowLocZ - 1);
- highPoint = new Vector(highLocX, highLocY + 1, highLocZ + 1);
- }
-
- List<Block> portalBlocks = new ArrayList<Block>();
- List<Block> obsidianBlocks = new ArrayList<Block>();
- List<Sign> s = new ArrayList<Sign>();
-
- for (int x = lowPoint.getBlockX(); x <= highPoint.getBlockX(); x++) {
- for (int y = lowPoint.getBlockY(); y <= highPoint.getBlockY(); y++) {
- for (int z = lowPoint.getBlockZ(); z <= highPoint.getBlockZ(); z++) {
- Block block = w.getBlockAt(x, y, z);
- if (block.getType().equals(Material.PORTAL))
- portalBlocks.add(block);
- if (block.getType().equals(Material.OBSIDIAN)) {
- obsidianBlocks.add(block);
-
- // This next bit of mess grabs the BlockState for all 4 possible sides which a sign could be placed on.
- // Checks if a WALL_SIGN is present... if so it then checks if the Sign is attached to the Obsidian block or not.
- BlockState bs = null;
- bs = block.getRelative(BlockFace.NORTH).getState();
- if (bs.getType() == Material.WALL_SIGN) {
- if (((org.bukkit.material.Sign) bs.getData()).getAttachedFace() == BlockFace.SOUTH) {
- s.add((Sign) bs);
- }
- }
- bs = block.getRelative(BlockFace.EAST).getState();
- if (bs.getType() == Material.WALL_SIGN) {
- if (((org.bukkit.material.Sign) bs.getData()).getAttachedFace() == BlockFace.WEST) {
- s.add((Sign) bs);
- }
- }
- bs = block.getRelative(BlockFace.SOUTH).getState();
- if (bs.getType() == Material.WALL_SIGN) {
- if (((org.bukkit.material.Sign) bs.getData()).getAttachedFace() == BlockFace.NORTH) {
- s.add((Sign) bs);
- }
- }
- bs = block.getRelative(BlockFace.WEST).getState();
- if (bs.getType() == Material.WALL_SIGN) {
- if (((org.bukkit.material.Sign) bs.getData()).getAttachedFace() == BlockFace.EAST) {
- s.add((Sign) bs);
- }
- }
- }
-
- }
- }
- }
-
- // DEBUG
- // MultiVerseCore.debugMsg(portalBlocks.size() + " - Portal Blocks");
- // MultiVerseCore.debugMsg(obsidianBlocks.size() + " - Obsidian Blocks");
- // MultiVerseCore.debugMsg(s.size() + " - Signs");
- // MultiVerseCore.debugMsg(orientX + " - X Orientation");
- // DEBUG
-
- // TODO: Check if a sign exists full stop. -- Below is wrong... cycle all signs for a destination.
- // CYCLE THROUGH ALL SIGNS FOUND TO FIND A DESTINATION
- World world = null;
- for (int i = 0; i < s.size(); i++) {
- Sign sign = (Sign) s.get(i);
- if ((sign.getLine(1).equalsIgnoreCase("[multiverse]") || sign.getLine(1).equalsIgnoreCase("[mv]")) && (sign.getLine(2).length() > 0)) {
- world = this.plugin.getServer().getWorld(sign.getLine(2).toString());
- if (world != null) {
- break;
- } else {
- this.plugin.core.getPlayerSession(p).message(ChatColor.RED + "The World \"" + sign.getLine(2).toString() + "\" does not EXIST!");
- return;
- }
- }
- }
-
- MVTeleport mvtp = plugin.core.getTeleporter();
-
- Location dest;
-
- dest = mvtp.getCompressedLocation(p, world);
- MultiverseSignPortals.debugLog.log(Level.INFO, dest.toString());
-
- Location portal = mvtp.findPortal(dest);
- if (portal != null) {
- dest = portal;
- }
-
- MultiverseSignPortals.debugLog.log(Level.INFO, dest.toString());
-
- final Location d = mvtp.getSafeDestination(dest);
-
- if (d != null) {
- MultiverseSignPortals.debugLog.log(Level.INFO, dest.toString());
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- @Override
- public void run() {
- p.teleport(d);
- }
- });
- } else {
- MultiverseSignPortals.debugLog.log(Level.INFO, "Cannot find a safe location, try another portal/location.");
- //ps.message(ChatColor.RED + "Cannot find a safe location, try another portal/location.");
- return;
- }
- }
-}
@@ -1,17 +1,21 @@
package com.onarandombox.MultiverseSignPortals;
import java.io.File;
+import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
+import com.onarandombox.MultiverseCore.MVPlugin;
import com.onarandombox.MultiverseCore.MultiverseCore;
+import com.onarandombox.MultiverseSignPortals.listeners.MVSPPlayerListener;
+import com.onarandombox.MultiverseSignPortals.listeners.MVSPPluginListener;
import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.UpdateChecker;
-public class MultiverseSignPortals extends JavaPlugin {
+public class MultiverseSignPortals extends JavaPlugin implements MVPlugin {
public static final Logger log = Logger.getLogger("Minecraft");
public static final String logPrefix = "[MultiVerse-SignPortals] ";
@@ -23,29 +27,33 @@
public UpdateChecker updateCheck;
public void onEnable() {
- pluginListener = new MVSPPluginListener(this);
- // Register the PLUGIN_ENABLE Event as we will need to keep an eye out for the Core Enabling if we don't find it initially.
- getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, pluginListener, Priority.Normal, this);
-
- // Try and grab the Core Plugin, if it doesn't exist it will return null.
- core = (MultiverseCore) getServer().getPluginManager().getPlugin("Multiverse-Core");
+ this.core = (MultiverseCore) getServer().getPluginManager().getPlugin("Multiverse-Core");
// Test if the Core was found, if not we'll disable this plugin.
- if (core == null) {
+ if (this.core == null) {
log.info(logPrefix + "Multiverse-Core not found, will keep looking.");
getServer().getPluginManager().disablePlugin(this);
return;
}
+ debugLog = new DebugLog("Multiverse-SignPortals", getDataFolder() + File.separator + "debug.log");
+
+ this.core.incrementPluginCount();
+
+ // Init our listeners
+ pluginListener = new MVSPPluginListener(this);
+ playerListener = new MVSPPlayerListener(this);
+
+ // Init our events
+ getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, pluginListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Type.PLAYER_PORTAL, playerListener, Priority.Normal, this);
+
// Setup the Player Listener, we only need to listen out for PLAYER_MOVE Events.
- playerListener = new MVSPPlayerListener(this);
- getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
+
+
// Simple Log output to state the plugin is ENABLED
log.info(logPrefix + "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
-
- // Setup the Update Checker, this will check every 30 minutes for an update to the plugin and output to the console.
- // updateCheck = new UpdateChecker(this.getDescription().getName(),this.getDescription().getVersion());
}
public void onDisable() {
@@ -77,4 +85,33 @@ private String getAuthors() {
}
return authors.substring(2);
}
+
+ @Override
+ public void log(Level level, String msg) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String dumpVersionInfo(String buffer) {
+ buffer += logAndAddToPasteBinBuffer("Multiverse-SignPortals Version: " + this.getDescription().getVersion());
+ buffer += logAndAddToPasteBinBuffer("Bukkit Version: " + this.getServer().getVersion());
+ buffer += logAndAddToPasteBinBuffer("Special Code: FRN001");
+ return buffer;
+ }
+
+ private String logAndAddToPasteBinBuffer(String string) {
+ this.log(Level.INFO, string);
+ return "[Multiverse-NetherPortals] " + string + "\n";
+ }
+
+ @Override
+ public MultiverseCore getCore() {
+ return this.core;
+ }
+
+ @Override
+ public void setCore(MultiverseCore core) {
+ this.core = core;
+ }
}
@@ -0,0 +1,26 @@
+package com.onarandombox.MultiverseSignPortals.listeners;
+
+import org.bukkit.event.player.PlayerListener;
+import org.bukkit.event.player.PlayerPortalEvent;
+
+import com.onarandombox.MultiverseSignPortals.MultiverseSignPortals;
+import com.onarandombox.MultiverseSignPortals.utils.PortalDetector;
+
+public class MVSPPlayerListener extends PlayerListener {
+
+ private final MultiverseSignPortals plugin;
+
+ public MVSPPlayerListener(MultiverseSignPortals plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public void onPlayerPortal(PlayerPortalEvent event) {
+ if(event.isCancelled()) {
+ return;
+ }
+ PortalDetector detector = new PortalDetector(this.plugin);
+ detector.isNotchStylePortal(event.getPlayer().getLocation());
+ event.setCancelled(true);
+ }
+}
@@ -1,9 +1,10 @@
-package com.onarandombox.MultiverseSignPortals;
+package com.onarandombox.MultiverseSignPortals.listeners;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import com.onarandombox.MultiverseCore.MultiverseCore;
+import com.onarandombox.MultiverseSignPortals.MultiverseSignPortals;
public class MVSPPluginListener extends ServerListener {
@@ -15,7 +16,7 @@ public MVSPPluginListener(MultiverseSignPortals plugin) {
public void onPluginEnable(PluginEnableEvent event) {
if (event.getPlugin().getDescription().getName().equals("Multiverse-Core")) {
- this.plugin.core = ((MultiverseCore) plugin.getServer().getPluginManager().getPlugin("Multiverse-Core"));
+ this.plugin.setCore(((MultiverseCore) plugin.getServer().getPluginManager().getPlugin("Multiverse-Core")));
this.plugin.getServer().getPluginManager().enablePlugin(this.plugin);
}
}
Oops, something went wrong.

0 comments on commit 8404619

Please sign in to comment.