Exemplo n.º 1
0
 public static void showInventory(Player player, String group, int page) {
   // Show inventory
   final GroupPageInfo info = new GroupPageInfo(group, page);
   Inventory inventory = null;
   if (inventories.containsKey(info)) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_INVENTORY)) {
       plugin.getLogger().info("inventory already open");
     }
     // Grab already open inventory
     inventory = inventories.get(info).getInventory();
   } else {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_INVENTORY)) {
       plugin.getLogger().info("inventory first open");
     }
     final KSInventoryHolder holder = new KSInventoryHolder(info);
     inventory = plugin.getServer().createInventory(holder, chestSize, group + " : " + page);
     populateInventory(inventory, page, group);
     holder.setInventory(inventory);
     inventories.put(info, holder);
   }
   // Set task
   final int id =
       plugin
           .getServer()
           .getScheduler()
           .scheduleSyncDelayedTask(plugin, new ShowKSInventoryTask(plugin, player, inventory), 3);
   if (id == -1) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_INVENTORY)) {
       plugin.getLogger().warning("Could not schedule open inventory for " + player.getName());
     }
     player.sendMessage(ChatColor.RED + KarmicShare.TAG + " Could not schedule open inventory!");
   }
 }
Exemplo n.º 2
0
 /**
  * Updates the player's karma
  *
  * @param Name of player
  * @param Amount of karma to add
  * @param Boolean if to add to current karma, or to set it as given value
  * @throws SQLException
  */
 public static void updatePlayerKarma(String name, int k) throws SQLException {
   if (RootConfig.getBoolean(ConfigNode.KARMA_ECONOMY)) {
     EconomyResponse response = null;
     if (k < 0) {
       // negative, take away
       response = plugin.getEconomy().withdrawPlayer(name, (k * -1));
     } else {
       // give
       response = plugin.getEconomy().depositPlayer(name, k);
     }
     if (response == null) {
       return;
     }
     switch (response.type) {
       case FAILURE:
         {
           try {
             plugin
                 .getServer()
                 .getPlayer(name)
                 .sendMessage(ChatColor.RED + KarmicShare.TAG + " Failed economy transaction!");
           } catch (NullPointerException npe) {
             // IGNORE
           }
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .warning(
                     "Failed economy transaction on updatePlayerKarma("
                         + name
                         + ", "
                         + k
                         + ") : "
                         + response.errorMessage);
           }
           break;
         }
       case NOT_IMPLEMENTED:
         {
           try {
             plugin
                 .getServer()
                 .getPlayer(name)
                 .sendMessage(ChatColor.RED + KarmicShare.TAG + " Failed economy transaction!");
           } catch (NullPointerException npe) {
             // IGNORE
           }
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .warning(
                     "Unimplemented economy transaction on updatePlayerKarma("
                         + name
                         + ", "
                         + k
                         + ") for eco "
                         + plugin.getEconomy().getName()
                         + " : "
                         + response.errorMessage);
           }
           break;
         }
       case SUCCESS:
         {
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .info(
                     "Successful economy transaction on updatePlayerKarma("
                         + name
                         + ", "
                         + k
                         + ")");
           }
           break;
         }
       default:
         {
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin.getLogger().warning("Unknown response type:" + response.type.toString());
           }
           break;
         }
     }
   } else {
     try {
       // Retrieve karma from database
       int karma = getPlayerKarma(name);
       // Add to existing value
       karma += k;
       String query;
       // Check updated karma value to limits in config
       if (karma <= RootConfig.getInt(ConfigNode.KARMA_LOWER_LIMIT)) {
         // Updated karma value is beyond lower limit, so set to min
         query =
             "UPDATE "
                 + Table.PLAYERS.getName()
                 + " SET karma='"
                 + RootConfig.getInt(ConfigNode.KARMA_LOWER_LIMIT)
                 + "' WHERE playername='"
                 + name
                 + "';";
       } else if (karma >= RootConfig.getInt(ConfigNode.KARMA_UPPER_LIMIT)) {
         // Updated karma value is beyond upper limit, so set to max
         query =
             "UPDATE "
                 + Table.PLAYERS.getName()
                 + " SET karma='"
                 + RootConfig.getInt(ConfigNode.KARMA_UPPER_LIMIT)
                 + "' WHERE playername='"
                 + name
                 + "';";
       } else {
         // Updated karma value is within acceptable range
         query =
             "UPDATE "
                 + Table.PLAYERS.getName()
                 + " SET karma='"
                 + karma
                 + "' WHERE playername='"
                 + name
                 + "';";
       }
       plugin.getDatabaseHandler().standardQuery(query);
     } catch (SQLException e) {
       if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
         plugin.getLogger().warning("SQLException on updatePlayerKarma(" + name + "," + k + ")");
       }
       throw e;
     }
   }
 }
Exemplo n.º 3
0
 public static void setPlayerKarma(String name, int karma) {
   if (RootConfig.getBoolean(ConfigNode.KARMA_ECONOMY)) {
     EconomyResponse response = null;
     try {
       int balance = getPlayerKarma(name);
       if (balance > karma) {
         // Give difference
         response = plugin.getEconomy().depositPlayer(name, (balance - karma));
       } else {
         // Take difference
         response = plugin.getEconomy().withdrawPlayer(name, (karma - balance));
       }
     } catch (SQLException e) {
       // Won't happen since we're using economy
     }
     if (response == null) {
       return;
     }
     switch (response.type) {
       case FAILURE:
         {
           try {
             plugin
                 .getServer()
                 .getPlayer(name)
                 .sendMessage(ChatColor.RED + KarmicShare.TAG + " Failed economy transaction!");
           } catch (NullPointerException npe) {
             // IGNORE
           }
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .warning(
                     "Failed economy transaction on setPlayerKarma("
                         + name
                         + ", "
                         + karma
                         + ") : "
                         + response.errorMessage);
           }
           break;
         }
       case NOT_IMPLEMENTED:
         {
           try {
             plugin
                 .getServer()
                 .getPlayer(name)
                 .sendMessage(ChatColor.RED + KarmicShare.TAG + " Failed economy transaction!");
           } catch (NullPointerException npe) {
             // IGNORE
           }
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .warning(
                     "Unimplemented economy transaction on setPlayerKarma("
                         + name
                         + ", "
                         + karma
                         + ") for eco "
                         + plugin.getEconomy().getName()
                         + " : "
                         + response.errorMessage);
           }
           break;
         }
       case SUCCESS:
         {
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin
                 .getLogger()
                 .info(
                     "Successful economy transaction on setPlayerKarma("
                         + name
                         + ", "
                         + karma
                         + ")");
           }
           break;
         }
       default:
         {
           if (RootConfig.getBoolean(ConfigNode.DEBUG_ECONOMY)) {
             plugin.getLogger().warning("Unknown response type:" + response.type.toString());
           }
           break;
         }
     }
   } else {
     String query;
     // Check updated karma value to limits in config
     if (karma <= RootConfig.getInt(ConfigNode.KARMA_LOWER_LIMIT)) {
       // Updated karma value is beyond lower limit, so set to min
       query =
           "UPDATE "
               + Table.PLAYERS.getName()
               + " SET karma='"
               + RootConfig.getInt(ConfigNode.KARMA_LOWER_LIMIT)
               + "' WHERE playername='"
               + name
               + "';";
     } else if (karma >= RootConfig.getInt(ConfigNode.KARMA_UPPER_LIMIT)) {
       // Updated karma value is beyond upper limit, so set to max
       query =
           "UPDATE "
               + Table.PLAYERS.getName()
               + " SET karma='"
               + RootConfig.getInt(ConfigNode.KARMA_UPPER_LIMIT)
               + "' WHERE playername='"
               + name
               + "';";
     } else {
       // Updated karma value is within acceptable range
       query =
           "UPDATE "
               + Table.PLAYERS.getName()
               + " SET karma='"
               + karma
               + "' WHERE playername='"
               + name
               + "';";
     }
     plugin.getDatabaseHandler().standardQuery(query);
   }
 }