SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rs2hd.content;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6.  
  7. import com.rs2hd.model.Location;
  8. import com.rs2hd.model.Player;
  9. import com.rs2hd.model.World;
  10. import com.rs2hd.util.*;
  11.  
  12. public class DoorManager {
  13.    
  14.     public DoorManager() throws Throwable {
  15.         final XMLParser doorInstream = new XMLParser("./data/doors.xml");
  16.         doorInstream.setByElement("door");
  17.         for (int i = 0; i < doorInstream.getElements().size(); i++) {
  18.             final Map<String, String> element = doorInstream.getElements().get(i);
  19.             final int doorObject = doorInstream.getIntByTag(element,"doorObject");
  20.             final int absX = doorInstream.getIntByTag(element,"absoulteX");
  21.             final int absY = doorInstream.getIntByTag(element,"absoulteY");
  22.             final Direction direction = getDirection(doorInstream.getStringByTag(element,"direction"));
  23.             final Direction swivel = getDirection(doorInstream.getStringByTag(element,"swivelDirection"));
  24.             doorContainer.add(new Door(doorObject, absX, absY, direction, swivel));
  25.         }
  26.     }
  27.    
  28.     private List<Door> doorContainer = new ArrayList<Door>();
  29.    
  30.     public void swivelDoor(int absX, int absY) {
  31.         if(getDoor(absX, absY) == null) {
  32.             return;
  33.         }
  34.         getDoor(absX, absY).swivel();
  35.     }
  36.    
  37.     public Door getDoor(int absX, int absY) {
  38.         for(int i = 0; i < doorContainer.size(); i++) {
  39.             Door x = doorContainer.get(i);
  40.             if(x.getAbsX() == absX && x.getAbsY() == absY) {
  41.                 return x;
  42.             }
  43.         }
  44.         return null;
  45.     }
  46.    
  47.     public Direction getDirection(String direction) {
  48.         for(Direction x : Direction.values()) {
  49.             if(direction.equalsIgnoreCase(x.toString().split(" ")[0])) {
  50.                 return x;
  51.             }
  52.         }
  53.         return null;
  54.     }
  55.    
  56.     private class Door {
  57.        
  58.         private final int absX;
  59.         private final int absY;
  60.         private final int doorObject;
  61.         private final Direction baseDirection;
  62.         private final Direction switchDirection;
  63.         private Direction currentDirection;
  64.        
  65.         public Door(int doorObject, int absX, int absY, Direction baseDirection, Direction switchDirection) {
  66.             this.doorObject = doorObject;
  67.             this.absX = absX;
  68.             this.absY = absY;
  69.             this.currentDirection = baseDirection;
  70.             this.baseDirection = baseDirection;
  71.             this.switchDirection = switchDirection;
  72.         }
  73.        
  74.         public void swivel() {
  75.             currentDirection = currentDirection == baseDirection ? switchDirection : baseDirection;
  76.             for(Player globalPlayers : World.getInstance().getPlayerList()) {
  77.                 if(Math.round(globalPlayers.getLocation().getDistance(globalPlayers.getLocation())) <= 32) {
  78.                     RegionManager.sendObjects(globalPlayers);
  79.                 }
  80.             }
  81.             RegionManager.removeObject(Location.location(absX, absY, 0));
  82.             RegionManager.addObject(doorObject, currentDirection.getDirectionType(), 0, Location.location(absX, absY, 0));
  83.         }
  84.  
  85.         public int getAbsX() {
  86.             return absX;
  87.         }
  88.  
  89.         public int getAbsY() {
  90.             return absY;
  91.         }
  92.        
  93.     }
  94.  
  95. }
RAW Paste Data
Want to get better at Java?
Learn to code Java in 2017
Top