/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.DialogReceiver; /* */ import NET.worlds.console.Main; /* */ import NET.worlds.console.MainCallback; /* */ import NET.worlds.console.WorldsMarkPart; /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.network.NetUpdate; /* */ import NET.worlds.network.URL; /* */ import java.awt.Frame; /* */ import java.io.IOException; /* */ import java.net.MalformedURLException; /* */ import java.text.MessageFormat; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class TeleportAction /* */ extends Action /* */ implements LoadedURLSelf, MainCallback, DialogReceiver /* */ { /* 102 */ private Point3 targetCoords = new Point3(); /* 103 */ private float targetRot = 0.0F; /* 104 */ private Point3 targetAxis = new Point3(0.0F, 0.0F, -1.0F); /* 105 */ private String targetRoomName = null; /* 106 */ private String targetDimension = null; /* 107 */ private URL targetWorldURL = null; /* */ /* 109 */ private boolean useDefCoordinates = false; /* 110 */ private boolean done = false; /* 111 */ private boolean showDialog = true; /* 112 */ private boolean forceWorldLoad = false; /* 113 */ private boolean forceNoWorldLoad = false; /* */ /* */ /* */ /* */ /* */ private String targetURL; /* */ /* */ /* */ /* */ /* 123 */ private static TeleportAction activeTeleport = null; /* 124 */ private TeleportDialog dialog = null; /* */ private TeleportStatus doneCallback; /* */ String tempParseStr; /* */ /* */ public TeleportAction() {} /* */ /* 130 */ public Persister trigger(Event e, Persister seqID) { if (activeTeleport != this) { /* 131 */ this.targetURL = asURL(); /* 132 */ startTeleport(); /* */ } /* */ /* */ /* 136 */ return (this.done) || (activeTeleport == this) ? null : this; /* */ } /* */ /* */ public void stopLoading() { /* 140 */ this.done = true; /* 141 */ if (activeTeleport == this) { /* 142 */ stopTeleport(null); /* */ } /* */ } /* */ /* */ public static boolean isTeleporting() /* */ { /* 148 */ return activeTeleport != null; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static void teleport(String url, TeleportStatus callback) /* */ { /* 166 */ TeleportAction t = new TeleportAction(url, callback); /* */ /* 168 */ if (Main.isMainThread()) { /* 169 */ t.startTeleport(); /* */ } else { /* 171 */ Main.register(t); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static void teleport(String url, TeleportStatus callback, boolean forceWorldLoad) /* */ { /* 183 */ TeleportAction t = new TeleportAction(url, callback); /* 184 */ t.forceWorldLoad = forceWorldLoad; /* 185 */ t.forceNoWorldLoad = (!forceWorldLoad); /* */ /* 187 */ if (Main.isMainThread()) { /* 188 */ t.startTeleport(); /* */ } else { /* 190 */ Main.register(t); /* */ } /* */ } /* */ /* */ public static void teleport(String url, TeleportStatus callback, boolean forceWorldLoad, boolean pShowDialog) /* */ { /* 196 */ TeleportAction t = new TeleportAction(url, callback); /* 197 */ t.showDialog = pShowDialog; /* 198 */ t.forceWorldLoad = forceWorldLoad; /* 199 */ t.forceNoWorldLoad = (!forceWorldLoad); /* */ /* 201 */ if (Main.isMainThread()) { /* 202 */ t.startTeleport(); /* */ } else /* 204 */ Main.register(t); /* */ } /* */ /* */ public void mainCallback() { /* 208 */ Main.unregister(this); /* 209 */ startTeleport(); /* */ } /* */ /* */ public static String toURLString(String url) { /* 213 */ if ((url == null) || (url.equals("world:"))) /* 214 */ url = WorldsMarkPart.getFirstSystemMarkURL(); /* 215 */ if (url == null) /* 216 */ url = "home:NewWorld.world"; /* 217 */ if (url.startsWith("world:")) { /* 218 */ if (url.equals("world:restart")) { /* 219 */ url = IniFile.gamma().getIniString("RestartAt", /* 220 */ WorldsMarkPart.getFirstSystemMarkURL()); /* 221 */ } else if (url.equals("world:store")) { /* 222 */ url = World.getHomeStore().getAbsolute(); /* */ } else /* 224 */ url = url.substring(6); /* 225 */ int i = url.indexOf(".world?"); /* 226 */ if (i >= 0) /* 227 */ url = url.substring(0, i) + ".world#" + url.substring(i + 7); /* */ } /* 229 */ if (url.indexOf(':') < 0) { /* 230 */ if ((url.indexOf('/') < 0) && (url.indexOf('\\') < 0) && /* 231 */ (!url.endsWith(".world"))) { /* 232 */ url = "home:" + url + "/" + url + ".world"; /* */ } else /* 234 */ url = "file:" + url; /* */ } /* 236 */ return url; /* */ } /* */ /* */ /* */ private TeleportAction(String url, TeleportStatus callback) /* */ { /* 242 */ this.doneCallback = callback; /* */ /* 244 */ this.targetURL = toURLString(url); /* */ /* */ /* 247 */ url = setFromURL(this.targetURL); /* */ try /* */ { /* 250 */ if (this.targetURL.startsWith("http://")) { /* 251 */ this.targetWorldURL = new URL(url); /* */ } else { /* 253 */ this.targetWorldURL = new URL(URL.getCurDir(), /* 254 */ URL.maybeAddExt(url, ".world")); /* */ } /* */ } /* */ catch (MalformedURLException e) { /* 258 */ this.targetWorldURL = URL.make("error:\"" + url + '"'); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private float getNextFloat(float def) /* */ { /* 273 */ String s = this.tempParseStr; /* */ /* 275 */ int end = this.tempParseStr.indexOf(','); /* 276 */ if (end == -1) /* */ { /* 278 */ end = this.tempParseStr.length(); /* 279 */ this.tempParseStr = ""; /* */ } else { /* 281 */ this.tempParseStr = this.tempParseStr.substring(end + 1); /* */ } /* */ try { /* 284 */ return Float.valueOf(s.substring(0, end)).floatValue(); /* */ } /* */ catch (NumberFormatException ex) {} /* 287 */ return def; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ private String setFromURL(String url) /* */ { /* 297 */ this.useDefCoordinates = true; /* */ /* 299 */ int roomNameStart = url.lastIndexOf('#'); /* 300 */ if (roomNameStart >= 0) { /* 301 */ String rest = url.substring(roomNameStart + 1); /* 302 */ url = url.substring(0, roomNameStart); /* */ /* 304 */ int roomNameEnd = rest.lastIndexOf('@'); /* 305 */ if (roomNameEnd < 0) { /* 306 */ this.targetRoomName = rest; /* */ } /* */ else { /* 309 */ this.useDefCoordinates = false; /* */ /* 311 */ this.targetRoomName = rest.substring(0, roomNameEnd); /* */ /* 313 */ this.tempParseStr = rest.substring(roomNameEnd + 1); /* */ /* 315 */ this.targetCoords.x = getNextFloat(this.targetCoords.x); /* 316 */ this.targetCoords.y = getNextFloat(this.targetCoords.y); /* 317 */ this.targetCoords.z = getNextFloat(this.targetCoords.z); /* 318 */ this.targetRot = getNextFloat(this.targetRot); /* 319 */ this.targetAxis.x = getNextFloat(this.targetAxis.x); /* 320 */ this.targetAxis.y = getNextFloat(this.targetAxis.y); /* 321 */ this.targetAxis.z = getNextFloat(this.targetAxis.z); /* */ /* 323 */ this.tempParseStr = null; /* */ } /* */ } /* */ /* */ /* 328 */ if (this.targetRoomName != null) { /* 329 */ int rightAngle = this.targetRoomName.lastIndexOf('>'); /* 330 */ int leftAngle = this.targetRoomName.lastIndexOf('<'); /* 331 */ if ((rightAngle + 1 == this.targetRoomName.length()) && (leftAngle >= 0)) { /* 332 */ this.targetDimension = this.targetRoomName.substring(leftAngle + 1, /* 333 */ rightAngle); /* 334 */ this.targetRoomName = this.targetRoomName.substring(0, leftAngle); /* */ } /* */ } /* 337 */ return url; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private void makeTeleportDialog(URL url) /* */ { /* 351 */ if (this.showDialog) { /* 352 */ Frame gf = Console.getFrame(); /* */ /* */ /* 355 */ if ((gf != null) && (gf.isShowing())) { /* 356 */ this.dialog = new TeleportDialog(gf, this); /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ private void startTeleport() /* */ { /* 366 */ if (activeTeleport != null) { /* 367 */ if (activeTeleport.doneCallback != null) /* 368 */ activeTeleport.doneCallback.teleportStatus( /* 369 */ "overridden by new teleport", activeTeleport.targetURL); /* 370 */ activeTeleport.stopTeleport(null); /* */ } /* 372 */ activeTeleport = this; /* 373 */ Console.setFreezeFrameEvents(true); /* 374 */ this.done = false; /* */ /* */ /* 377 */ Console.teleportNotification("", this.targetURL); /* 378 */ if (this.targetWorldURL != null) { /* 379 */ makeTeleportDialog(this.targetWorldURL); /* 380 */ World.load(this.targetWorldURL, this, this.forceWorldLoad); /* */ } else { /* 382 */ Pilot pilot = Pilot.getActive(); /* */ World w; /* 384 */ if ((pilot == null) || ((w = pilot.getWorld()) == null)) { /* 385 */ stopTeleport("Pilot not in a room for intraworld teleport"); /* */ } else { World w; /* 387 */ makeTeleportDialog(w.getSourceURL()); /* 388 */ loadedURLSelf(w, this.targetWorldURL, null); /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private Room stopTeleport(String err) /* */ { /* 402 */ assert (this == activeTeleport); /* */ /* 404 */ this.done = true; /* 405 */ activeTeleport = null; /* 406 */ Console.setFreezeFrameEvents(false); /* */ /* 408 */ if (this.doneCallback != null) { /* 409 */ this.doneCallback.teleportStatus(err, this.targetURL); /* */ } /* 411 */ if ((err != null) && (!this.forceNoWorldLoad)) /* */ { /* 413 */ Console.teleportNotification(err, this.targetURL); /* */ /* 415 */ Console.println(err); /* */ } /* */ /* 418 */ if (this.dialog != null) { /* 419 */ this.dialog.closeIt(true); /* 420 */ this.dialog = null; /* */ } /* */ /* 423 */ return null; /* */ } /* */ /* */ public synchronized void dialogDone(Object who, boolean confirmed) { /* 427 */ if (activeTeleport != null) /* 428 */ activeTeleport.stopTeleport(null); /* */ } /* */ /* */ public static String getReadableNameOfWorld(URL url) { /* 432 */ String worldDir = url.getAbsolute(); /* */ /* 434 */ String readable = worldDir; /* 435 */ String packageName = null; /* 436 */ if ((readable.startsWith("home:")) && (readable.length() > 6)) { /* 437 */ readable = readable.substring(readable.charAt(5) == '/' ? 6 : 5); /* 438 */ int slash = readable.indexOf('/'); /* 439 */ if (slash > 0) { /* 440 */ packageName = readable.substring(0, slash); /* */ /* */ /* 443 */ if (readable.regionMatches(true, slash + 1, readable, 0, slash)) /* */ { /* 445 */ readable = packageName; /* */ /* 447 */ String s = WorldsMarkPart.getExternalName(readable); /* 448 */ if (s != null) { /* 449 */ readable = s; /* */ } /* */ } /* */ } /* 453 */ int tail = readable.indexOf(".world"); /* 454 */ if (tail > 0) { /* 455 */ readable = readable.substring(0, tail); /* */ } /* 457 */ readable = "the " + readable + " world"; /* */ } /* */ /* 460 */ return readable; /* */ } /* */ /* */ public static String getPackageNameOfWorld(URL url) { /* 464 */ String worldDir = url.getAbsolute(); /* */ /* 466 */ String readable = worldDir; /* 467 */ String packageName = null; /* 468 */ if ((readable.startsWith("home:")) && (readable.length() > 6)) { /* 469 */ readable = readable.substring(readable.charAt(5) == '/' ? 6 : 5); /* 470 */ int slash = readable.indexOf('/'); /* 471 */ if (slash > 0) { /* 472 */ packageName = readable.substring(0, slash); /* */ } /* */ } /* 475 */ return packageName; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void loadedURLSelf(URLSelf o, URL url, String err) /* */ { /* 485 */ if (activeTeleport != this) { /* 486 */ if (o != null) /* 487 */ o.decRef(); /* 488 */ return; /* */ } /* */ /* 491 */ if ((err != null) || (!(o instanceof World))) { /* 492 */ if (err == null) { /* 493 */ err = "file " + url + " doesn't contain a World"; /* 494 */ o.decRef(); /* */ } /* */ /* */ /* */ /* 499 */ String readable = getReadableNameOfWorld(url); /* 500 */ String packageName = getPackageNameOfWorld(url); /* */ /* 502 */ Object[] arguments = { new String(readable) }; /* 503 */ stopTeleport(MessageFormat.format(Console.message("cant-teleport"), arguments)); /* */ /* */ /* 506 */ if ((packageName != null) && (!this.forceNoWorldLoad)) /* 507 */ NetUpdate.loadWorld(packageName, this.forceWorldLoad); /* 508 */ return; /* */ } /* */ /* 511 */ String roomName = this.targetRoomName; /* 512 */ if (roomName == null) { /* 513 */ roomName = ((World)o).getDefaultRoomName(); /* */ } /* 515 */ Room room = ((World)o).getRoom(roomName); /* 516 */ if (room == null) { /* 517 */ stopTeleport("Error finding room " + this.targetRoomName); /* 518 */ return; /* */ } /* */ /* 521 */ if ((room.getVIPOnly()) && (!((World)o).getConsole().getVIP())) /* */ { /* 523 */ stopTeleport("Only VIPs may go there."); /* 524 */ if (this.forceNoWorldLoad) /* 525 */ Console.println(Console.message("Only-VIPs-there")); /* 526 */ return; /* */ } /* */ /* */ /* 530 */ Console.teleportNotification(null, this.targetURL); /* */ /* */ /* */ /* 534 */ Pilot pilot = Pilot.changeActiveRoom(room); /* */ /* */ /* 537 */ if (this.targetDimension != null) { /* 538 */ pilot.changeChannel(this.targetDimension); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 547 */ pilot.makeIdentity(); /* */ /* 549 */ if (this.useDefCoordinates) /* */ { /* 551 */ pilot.moveTo(room.getDefaultPosition()).spin(room.getDefaultOrientationAxis(), /* 552 */ room.getDefaultOrientation()); /* */ } else { /* 554 */ pilot.moveTo(this.targetCoords).spin(this.targetAxis, this.targetRot); /* */ } /* 556 */ stopTeleport(null); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 566 */ Object ret = null; /* 567 */ switch (index - offset) { /* */ case 0: /* 569 */ if (mode == 0) { /* 570 */ ret = Point3PropertyEditor.make(new Property(this, index, /* 571 */ "X, Y, Z")); /* 572 */ } else if (mode == 1) { /* 573 */ ret = new Point3(this.targetCoords); /* 574 */ } else if (mode == 2) { /* 575 */ this.targetCoords.copy((Point3)value); /* */ } /* 577 */ break; /* */ case 1: /* 579 */ if (mode == 0) { /* 580 */ ret = FloatPropertyEditor.make( /* 581 */ new Property(this, index, "Dir")); /* 582 */ } else if (mode == 1) { /* 583 */ ret = new Float(this.targetRot); /* 584 */ } else if (mode == 2) /* 585 */ this.targetRot = ((Float)value).floatValue(); /* 586 */ break; /* */ case 2: /* 588 */ if (mode == 0) { /* 589 */ ret = StringPropertyEditor.make( /* 590 */ new Property(this, index, "Room Name") /* 591 */ .allowSetNull()); /* 592 */ } else if (mode == 1) { /* 593 */ if (this.targetRoomName == null) { /* 594 */ ret = ""; /* */ } else /* 596 */ ret = new String(this.targetRoomName); /* 597 */ } else if (mode == 2) { /* 598 */ this.targetRoomName = ((String)value); /* 599 */ stopLoading(); /* */ } /* 601 */ break; /* */ case 3: /* 603 */ if (mode == 0) { /* 604 */ ret = URLPropertyEditor.make( /* 605 */ new Property(this, index, "World URL").allowSetNull(), /* 606 */ "world"); /* 607 */ } else if (mode == 1) { /* 608 */ ret = this.targetWorldURL; /* 609 */ } else if (mode == 2) { /* 610 */ this.targetWorldURL = ((URL)value); /* */ /* */ /* */ /* 614 */ stopLoading(); /* */ } /* 616 */ break; /* */ case 4: /* 618 */ if (mode == 0) { /* 619 */ ret = BooleanPropertyEditor.make( /* 620 */ new Property(this, index, "Use default coordinates"), /* 621 */ "No", "Yes"); /* 622 */ } else if (mode == 1) { /* 623 */ ret = new Boolean(this.useDefCoordinates); /* 624 */ } else if (mode == 2) { /* 625 */ this.useDefCoordinates = ((Boolean)value).booleanValue(); /* */ } /* 627 */ break; /* */ case 5: /* 629 */ if (mode == 0) { /* 630 */ ret = StringPropertyEditor.make( /* 631 */ new Property(this, index, "Dimension Name") /* 632 */ .allowSetNull()); /* 633 */ } else if (mode == 1) { /* 634 */ if (this.targetDimension == null) { /* 635 */ ret = ""; /* */ } else /* 637 */ ret = new String(this.targetDimension); /* 638 */ } else if (mode == 2) { /* 639 */ this.targetDimension = ((String)value); /* 640 */ if (this.targetDimension.equals("")) /* 641 */ this.targetDimension = null; /* 642 */ stopLoading(); /* */ } /* 644 */ break; /* */ case 6: /* 646 */ if (mode == 0) { /* 647 */ ret = BooleanPropertyEditor.make( /* 648 */ new Property(this, index, "Show dialog"), /* 649 */ "No", "Yes"); /* 650 */ } else if (mode == 1) { /* 651 */ ret = new Boolean(this.showDialog); /* 652 */ } else if (mode == 2) { /* 653 */ this.showDialog = ((Boolean)value).booleanValue(); /* */ } /* 655 */ break; /* */ default: /* 657 */ ret = super.properties(index, offset + 7, mode, value); /* */ } /* 659 */ return ret; /* */ } /* */ /* */ /* */ /* 664 */ private static Object classCookie = new Object(); /* */ /* */ public void saveState(Saver s) throws IOException /* */ { /* 668 */ s.saveVersion(3, classCookie); /* 669 */ super.saveState(s); /* */ /* 671 */ s.save(this.targetCoords); /* 672 */ s.saveFloat(this.targetRot); /* 673 */ s.save(this.targetAxis); /* 674 */ s.saveString(this.targetRoomName); /* 675 */ URL.save(s, this.targetWorldURL); /* 676 */ s.saveBoolean(this.useDefCoordinates); /* 677 */ s.saveString(this.targetDimension); /* */ } /* */ /* */ public void restoreState(Restorer r) throws IOException, TooNewException /* */ { /* 682 */ int vers = r.restoreVersion(classCookie); /* 683 */ switch (vers) { /* */ case 0: /* 685 */ super.restoreState(r); /* 686 */ this.targetCoords = ((Point3)r.restore()); /* 687 */ this.targetRot = r.restoreInt(); /* 688 */ this.targetRoomName = r.restoreString(); /* 689 */ this.targetWorldURL = URL.restore(r, ".world"); /* 690 */ this.useDefCoordinates = r.restoreBoolean(); /* 691 */ this.targetDimension = null; /* 692 */ break; /* */ /* */ case 1: /* */ case 2: /* 696 */ super.restoreState(r); /* 697 */ this.targetCoords = ((Point3)r.restore()); /* 698 */ this.targetRot = r.restoreFloat(); /* 699 */ this.targetAxis = ((Point3)r.restore()); /* 700 */ this.targetRoomName = r.restoreString(); /* 701 */ this.targetWorldURL = URL.restore(r, ".world"); /* 702 */ this.useDefCoordinates = r.restoreBoolean(); /* 703 */ this.targetDimension = null; /* 704 */ break; /* */ case 3: /* 706 */ super.restoreState(r); /* 707 */ this.targetCoords = ((Point3)r.restore()); /* 708 */ this.targetRot = r.restoreFloat(); /* 709 */ this.targetAxis = ((Point3)r.restore()); /* 710 */ this.targetRoomName = r.restoreString(); /* 711 */ this.targetWorldURL = URL.restore(r, ".world"); /* 712 */ this.useDefCoordinates = r.restoreBoolean(); /* 713 */ this.targetDimension = r.restoreString(); /* 714 */ break; /* */ /* */ default: /* 717 */ throw new TooNewException(); /* */ } /* */ /* 720 */ if ((vers < 2) && /* 721 */ (this.targetAxis.x == 0.0F) && (this.targetAxis.y == 0.0F) && (this.targetAxis.z == 1.0F)) /* */ { /* 723 */ this.targetAxis.z = -1.0F; /* 724 */ this.targetRot = (360.0F - this.targetRot); /* */ } /* */ } /* */ /* */ public String toString() /* */ { /* 730 */ return super.toString() + "[" + asURL() + "]"; /* */ } /* */ /* */ public String asURL() { /* */ String url; /* */ String url; /* 736 */ if (this.targetWorldURL != null) { /* 737 */ url = this.targetWorldURL.getRelativeTo(this) + "#"; /* */ } else { /* 739 */ url = "#"; /* */ } /* 741 */ if (this.targetRoomName != null) /* 742 */ url = url + this.targetRoomName; /* 743 */ if (this.targetDimension != null) { /* 744 */ url = url + "<" + this.targetDimension + ">"; /* */ } /* 746 */ if (!this.useDefCoordinates) /* */ { /* 748 */ url = url + "@" + this.targetCoords + "," + this.targetRot; /* 749 */ if ((this.targetAxis.x != 0.0F) || (this.targetAxis.y != 0.0F) || (this.targetAxis.z != 1.0F)) { /* 750 */ url = url + "," + this.targetAxis; /* */ } /* */ } /* 753 */ return url; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\TeleportAction.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */