/** prints a message to the console when there is a draw */
  public void printDrawMessage() {
    ArrayList<Player> drawedPlayers = playerlist.returnDrawedPlayers();

    System.out.println("\n" + "There is a draw between the following players: ");
    for (Player currentP : playerlist.returnDrawedPlayers()) {
      System.out.println(currentP.getName());
    }

    System.out.println(
        "with each of them having a score of " + drawedPlayers.get(0).getScore() + "!");
  }
Exemplo n.º 2
0
 /** Adds a new player to the list of all players. Only does so if the name is unique and valid. */
 private void addPlayerPrompt() {
   Scanner console = new Scanner(System.in);
   System.out.println("----- [Set up a New Player] -----");
   System.out.println("Please enter your name:");
   String name = console.nextLine().trim();
   if (players.uniqueName(name)) {
     if (players.addPlayer(name, 0, 0)) // Checks if the name is valid.
     {
       currentPlayer = players.getSize() - 1;
       System.out.println("Player created!\n");
     }
     // Already an else if invalid name in the PlayerList class.
   } else System.out.println("Name already exists. Please try another.\n");
 }
Exemplo n.º 3
0
 /**
  * This method starts the Lucky Vending Machine. It will continue to display the game menu to the
  * player and prompt for input until the player wishes to exit the game.
  */
 public void playGame() {
   String input = "";
   String exitValue = "7";
   Scanner console = new Scanner(System.in);
   while (!input.equals(exitValue)) {
     displayMenu();
     System.out.print("> "); // Prompts for user input.
     input = console.nextLine();
     System.out.println(); // New line for readability.
     switch (input) {
       case "1":
         addPlayerPrompt();
         break;
       case "2":
         if (players.getSize() > 0) guessPrize();
         else System.out.println("No players set up.\n");
         break;
       case "3":
         if (players.getSize() > 0) {
           System.out.println("----- [Player Information] -----");
           players.getPlayer(currentPlayer).displayPlayer();
         } else System.out.println("No players set up.\n");
         break;
       case "4":
         players.displayTop();
         pressEnter();
         break;
       case "5":
         System.out.println("----- [Player Information] -----");
         players.displayPlayers();
         pressEnter();
         break;
       case "6":
         displayHelp();
         pressEnter();
         break;
       case "7":
         exitGame();
         break;
       case "0":
         checkPassword();
         break; // Prize Menu.
       default:
         System.out.println("You have selected an invalid option.\n");
         break;
     }
   }
 }
Exemplo n.º 4
0
 /**
  * Compares the number given with a random lucky number. If they match, the Player object will be
  * updated with details of the new Prize they have won.
  *
  * @param guess The number that is to be compared.
  */
 private void compareLuckyNumber(int guess) {
   System.out.println("You have guessed: " + guess);
   int randomNumber = LuckyGuessGenerator.generateRandomNumber(prizes.getSize());
   System.out.println("The lucky number is: " + randomNumber);
   if (guess == randomNumber) {
     players.getPlayer(currentPlayer).addPrize(prizes.getPrize(guess - 1));
     System.out.println(
         "Congratulations! you have won a "
             + prizes.getPrize(guess - 1).getName()
             + " worth $"
             + prizes.getPrize(guess - 1).getWorth()
             + "!\n");
     players.getPlayer(currentPlayer).addWorth(prizes.getPrize(guess - 1).getWorth());
   } else System.out.println("Too bad! You didn't win anything.\n");
   players.getPlayer(currentPlayer).addSpent(prizes.getPrize(guess - 1).getCost());
 }
Exemplo n.º 5
0
 private void playFile(File file) throws Exception {
   player = playerList.getPlayer(playListManager.getTrackDatabase().getPlayer());
   try {
     player.play(file);
   } catch (PlayerException e) {
     e.printStackTrace();
   } finally {
     // Without this, RoboJock can't talk because it fights with the
     // Java player over the sound device.
     player.close();
   }
 }
Exemplo n.º 6
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (cmd.getName().equalsIgnoreCase("dmarker")) {
      return MarkerAPIImpl.onCommand(this, sender, cmd, commandLabel, args);
    }
    if (!cmd.getName().equalsIgnoreCase("dynmap")) return false;
    Player player = null;
    if (sender instanceof Player) player = (Player) sender;
    /* Re-parse args - handle doublequotes */
    args = parseArgs(args, sender);

    if (args == null) return false;

    if (args.length > 0) {
      String c = args[0];
      if (!commands.contains(c)) {
        return false;
      }

      if (c.equals("render") && checkPlayerPermission(sender, "render")) {
        if (player != null) {
          int invalidates = mapManager.touch(player.getLocation(), "render");
          sender.sendMessage(
              "Queued "
                  + invalidates
                  + " tiles"
                  + (invalidates == 0 ? " (world is not loaded?)" : "..."));
        } else {
          sender.sendMessage("Command can only be issued by player.");
        }
      } else if (c.equals("radiusrender") && checkPlayerPermission(sender, "radiusrender")) {
        if (player != null) {
          int radius = 0;
          String mapname = null;
          if (args.length > 1) {
            radius = Integer.parseInt(args[1]); /* Parse radius */
            if (radius < 0) radius = 0;
            if (args.length > 2) mapname = args[2];
          }
          Location loc = player.getLocation();
          if (loc != null) mapManager.renderWorldRadius(loc, sender, mapname, radius);
        } else {
          sender.sendMessage("Command can only be issued by player.");
        }
      } else if (c.equals("hide")) {
        if (args.length == 1) {
          if (player != null && checkPlayerPermission(sender, "hide.self")) {
            playerList.setVisible(player.getName(), false);
            sender.sendMessage("You are now hidden on Dynmap.");
          }
        } else if (checkPlayerPermission(sender, "hide.others")) {
          for (int i = 1; i < args.length; i++) {
            playerList.setVisible(args[i], false);
            sender.sendMessage(args[i] + " is now hidden on Dynmap.");
          }
        }
      } else if (c.equals("show")) {
        if (args.length == 1) {
          if (player != null && checkPlayerPermission(sender, "show.self")) {
            playerList.setVisible(player.getName(), true);
            sender.sendMessage("You are now visible on Dynmap.");
          }
        } else if (checkPlayerPermission(sender, "show.others")) {
          for (int i = 1; i < args.length; i++) {
            playerList.setVisible(args[i], true);
            sender.sendMessage(args[i] + " is now visible on Dynmap.");
          }
        }
      } else if (c.equals("fullrender") && checkPlayerPermission(sender, "fullrender")) {
        String map = null;
        if (args.length > 1) {
          for (int i = 1; i < args.length; i++) {
            int dot = args[i].indexOf(":");
            DynmapWorld w;
            String wname = args[i];
            if (dot >= 0) {
              wname = args[i].substring(0, dot);
              map = args[i].substring(dot + 1);
            }
            w = mapManager.getWorld(wname);
            if (w != null) {
              Location spawn = w.world.getSpawnLocation();
              Location loc =
                  new Location(
                      w.world,
                      w.configuration.getDouble("center/x", spawn.getX()),
                      w.configuration.getDouble("center/y", spawn.getY()),
                      w.configuration.getDouble("center/z", spawn.getZ()));
              mapManager.renderFullWorld(loc, sender, map);
            } else sender.sendMessage("World '" + wname + "' not defined/loaded");
          }
        } else if (player != null) {
          Location loc = player.getLocation();
          if (args.length > 1) map = args[1];
          if (loc != null) mapManager.renderFullWorld(loc, sender, map);
        } else {
          sender.sendMessage("World name is required");
        }
      } else if (c.equals("cancelrender") && checkPlayerPermission(sender, "cancelrender")) {
        if (args.length > 1) {
          for (int i = 1; i < args.length; i++) {
            World w = getServer().getWorld(args[i]);
            if (w != null) mapManager.cancelRender(w, sender);
            else sender.sendMessage("World '" + args[i] + "' not defined/loaded");
          }
        } else if (player != null) {
          Location loc = player.getLocation();
          if (loc != null) mapManager.cancelRender(loc.getWorld(), sender);
        } else {
          sender.sendMessage("World name is required");
        }
      } else if (c.equals("purgequeue") && checkPlayerPermission(sender, "purgequeue")) {
        mapManager.purgeQueue(sender);
      } else if (c.equals("reload") && checkPlayerPermission(sender, "reload")) {
        sender.sendMessage("Reloading Dynmap...");
        reload();
        sender.sendMessage("Dynmap reloaded");
      } else if (c.equals("stats") && checkPlayerPermission(sender, "stats")) {
        if (args.length == 1) mapManager.printStats(sender, null);
        else mapManager.printStats(sender, args[1]);
      } else if (c.equals("triggerstats") && checkPlayerPermission(sender, "stats")) {
        mapManager.printTriggerStats(sender);
      } else if (c.equals("resetstats") && checkPlayerPermission(sender, "resetstats")) {
        if (args.length == 1) mapManager.resetStats(sender, null);
        else mapManager.resetStats(sender, args[1]);
      } else if (c.equals("sendtoweb") && checkPlayerPermission(sender, "sendtoweb")) {
        String msg = "";
        for (int i = 1; i < args.length; i++) {
          msg += args[i] + " ";
        }
        this.sendBroadcastToWeb("dynmap", msg);
      }
      return true;
    }
    return false;
  }
Exemplo n.º 7
0
  @Override
  public void onEnable() {
    /* Start with clean events */
    events = new Events();

    permissions = NijikokunPermissions.create(getServer(), "dynmap");
    if (permissions == null) permissions = BukkitPermissions.create("dynmap");
    if (permissions == null)
      permissions =
          new OpPermissions(
              new String[] {
                "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue"
              });

    dataDirectory = this.getDataFolder();
    if (dataDirectory.exists() == false) dataDirectory.mkdirs();

    /* Initialize confguration.txt if needed */
    File f = new File(this.getDataFolder(), "configuration.txt");
    if (!createDefaultFileFromResource("/configuration.txt", f)) {
      this.setEnabled(false);
      return;
    }
    /* Load configuration.txt */
    org.bukkit.util.config.Configuration bukkitConfiguration =
        new org.bukkit.util.config.Configuration(f);
    bukkitConfiguration.load();
    configuration = new ConfigurationNode(bukkitConfiguration);

    /* Load block models */
    HDBlockModels.loadModels(dataDirectory, configuration);
    /* Load texture mappings */
    TexturePack.loadTextureMapping(dataDirectory, configuration);

    /* Now, process worlds.txt - merge it in as an override of existing values (since it is only user supplied values) */
    f = new File(this.getDataFolder(), "worlds.txt");
    if (!createDefaultFileFromResource("/worlds.txt", f)) {
      this.setEnabled(false);
      return;
    }
    org.bukkit.util.config.Configuration cfg = new org.bukkit.util.config.Configuration(f);
    cfg.load();
    ConfigurationNode cn = new ConfigurationNode(cfg);
    mergeConfigurationBranch(cn, "worlds", true, true);

    /* Now, process templates */
    loadTemplates();

    Log.verbose = configuration.getBoolean("verbose", true);
    deftemplatesuffix = configuration.getString("deftemplatesuffix", "");
    /* Default swamp shading off for 1.8, on after */
    swampshading =
        configuration.getBoolean("swampshaded", !getServer().getVersion().contains("(MC: 1.8"));
    /* Default water biome shading off for 1.8, on after */
    waterbiomeshading =
        configuration.getBoolean(
            "waterbiomeshaded", !getServer().getVersion().contains("(MC: 1.8"));
    /* Default fence-to-block-join off for 1.8, on after */
    fencejoin =
        configuration.getBoolean(
            "fence-to-block-join", !getServer().getVersion().contains("(MC: 1.8"));
    /* Default compassmode to pre19, to newrose after */
    String cmode =
        configuration.getString(
            "compass-mode", getServer().getVersion().contains("(MC: 1.8") ? "pre19" : "newrose");
    if (cmode.equals("newnorth")) compassmode = CompassMode.NEWNORTH;
    else if (cmode.equals("newrose")) compassmode = CompassMode.NEWROSE;
    else compassmode = CompassMode.PRE19;

    loadDebuggers();

    tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
    if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
      Log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
    }

    playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"), configuration);
    playerList.load();
    PlayerListener pl =
        new PlayerListener() {
          public void onPlayerJoin(PlayerJoinEvent evt) {
            playerList.updateOnlinePlayers(null);
          }

          public void onPlayerQuit(PlayerQuitEvent evt) {
            playerList.updateOnlinePlayers(evt.getPlayer());
          }
        };
    registerEvent(Type.PLAYER_JOIN, pl);
    registerEvent(Type.PLAYER_QUIT, pl);

    mapManager = new MapManager(this, configuration);
    mapManager.startRendering();

    playerfacemgr = new PlayerFaces(this);

    loadWebserver();

    enabledTriggers.clear();
    List<String> triggers = configuration.getStrings("render-triggers", new ArrayList<String>());
    if (triggers != null) {
      for (Object trigger : triggers) {
        enabledTriggers.add((String) trigger);
      }
    }

    // Load components.
    for (Component component :
        configuration.<Component>createInstances(
            "components", new Class<?>[] {DynmapPlugin.class}, new Object[] {this})) {
      componentManager.add(component);
    }
    Log.verboseinfo("Loaded " + componentManager.components.size() + " components.");

    registerEvents();

    if (!configuration.getBoolean("disable-webserver", false)) {
      startWebserver();
    }

    /* Print version info */
    PluginDescriptionFile pdfFile = this.getDescription();
    Log.info("version " + pdfFile.getVersion() + " is enabled");

    events.<Object>trigger("initialized", null);
  }
 /**
  * checks if there is a draw between the players or not
  *
  * @return True if there is a draw. Else false.
  */
 public boolean draw() {
   return playerlist.returnDrawedPlayers().size() > 1;
 }
Exemplo n.º 9
0
 public boolean isGameOver(Dealer dealer, PlayerList playerList) {
   if (dealer.isDeckEmpty() && playerList.isAllPlayerHandEmpty()) return true;
   return false;
 }