Ejemplo n.º 1
0
 public void doMalfunction(Location l) {
   HashMap<String, Object> where = new HashMap<String, Object>();
   where.put("tardis_id", id);
   ResultSetLamps rsl = new ResultSetLamps(plugin, where, true);
   List<Block> lamps = new ArrayList<Block>();
   if (rsl.resultSet()) {
     // flicker lights
     ArrayList<HashMap<String, String>> data = rsl.getData();
     for (HashMap<String, String> map : data) {
       Location loc = plugin.utils.getLocationFromDB(map.get("location"), 0.0F, 0.0F);
       lamps.add(loc.getBlock());
     }
     if (plugin.pm.isPluginEnabled("Citizens")
         && plugin.getConfig().getBoolean("allow.emergency_npc")) {
       // get player prefs
       HashMap<String, Object> wherep = new HashMap<String, Object>();
       wherep.put("player", p.getName());
       ResultSetPlayerPrefs rsp = new ResultSetPlayerPrefs(plugin, wherep);
       if (rsp.resultSet() && rsp.isEpsOn()) {
         // schedule the NPC to appear
         String message =
             "This is Emergency Programme One. Now listen, this is important. If this message is activated, then it can only mean one thing: we must be in danger, and I mean fatal. You're about to die any second with no chance of escape.";
         HashMap<String, Object> wherev = new HashMap<String, Object>();
         wherev.put("tardis_id", id);
         ResultSetTravellers rst = new ResultSetTravellers(plugin, wherev, true);
         List<String> players;
         if (rst.resultSet()) {
           players = rst.getData();
         } else {
           players = new ArrayList<String>();
           players.add(p.getName());
         }
         TARDISEPSRunnable EPS_runnable =
             new TARDISEPSRunnable(plugin, message, p, players, id, eps, creeper);
         plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, EPS_runnable, 220L);
       }
     }
     final long start = System.currentTimeMillis() + 10000;
     TARDISLampsRunnable runnable = new TARDISLampsRunnable(plugin, lamps, start);
     runnable.setHandbrake(handbrake_loc);
     int taskID =
         plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, runnable, 10L, 10L);
     runnable.setTask(taskID);
   }
 }
 @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.º 3
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);
 }