@SuppressWarnings("deprecation")
 private byte getWoolColour(int id, PRESET p) {
   HashMap<String, Object> where = new HashMap<String, Object>();
   where.put("tardis_id", id);
   where.put("door_type", 0);
   ResultSetDoors rs = new ResultSetDoors(plugin, where, false);
   if (rs.resultSet()) {
     Block b = plugin.getUtils().getLocationFromDB(rs.getDoor_location(), 0.0F, 0.0F).getBlock();
     if (p.equals(PRESET.FLOWER)) {
       return b.getRelative(BlockFace.UP, 3).getData();
     } else {
       for (BlockFace f : plugin.getGeneralKeeper().getFaces()) {
         if (b.getRelative(f).getType().equals(Material.WOOL)) {
           return b.getRelative(f).getData();
         }
       }
     }
   }
   return (byte) 0;
 }
 public boolean doAbandon(CommandSender sender, boolean list) {
   if (sender.hasPermission("tardis.abandon")
       && plugin.getConfig().getBoolean("abandon.enabled")) {
     if (list) {
       // list abandoned TARDISes
       if (sender.hasPermission("tardis.admin")) {
         new TARDISAbandonLister(plugin).list(sender);
         return true;
       } else {
         TARDISMessage.send(sender, "NO_PERMS");
       }
     } else {
       // must be a Player
       Player player = null;
       if (sender instanceof Player) {
         player = (Player) sender;
       }
       if (player == null) {
         TARDISMessage.send(sender, "CMD_NO_CONSOLE");
         return true;
       }
       if (!plugin.getConfig().getBoolean("allow.power_down")) {
         TARDISMessage.send(sender, "ABANDON_POWER_DOWN");
         return true;
       }
       // abandon TARDIS
       ResultSetTardisAbandoned rs = new ResultSetTardisAbandoned(plugin);
       if (!rs.fromUUID(player.getUniqueId().toString())) {
         TARDISMessage.send(player, "NO_TARDIS");
         return true;
       } else {
         PRESET preset = rs.getPreset();
         // need to be in tardis
         HashMap<String, Object> where = new HashMap<String, Object>();
         where.put("uuid", player.getUniqueId().toString());
         ResultSetTravellers rst = new ResultSetTravellers(plugin, where, false);
         if (!rst.resultSet()) {
           TARDISMessage.send(player, "NOT_IN_TARDIS");
           return true;
         }
         if (preset.equals(PRESET.JUNK_MODE)) {
           TARDISMessage.send(player, "ABANDONED_NOT_JUNK");
           return true;
         }
         int id = rs.getTardis_id();
         if (rst.getTardis_id() != id) {
           TARDISMessage.send(player, "ABANDONED_OWN");
           return true;
         }
         if (!rs.isTardis_init()) {
           TARDISMessage.send(player, "ENERGY_NO_INIT");
           return true;
         }
         if (!rs.isHandbrake_on()) {
           TARDISMessage.send(player, "HANDBRAKE_ENGAGE");
           return true;
         }
         if (plugin.getTrackerKeeper().getDestinationVortex().containsKey(id)) {
           TARDISMessage.send(player, "NOT_IN_VORTEX");
           return true;
         }
         new TARDISAbandonUpdate(plugin, id, player.getUniqueId().toString()).run();
         if (rs.isPowered_on()) {
           // power down TARDIS
           new TARDISPowerButton(
                   plugin,
                   id,
                   player,
                   rs.getPreset(),
                   rs.isPowered_on(),
                   rs.isHidden(),
                   rs.isLights_on(),
                   player.getLocation(),
                   rs.getArtron_level(),
                   rs.getSchematic().hasLanterns())
               .clickButton();
         }
         // close the door
         new TARDISDoorCloser(plugin, player.getUniqueId(), id).closeDoors();
         TARDISMessage.send(player, "ABANDONED_SUCCESS");
         // clear sign
         if (plugin.getConfig().getBoolean("police_box.name_tardis")) {
           HashMap<String, Object> wherec = new HashMap<String, Object>();
           wherec.put("tardis_id", id);
           ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherec);
           if (rsc.resultSet()) {
             Location current = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ());
             Sign sign = getSign(current, rsc.getDirection(), preset);
             if (sign != null) {
               switch (preset) {
                 case GRAVESTONE:
                   sign.setLine(3, "");
                   break;
                 case ANGEL:
                 case JAIL:
                   sign.setLine(2, "");
                   break;
                 default:
                   sign.setLine(0, "");
                   break;
               }
               sign.update();
             }
           }
         }
       }
     }
   } else {
     TARDISMessage.send(sender, "NO_PERMS_ABANDON");
   }
   return true;
 }
 @Override
 public void run() {
   int[][] ids;
   byte[][] datas;
   // get relative locations
   int x = tmd.getLocation().getBlockX(),
       plusx = tmd.getLocation().getBlockX() + 1,
       minusx = tmd.getLocation().getBlockX() - 1;
   int y;
   if (preset.equals(PRESET.SUBMERGED)) {
     y = tmd.getLocation().getBlockY() - 1;
   } else {
     y = tmd.getLocation().getBlockY();
   }
   int z = tmd.getLocation().getBlockZ(),
       plusz = tmd.getLocation().getBlockZ() + 1,
       minusz = tmd.getLocation().getBlockZ() - 1;
   World world = tmd.getLocation().getWorld();
   if (i < loops) {
     i++;
     // expand placed blocks to a police box
     switch (i % 3) {
       case 2: // stained
         ids = stained_column.getId();
         datas = stained_column.getData();
         break;
       case 1: // glass
         ids = glass_column.getId();
         datas = glass_column.getData();
         break;
       default: // preset
         ids = column.getId();
         datas = column.getData();
         break;
     }
     // first run - play sound
     if (i == 1) {
       switch (preset) {
         case GRAVESTONE:
           // remove flower
           int flowerx;
           int flowery = (tmd.getLocation().getBlockY() + 1);
           int flowerz;
           switch (tmd.getDirection()) {
             case NORTH:
               flowerx = tmd.getLocation().getBlockX();
               flowerz = tmd.getLocation().getBlockZ() + 1;
               break;
             case WEST:
               flowerx = tmd.getLocation().getBlockX() + 1;
               flowerz = tmd.getLocation().getBlockZ();
               break;
             case SOUTH:
               flowerx = tmd.getLocation().getBlockX();
               flowerz = tmd.getLocation().getBlockZ() - 1;
               break;
             default:
               flowerx = tmd.getLocation().getBlockX() - 1;
               flowerz = tmd.getLocation().getBlockZ();
               break;
           }
           plugin.getUtils().setBlock(world, flowerx, flowery, flowerz, 0, (byte) 0);
           break;
         case CAKE:
           plugin.getPresetDestroyer().destroyLamp(tmd.getLocation(), preset);
           break;
         default:
           break;
       }
       // only play the sound if the player is outside the TARDIS
       if (tmd.isOutside()) {
         HashMap<String, Object> wherep = new HashMap<String, Object>();
         wherep.put("uuid", tmd.getPlayer().getUniqueId().toString());
         ResultSetPlayerPrefs rsp = new ResultSetPlayerPrefs(plugin, wherep);
         boolean minecart = false;
         if (rsp.resultSet()) {
           minecart = rsp.isMinecartOn();
         }
         if (!minecart) {
           plugin.getUtils().playTARDISSoundNearby(tmd.getLocation(), "tardis_takeoff");
         } else {
           world.playSound(tmd.getLocation(), Sound.MINECART_INSIDE, 1.0F, 0.0F);
         }
       }
       the_colour = getWoolColour(tmd.getTardisID(), preset);
     } else {
       // just change the walls
       int xx, zz;
       for (int n = 0; n < 9; n++) {
         int[] colids = ids[n];
         byte[] coldatas = datas[n];
         switch (n) {
           case 0:
             xx = minusx;
             zz = minusz;
             break;
           case 1:
             xx = x;
             zz = minusz;
             break;
           case 2:
             xx = plusx;
             zz = minusz;
             break;
           case 3:
             xx = plusx;
             zz = z;
             break;
           case 4:
             xx = plusx;
             zz = plusz;
             break;
           case 5:
             xx = x;
             zz = plusz;
             break;
           case 6:
             xx = minusx;
             zz = plusz;
             break;
           case 7:
             xx = minusx;
             zz = z;
             break;
           default:
             xx = x;
             zz = z;
             break;
         }
         for (int yy = 0; yy < 4; yy++) {
           boolean change = true;
           if (yy == 0 && n == 9) {
             Block rail = world.getBlockAt(xx, y, zz);
             if (rail.getType().equals(Material.RAILS)
                 || rail.getType().equals(Material.POWERED_RAIL)) {
               change = false;
             }
           }
           switch (colids[yy]) {
             case 2:
             case 3:
               int subi = (preset.equals(PRESET.SUBMERGED)) ? cham_id : colids[yy];
               byte subd = (preset.equals(PRESET.SUBMERGED)) ? cham_data : coldatas[yy];
               plugin.getUtils().setBlock(world, xx, (y + yy), zz, subi, subd);
               break;
             case 35: // wool
               int chai =
                   (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) ? cham_id : colids[yy];
               byte chad =
                   (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD))
                       ? cham_data
                       : coldatas[yy];
               if (preset.equals(PRESET.PARTY)
                   || (preset.equals(PRESET.FLOWER) && coldatas[yy] == 0)) {
                 chad = the_colour;
               }
               plugin.getUtils().setBlock(world, xx, (y + yy), zz, chai, chad);
               break;
             case 38:
               break;
             case 50: // lamps, glowstone and torches
             case 89:
             case 124:
               int light =
                   (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) ? lamp : colids[yy];
               plugin.getUtils().setBlock(world, xx, (y + yy), zz, light, coldatas[yy]);
               break;
             case 64:
             case 68: // except the sign and doors
             case 71:
               break;
             case 95:
               if (coldatas[yy] == -1) {
                 if (preset.equals(PRESET.PARTY)
                     || (preset.equals(PRESET.FLOWER) && coldatas[yy] == 0)) {
                   chad = the_colour;
                 } else {
                   // if it was a wool / stained glass / stained clay block get the data from that
                   int[] finalids = column.getId()[n];
                   byte[] finaldatas = column.getData()[n];
                   if (finalids[yy] == 35
                       || finalids[yy] == 95
                       || finalids[yy] == 159
                       || finalids[yy] == 160
                       || finalids[yy] == 171) {
                     if (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) {
                       chad = cham_data;
                     } else {
                       chad = finaldatas[yy];
                     }
                   } else {
                     chad =
                         plugin.getBuildKeeper().getStainedGlassLookup().getStain().get(cham_id);
                   }
                 }
                 plugin.getUtils().setBlock(world, xx, (y + yy), zz, 95, chad);
               } else {
                 plugin.getUtils().setBlock(world, xx, (y + yy), zz, colids[yy], coldatas[yy]);
               }
               break;
             default: // everything else
               if (change) {
                 plugin.getUtils().setBlock(world, xx, (y + yy), zz, colids[yy], coldatas[yy]);
               }
               break;
           }
         }
       }
     }
   } else {
     plugin.getServer().getScheduler().cancelTask(task);
     task = 0;
     new TARDISDeinstaPreset(plugin).instaDestroyPreset(tmd, false, preset);
   }
 }
Ejemplo n.º 4
0
 public void clickButton() {
   HashMap<String, Object> wherep = new HashMap<String, Object>();
   wherep.put("tardis_id", id);
   HashMap<String, Object> setp = new HashMap<String, Object>();
   if (powered) {
     if (isTravelling(id)) {
       TARDISMessage.send(player, "POWER_NO");
       return;
     }
     TARDISSounds.playTARDISSound(loc, player, "power_down");
     // power down
     setp.put("powered_on", 0);
     TARDISMessage.send(player, "POWER_OFF");
     long delay = 0;
     // if hidden, rebuild
     if (hidden) {
       plugin
           .getServer()
           .dispatchCommand(plugin.getConsole(), "tardisremote " + player.getName() + " rebuild");
       TARDISMessage.send(player, "POWER_FAIL");
       delay = 20L;
     }
     // police box lamp, delay it incase the TARDIS needs rebuilding
     if (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) {
       plugin
           .getServer()
           .getScheduler()
           .scheduleSyncDelayedTask(
               plugin,
               new Runnable() {
                 @Override
                 public void run() {
                   new TARDISPoliceBoxLampToggler(plugin).toggleLamp(id, false);
                 }
               },
               delay);
     }
     // if lights are on, turn them off
     if (lights) {
       new TARDISLampToggler(plugin).flickSwitch(id, player.getUniqueId(), true, lanterns);
     }
     // if beacon is on turn it off
     new TARDISBeaconToggler(plugin).flickSwitch(player.getUniqueId(), false);
   } else {
     // don't power up if there is no power
     if (level <= plugin.getArtronConfig().getInt("standby")) {
       TARDISMessage.send(player, "POWER_LOW");
       return;
     }
     TARDISSounds.playTARDISSound(loc, player, "power_up");
     // power up
     setp.put("powered_on", 1);
     TARDISMessage.send(player, "POWER_ON");
     // if lights are off, turn them on
     if (lights) {
       new TARDISLampToggler(plugin).flickSwitch(id, player.getUniqueId(), false, lanterns);
     }
     // determine beacon prefs
     HashMap<String, Object> wherek = new HashMap<String, Object>();
     wherek.put("uuid", player.getUniqueId().toString());
     ResultSetPlayerPrefs rsp = new ResultSetPlayerPrefs(plugin, wherek);
     boolean beacon_on = true;
     if (rsp.resultSet()) {
       beacon_on = rsp.isBeaconOn();
     }
     // if beacon is off turn it on
     if (beacon_on) {
       new TARDISBeaconToggler(plugin).flickSwitch(player.getUniqueId(), true);
     }
     // police box lamp
     if (preset.equals(PRESET.NEW) || preset.equals(PRESET.OLD)) {
       new TARDISPoliceBoxLampToggler(plugin).toggleLamp(id, true);
     }
   }
   new QueryFactory(plugin).doUpdate("tardis", setp, wherep);
 }