Economy + schematics for /p auto :P

This commit is contained in:
Sauilitired
2014-10-08 07:11:46 +02:00
parent 30f1f829cb
commit ee86310988
4 changed files with 288 additions and 303 deletions

View File

@ -10,9 +10,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Citymonstret on 2014-10-06.
*/
public class UUIDHandler {
private static ConcurrentHashMap<String, UUID> uuidMap = new ConcurrentHashMap<>();
@ -29,6 +26,10 @@ public class UUIDHandler {
uuidMap.put(name, uuid);
}
/**
*
* @param plugin
*/
public static void startFetch(JavaPlugin plugin) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
@ -53,6 +54,11 @@ public class UUIDHandler {
});
}
/**
*
* @param name
* @return
*/
public static UUID getUUID(String name) {
if (nameExists(name)) {
return uuidMap.get(name);
@ -72,6 +78,11 @@ public class UUIDHandler {
return null;
}
/**
*
* @param uuid
* @return
*/
private static String loopSearch(UUID uuid) {
for(Map.Entry<String, UUID> entry : uuidMap.entrySet()) {
if(entry.getValue().equals(uuid)) {
@ -81,6 +92,11 @@ public class UUIDHandler {
return "";
}
/**
*
* @param uuid
* @return
*/
public static String getName(UUID uuid) {
if(uuidExists(uuid)) {
return loopSearch(uuid);
@ -95,12 +111,22 @@ public class UUIDHandler {
return null;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflineMode(String name) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
add(name, uuid);
return uuid;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOnlinePlayer(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
if(player == null || !player.isOnline()) {
@ -111,6 +137,11 @@ public class UUIDHandler {
return name;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOfflinePlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
@ -121,6 +152,11 @@ public class UUIDHandler {
return name;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOnlinePlayer(String name) {
Player player = Bukkit.getPlayer(name);
if (player == null || !player.isOnline()) {
@ -131,6 +167,11 @@ public class UUIDHandler {
return uuid;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflinePlayer(String name) {
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
if (player == null || !player.hasPlayedBefore()) {

View File

@ -8,17 +8,12 @@
*/
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
@SuppressWarnings("deprecation")
public class Auto extends SubCommand {
public Auto() {
@ -31,6 +26,7 @@ public class Auto extends SubCommand {
World world;
int size_x = 1;
int size_z = 1;
String schematic = "";
if (PlotMain.getPlotWorlds().length == 1) {
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
} else {
@ -41,7 +37,7 @@ public class Auto extends SubCommand {
return false;
}
}
if (args.length == 1) {
if (args.length > 0) {
if (PlotMain.hasPermission(plr, "plots.auto.mega")) {
try {
String[] split = args[0].split(",");
@ -53,19 +49,49 @@ public class Auto extends SubCommand {
if ((size_x > 4) || (size_z > 4)) {
PlayerFunctions.sendMessage(plr, "&cError: size>4");
}
if(args.length > 1) {
schematic = args[1];
}
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, "&cError: Invalid size (X,Y)");
return false;
schematic = args[0];
//PlayerFunctions.sendMessage(plr, "&cError: Invalid size (X,Y)");
//return false;
}
} else {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return false;
schematic = args[0];
//PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
//return false;
}
}
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return false;
}
PlotWorld pWorld = PlotMain.getWorldSettings(world);
if(PlotMain.useEconomy && pWorld.USE_ECONOMY) {
double cost = pWorld.PLOT_PRICE;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if(!schematic.equals("")) {
if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if(pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
}
}
boolean br = false;
int x = 0, z = 0, q = 100;
PlotId id;

View File

@ -69,7 +69,7 @@ public class Claim extends SubCommand {
if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {