Ejemplo n.º 1
0
  public void startFinished() {
    if (bets != null && !bets.isEmpty() && bets.size() > 0) {
      for (int i = 0; i < bets.size(); i++) {
        try {
          Bet b = bets.get(i);

          if (isTribute(server.getPlayer(b.tribute))) {
            addScore(b.better, b.wager / 4);
            addScore(b.tribute, b.wager / 4);
          } else {
            subtractScore(b.better, b.wager);
          }

          bets.remove(b);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    clearAll();
    load();
    bets.clear();

    state = State.DONE;
    game = new Finished(this);

    startTimer();
  }
Ejemplo n.º 2
0
 public static void setRenderDistance(World world, int distance) {
   try {
     ReflectionHelper.field("e")
         .in(ReflectionHelper.field("manager").in(((CraftWorld) world).getHandle()).get())
         .set(distance);
   } catch (Exception ignored) {
     ignored.printStackTrace();
   }
 }
Ejemplo n.º 3
0
  public void onDisable() {
    this.getLogger().info("Disabling Minecraftno plugin...");

    // Enable whitelist to stop players joining while we're shutting down.
    if (this.getConfig().getBoolean("whitelist.on_disable.toggle", false)) {
      this.getServer()
          .setWhitelist(this.getConfig().getBoolean("whitelist.on_disable.toggle", true));

      // Kick everyone who's already online before we start disabling functionality.
      // They're not supposed to be here anyway.
      for (Player player : this.getServer().getOnlinePlayers()) {
        player.kickPlayer(
            this.getConfig().getString("whitelist.message", "The server is shutting down..."));
      }
    }

    if (configuration.irc && bot.isConnected()) {
      this.getLogger().info(" - Disabling IRC bot...");
      bot.disconnect();
      bot.dispose();
    }

    this.getLogger().info(" - Handlers cleanup...");
    this.groupHandler.cleanup();
    this.userHandler.cleanup();

    try {
      configuration.cleanup();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (this.blockHandler != null) {
      if (this.blockHandler.getQueueSize() > 0) {
        this.getLogger().info(" - Waiting for block handler to finish...");

        try {
          Thread.sleep(3000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        this.blockHandler.run();
      }
    }

    if (sqlc != null) {
      this.getLogger().info(" - Closing SQL connection...");
      sqlc.close();
    }

    this.getLogger().info(" - Cancelling scheduled tasks...");
    getServer().getScheduler().cancelAllTasks();

    this.getLogger().info("Finished disabling Minecraftno plugin.");
  }
Ejemplo n.º 4
0
  public void onEnable() {
    // TODO: Place any custom enable code here including the registration of any events

    // Setup Plugin Member Variables
    server = getServer();
    log = server.getLogger();

    commandMap =
        new CommandsManager<Player>() {
          @Override
          public boolean hasPermission(Player player, String perm) {
            // TODO: Implement Permissions
            return true;
          }
        };

    dungeons = new HashMap<String, Dungeon>();
    editSessions = new HashMap<Player, EditSession>();

    PluginManager pm = getServer().getPluginManager();

    try {
      // Register our events
      pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
      pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
      pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
      pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this);
      pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);

    } catch (Exception e) {

      log.info("Exception while registering events.");
      log.info(e.getMessage());
    }

    try {

      // Setup PlayerListener class to preprocess command events
      pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this);
      pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);

      // Register Commands to the command map
      commandMap.register(LairDungeonCommand.class);

    } catch (Exception e) {

      log.info("Exception Registering Commands: ");
      log.info(e.getMessage());
    }

    // Say Hello
    log.info("Legends.Lair Hello!");
  }
Ejemplo n.º 5
0
  static {
    try {
      Plugin wgp = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
      hasWG = wgp != null; // Short and sweet
      if (hasWG) wg = (WorldGuardPlugin) wgp;
      hasResidence = Bukkit.getServer().getPluginManager().getPlugin("Residence") != null;
      log = Storm.instance.getLogger();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
 /*
  * Сохранение сообщений в файл
  */
 public void SaveMSG() {
   String[] keys = this.msglist.split(",");
   try {
     File f = new File(plg.getDataFolder() + File.separator + this.language + ".lng");
     if (!f.exists()) f.createNewFile();
     YamlConfiguration cfg = new YamlConfiguration();
     for (int i = 0; i < keys.length; i++) cfg.set(keys[i], msg.get(keys[i]));
     cfg.save(f);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 7
0
  public static boolean save() {
    // Factions.log("Saving config to disk.");

    try {
      DiscUtil.write(file, Factions.gson.toJson(new Conf()));
    } catch (Exception e) {
      e.printStackTrace();
      Factions.log("Failed to save the config to disk.");
      return false;
    }
    return true;
  }
Ejemplo n.º 8
0
 public boolean renameFileOrFolder(String oldName, String newName) {
   File f;
   if ((f = new File(oldName)).exists()) {
     try {
       return f.renameTo(new File(newName));
     } catch (Exception e) {
       e.printStackTrace();
       return false;
     }
   } else {
     return false;
   }
 }
Ejemplo n.º 9
0
 /*
  *  Инициализация файла с сообщениями
  */
 public void InitMsgFile() {
   try {
     lng = new YamlConfiguration();
     File f = new File(plg.getDataFolder() + File.separator + this.language + ".lng");
     if (f.exists()) lng.load(f);
     else {
       InputStream is = plg.getClass().getResourceAsStream("/language/" + this.language + ".lng");
       if (is != null) lng.load(is);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 10
0
 public boolean deleteFileOrFolder(String fileName) {
   File f;
   if ((f = new File(fileName)).exists()) {
     try {
       if (f.isDirectory()) {
         return deleteDirectory(f);
       } else {
         return f.delete();
       }
     } catch (Exception e) {
       e.printStackTrace();
       return false;
     }
   } else {
     return false;
   }
 }
Ejemplo n.º 11
0
 static {
   ParticleUtils.version = "";
   try {
     ParticleUtils.version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
     ParticleUtils.packetType = Class.forName(getPacketPlayOutParticles());
     final Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
     final Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
     final Class<?> typePlayerConnection = Class.forName(getPlayerConnectionClasspath());
     ParticleUtils.getHandle = typeCraftPlayer.getMethod("getHandle", (Class<?>[]) new Class[0]);
     ParticleUtils.playerConnection = typeNMSPlayer.getField("playerConnection");
     ParticleUtils.sendPacket =
         typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath()));
   } catch (Exception e) {
     System.out.println("Failed to setup reflection for PacketPlayOutWorldParticles");
     e.printStackTrace();
   }
 }
Ejemplo n.º 12
0
  public Connection getConnection() {
    try {
      final Connection conn = sqlc.getConnection();

      if (!sqlConnected && conn != null) {
        this.getLogger().info("SQL connection re-established.");
        sqlConnected = true;
      }

      return conn;
    } catch (final Exception e) {
      sqlConnected = false;

      this.getLogger().severe("Could not fetch SQL connection! " + e.getMessage());

      return null;
    }
  }
Ejemplo n.º 13
0
  public static boolean load() {
    Factions.log("Loading conf from disk");

    if (!file.exists()) {
      Factions.log("No conf to load from disk. Creating new file.");
      save();
      return true;
    }

    try {
      Factions.gson.fromJson(DiscUtil.read(file), Conf.class);
    } catch (Exception e) {
      e.printStackTrace();
      Factions.log("Failed to load the config from disk.");
      return false;
    }

    return true;
  }
Ejemplo n.º 14
0
 PerformResult perform() throws WorldEditorException {
   if (dontRollback.contains(replaced)) return PerformResult.BLACKLISTED;
   final Block block = loc.getBlock();
   if (replaced == 0 && block.getTypeId() == 0) return PerformResult.NO_ACTION;
   final BlockState state = block.getState();
   if (!world.isChunkLoaded(block.getChunk())) world.loadChunk(block.getChunk());
   if (type == replaced) {
     if (type == 0) {
       if (!block.setTypeId(0))
         throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
     } else if (ca != null && (type == 23 || type == 54 || type == 61 || type == 62)) {
       int leftover = 0;
       try {
         leftover =
             modifyContainer(
                 state, new ItemStack(ca.itemType, -ca.itemAmount, (short) 0, ca.itemData));
         if (leftover > 0)
           for (final BlockFace face :
               new BlockFace[] {
                 BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST
               })
             if (block.getRelative(face).getTypeId() == 54)
               leftover =
                   modifyContainer(
                       block.getRelative(face).getState(),
                       new ItemStack(
                           ca.itemType,
                           ca.itemAmount < 0 ? leftover : -leftover,
                           (short) 0,
                           ca.itemData));
       } catch (final Exception ex) {
         throw new WorldEditorException(ex.getMessage(), block.getLocation());
       }
       if (!state.update())
         throw new WorldEditorException(
             "Failed to update inventory of " + materialName(block.getTypeId()),
             block.getLocation());
       if (leftover > 0 && ca.itemAmount < 0)
         throw new WorldEditorException(
             "Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
     } else return PerformResult.NO_ACTION;
     return PerformResult.SUCCESS;
   }
   if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId())))
     return PerformResult.NO_ACTION;
   if (state instanceof InventoryHolder) {
     ((InventoryHolder) state).getInventory().clear();
     state.update();
   }
   if (block.getTypeId() == replaced) {
     if (block.getData() != (type == 0 ? data : (byte) 0))
       block.setData(type == 0 ? data : (byte) 0, true);
     else return PerformResult.NO_ACTION;
   } else if (!block.setTypeIdAndData(replaced, type == 0 ? data : (byte) 0, true))
     throw new WorldEditorException(block.getTypeId(), replaced, block.getLocation());
   final int curtype = block.getTypeId();
   if (signtext != null && (curtype == 63 || curtype == 68)) {
     final Sign sign = (Sign) block.getState();
     final String[] lines = signtext.split("\0", 4);
     if (lines.length < 4) return PerformResult.NO_ACTION;
     for (int i = 0; i < 4; i++) sign.setLine(i, lines[i]);
     if (!sign.update())
       throw new WorldEditorException(
           "Failed to update signtext of " + materialName(block.getTypeId()),
           block.getLocation());
   } else if (curtype == 26) {
     final Bed bed = (Bed) block.getState().getData();
     final Block secBlock =
         bed.isHeadOfBed()
             ? block.getRelative(bed.getFacing().getOppositeFace())
             : block.getRelative(bed.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(26, (byte) (bed.getData() | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), 26, secBlock.getLocation());
   } else if (curtype == 64 || curtype == 71) {
     final byte blockData = block.getData();
     final Block secBlock =
         (blockData & 8) == 8
             ? block.getRelative(BlockFace.DOWN)
             : block.getRelative(BlockFace.UP);
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(curtype, (byte) (blockData | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), curtype, secBlock.getLocation());
   } else if ((curtype == 29 || curtype == 33) && (block.getData() & 8) > 0) {
     final PistonBaseMaterial piston = (PistonBaseMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             34,
             curtype == 29 ? (byte) (block.getData() | 8) : (byte) (block.getData() & ~8),
             true))
       throw new WorldEditorException(secBlock.getTypeId(), 34, secBlock.getLocation());
   } else if (curtype == 34) {
     final PistonExtensionMaterial piston = (PistonExtensionMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing().getOppositeFace());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             piston.isSticky() ? 29 : 33, (byte) (block.getData() | 8), true))
       throw new WorldEditorException(
           secBlock.getTypeId(), piston.isSticky() ? 29 : 33, secBlock.getLocation());
   } else if (curtype == 18 && (block.getData() & 8) > 0)
     block.setData((byte) (block.getData() & 0xF7));
   return PerformResult.SUCCESS;
 }
Ejemplo n.º 15
0
  public void onEnable() {
    hardwork.onEnable();

    // Use the default Bukkit logger.
    // Previous log handler is no longer needed, as "Overloaded!" messages can be disabled in
    // config.
    Minecraftno.log = this.getLogger();
    Minecraftno.debugLog = this.getLogger();

    this.getLogger().info("Loading native Bukkit configuration...");
    this.saveDefaultConfig();
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();

    this.getLogger().info("Loading custom configuration...");
    try {
      this.configuration.load();
    } catch (Exception e) {
      e.printStackTrace();
    }

    this.getLogger().info("Enabling Minecraftno plugin...");

    this.getLogger().info(" - Enabling IRC bot...");
    bot.ircBot();

    this.getLogger().info(" - Binding to events...");
    registerEvents();

    this.getLogger().info(" - Connecting to SQL server...");
    if (!sqlConnection()) {
      return;
    }

    this.getLogger().info(" - Initializing handlers...");
    this.userHandler.initialise();
    this.bankHandler.initialise();
    this.weBridge.initialise();
    this.worldHandler.initialise();
    this.sandtakHandler.initialise();

    this.getLogger().info(" - Initializing handlers, part 2...");
    // this.afkkickhandler.reloadAllAfk();
    this.userHandler.reloadUsers();
    this.startupHandler.weather();
    this.startupHandler.checkSpace();
    this.groupHandler.getAllGroups();

    this.getLogger().info(" - Scheduling tasks...");
    new WorldBackup(this).scheduleWorldBackup();
    new ServerLogBackup(this).scheduleServerLogBackup();
    new SpawnProtection(this).scheduleSpawnProtection();

    if (getServer()
            .getScheduler()
            .runTaskTimerAsynchronously(this, this.blockHandler, 20, 20)
            .getTaskId()
        > 0) {
      this.getLogger().info("Scheduled start up.");
    } else {
      this.getLogger().info("Scheduled failed. Starting now manualy.");
      timer = new Timer();
      timer.scheduleAtFixedRate(this.blockHandler, 1000, 1000);
    }

    this.getLogger().info(" - Enabling custom recipes...");
    new RecipeHandler(this).registerRecipes();

    this.getLogger().info(" - Registering commands...");
    registerCommands();

    // Enable or disable whitelist on plugin load.
    // Enable whitelist in server.properties to ensures nobody
    // can join the server until we're really ready for it.
    if (this.getConfig().getBoolean("whitelist.on_enable.toggle", false)) {
      this.getServer()
          .setWhitelist(this.getConfig().getBoolean("whitelist.on_enable.state", false));
    }

    this.getLogger().info("Finished enabling Minecraftno plugin.");
  }