mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
ivan u never commit
This commit is contained in:
parent
1ee1cbca2b
commit
7940313dd1
@ -100,7 +100,7 @@ public class Command_shop extends FreedomCommand
|
||||
case "buy":
|
||||
{
|
||||
ShopItem item = ShopItem.findItem(args[1]);
|
||||
if (item == null)
|
||||
if (item == null || !item.isPurchaseable())
|
||||
{
|
||||
msg("Invalid item: " + item);
|
||||
return true;
|
||||
@ -133,7 +133,7 @@ public class Command_shop extends FreedomCommand
|
||||
case "get":
|
||||
{
|
||||
ShopItem item = ShopItem.findItem(args[1]);
|
||||
if (item == null)
|
||||
if (item == null || !item.isPurchaseable())
|
||||
{
|
||||
msg("Invalid item: " + item);
|
||||
return true;
|
||||
|
@ -49,26 +49,39 @@ public class ItemFun extends FreedomService
|
||||
|
||||
private static final String COOLDOWN_MESSAGE = ChatColor.RED + "You're on cooldown for this feature.";
|
||||
|
||||
private final Map<String, String> cooldownTracker = new HashMap<>();
|
||||
private final Map<String, List<String>> cooldownTracker = new HashMap<>();
|
||||
|
||||
private final Map<Player, Float> orientationTracker = new HashMap<>();
|
||||
|
||||
private void cooldown(Player player, String feature, int seconds)
|
||||
{
|
||||
cooldownTracker.put(player.getName(), feature);
|
||||
if (cooldownTracker.get(player.getName()) == null)
|
||||
{
|
||||
List<String> featureList = new ArrayList<>();
|
||||
featureList.add(feature);
|
||||
cooldownTracker.put(player.getName(), featureList);
|
||||
}
|
||||
else
|
||||
{
|
||||
cooldownTracker.get(player.getName()).add(feature);
|
||||
}
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
cooldownTracker.remove(player.getName());
|
||||
cooldownTracker.get(player.getName()).remove(feature);
|
||||
}
|
||||
}.runTaskLater(plugin, seconds * 20);
|
||||
}
|
||||
|
||||
public boolean onCooldown(Player player, String feature)
|
||||
{
|
||||
return cooldownTracker.containsKey(player.getName()) && cooldownTracker.containsValue(feature);
|
||||
if (cooldownTracker.get(player.getName()) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return cooldownTracker.get(player.getName()).contains(feature);
|
||||
}
|
||||
|
||||
public ItemFun(TotalFreedomMod plugin)
|
||||
@ -345,23 +358,23 @@ public class ItemFun extends FreedomService
|
||||
boolean superior = FUtil.random(1, 100) == 50;
|
||||
Player rplayer = FUtil.getRandomPlayer();
|
||||
ShopData psd = plugin.sh.getData(rplayer);
|
||||
String key = FUtil.generateKey(8);
|
||||
psd.giveRawItem(key);
|
||||
plugin.sh.save(psd);
|
||||
if (superior)
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
rplayer.getWorld().strikeLightning(rplayer.getLocation());
|
||||
}
|
||||
String key = psd.giveItem(ShopItem.SUPERIOR_SWORD);
|
||||
FUtil.bcastMsg("THOR'S STAR HAS GRANTED " + rplayer.getName().toUpperCase() + " A " + ChatColor.GOLD + "SUPERIOR SWORD" + ChatColor.RED + "!!!!", ChatColor.RED);
|
||||
FUtil.give(rplayer, Material.GOLDEN_SWORD, "&6Superior Sword", 1, "&7RMB - Shoot fireball", ChatColor.DARK_GRAY + key);
|
||||
FUtil.give(player, ShopItem.SUPERIOR_SWORD, "&7RMB - Shoot fireball", ChatColor.DARK_GRAY + key);
|
||||
}
|
||||
else
|
||||
{
|
||||
String key = psd.giveItem(ShopItem.ELECTRICAL_DIAMOND_SWORD);
|
||||
FUtil.bcastMsg("Thor's Star has granted " + rplayer.getName() + " an " + ChatColor.YELLOW + "Electrical Diamond Sword" + ChatColor.RED + "!", ChatColor.RED);
|
||||
FUtil.give(rplayer, Material.DIAMOND_SWORD, "&eElectrical Diamond Sword", 1, "&7RMB - Strike lightning", ChatColor.DARK_GRAY + key);
|
||||
FUtil.give(player, ShopItem.ELECTRICAL_DIAMOND_SWORD, "&7RMB - Strike lightning", ChatColor.DARK_GRAY + key);
|
||||
}
|
||||
plugin.sh.save(psd);
|
||||
cooldown(player, "nether_star", 600);
|
||||
break;
|
||||
}
|
||||
|
@ -82,11 +82,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
|
||||
public String giveItem(ShopItem item)
|
||||
{
|
||||
String signature = String.valueOf(item.ordinal());
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
signature += FUtil.getRandomCharacter();
|
||||
}
|
||||
String signature = FUtil.generateSignature(item);
|
||||
items.add(signature);
|
||||
return signature;
|
||||
}
|
||||
@ -103,7 +99,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
int id;
|
||||
try
|
||||
{
|
||||
id = Integer.valueOf(i.substring(0, 1));
|
||||
id = Integer.valueOf(i.substring(0, i.indexOf("A")));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
@ -122,7 +118,15 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
String signature = "";
|
||||
for (String i : items)
|
||||
{
|
||||
int id = Integer.valueOf(i.substring(0, 1));
|
||||
int id;
|
||||
try
|
||||
{
|
||||
id = Integer.valueOf(i.substring(0, i.indexOf("A")));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ordinal() == id)
|
||||
{
|
||||
signature = i;
|
||||
|
@ -6,8 +6,10 @@ import org.bukkit.Material;
|
||||
|
||||
public enum ShopItem
|
||||
{
|
||||
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 100, ChatColor.GREEN),
|
||||
THOR_STAR("Thor's Star", Material.NETHER_STAR, 10000, ChatColor.LIGHT_PURPLE);
|
||||
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 100, ChatColor.GREEN, true),
|
||||
THOR_STAR("Thor's Star", Material.NETHER_STAR, 10000, ChatColor.LIGHT_PURPLE, true),
|
||||
ELECTRICAL_DIAMOND_SWORD("Electrical Diamond Sword", Material.DIAMOND_SWORD, 0, ChatColor.YELLOW, false),
|
||||
SUPERIOR_SWORD("Superior Sword", Material.GOLDEN_SWORD, 0, ChatColor.GOLD, false);
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
@ -17,13 +19,16 @@ public enum ShopItem
|
||||
private final int cost;
|
||||
@Getter
|
||||
private final ChatColor color;
|
||||
@Getter
|
||||
private final boolean purchaseable;
|
||||
|
||||
ShopItem(String name, Material material, int cost, ChatColor color)
|
||||
ShopItem(String name, Material material, int cost, ChatColor color, boolean purchaseable)
|
||||
{
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
this.cost = cost;
|
||||
this.color = color;
|
||||
this.purchaseable = purchaseable;
|
||||
}
|
||||
|
||||
public String getColoredName()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.lang.reflect.Field;
|
||||
@ -22,6 +23,7 @@ import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -535,14 +537,25 @@ public class FUtil
|
||||
player.getInventory().setItem(player.getInventory().firstEmpty(), stack);
|
||||
}
|
||||
|
||||
public static String generateKey(int length)
|
||||
public static void give(Player player, ShopItem item, String... lore)
|
||||
{
|
||||
StringBuilder key = new StringBuilder();
|
||||
for (int i = 0; i < length; i++)
|
||||
give(player, item.getMaterial(), item.getColoredName(), 1, lore);
|
||||
}
|
||||
|
||||
public static String generateSignature(ShopItem item)
|
||||
{
|
||||
String signature = String.valueOf(item.ordinal());
|
||||
signature += "A"; // mark the ending
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
key.append(getRandomCharacter());
|
||||
char c = FUtil.getRandomCharacter();
|
||||
while (c == 'A')
|
||||
{
|
||||
c = FUtil.getRandomCharacter();
|
||||
}
|
||||
signature += FUtil.getRandomCharacter();
|
||||
}
|
||||
return key.toString();
|
||||
return signature;
|
||||
}
|
||||
|
||||
public static Player getRandomPlayer()
|
||||
|
Loading…
Reference in New Issue
Block a user