mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +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":
|
case "buy":
|
||||||
{
|
{
|
||||||
ShopItem item = ShopItem.findItem(args[1]);
|
ShopItem item = ShopItem.findItem(args[1]);
|
||||||
if (item == null)
|
if (item == null || !item.isPurchaseable())
|
||||||
{
|
{
|
||||||
msg("Invalid item: " + item);
|
msg("Invalid item: " + item);
|
||||||
return true;
|
return true;
|
||||||
@ -133,7 +133,7 @@ public class Command_shop extends FreedomCommand
|
|||||||
case "get":
|
case "get":
|
||||||
{
|
{
|
||||||
ShopItem item = ShopItem.findItem(args[1]);
|
ShopItem item = ShopItem.findItem(args[1]);
|
||||||
if (item == null)
|
if (item == null || !item.isPurchaseable())
|
||||||
{
|
{
|
||||||
msg("Invalid item: " + item);
|
msg("Invalid item: " + item);
|
||||||
return true;
|
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 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 final Map<Player, Float> orientationTracker = new HashMap<>();
|
||||||
|
|
||||||
private void cooldown(Player player, String feature, int seconds)
|
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()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
cooldownTracker.remove(player.getName());
|
cooldownTracker.get(player.getName()).remove(feature);
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, seconds * 20);
|
}.runTaskLater(plugin, seconds * 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCooldown(Player player, String feature)
|
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)
|
public ItemFun(TotalFreedomMod plugin)
|
||||||
@ -345,23 +358,23 @@ public class ItemFun extends FreedomService
|
|||||||
boolean superior = FUtil.random(1, 100) == 50;
|
boolean superior = FUtil.random(1, 100) == 50;
|
||||||
Player rplayer = FUtil.getRandomPlayer();
|
Player rplayer = FUtil.getRandomPlayer();
|
||||||
ShopData psd = plugin.sh.getData(rplayer);
|
ShopData psd = plugin.sh.getData(rplayer);
|
||||||
String key = FUtil.generateKey(8);
|
|
||||||
psd.giveRawItem(key);
|
|
||||||
plugin.sh.save(psd);
|
|
||||||
if (superior)
|
if (superior)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 25; i++)
|
for (int i = 0; i < 25; i++)
|
||||||
{
|
{
|
||||||
rplayer.getWorld().strikeLightning(rplayer.getLocation());
|
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.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
|
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.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);
|
cooldown(player, "nether_star", 600);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
|||||||
|
|
||||||
public String giveItem(ShopItem item)
|
public String giveItem(ShopItem item)
|
||||||
{
|
{
|
||||||
String signature = String.valueOf(item.ordinal());
|
String signature = FUtil.generateSignature(item);
|
||||||
for (int i = 0; i < 7; i++)
|
|
||||||
{
|
|
||||||
signature += FUtil.getRandomCharacter();
|
|
||||||
}
|
|
||||||
items.add(signature);
|
items.add(signature);
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
@ -103,7 +99,7 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
|||||||
int id;
|
int id;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
id = Integer.valueOf(i.substring(0, 1));
|
id = Integer.valueOf(i.substring(0, i.indexOf("A")));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
@ -122,7 +118,15 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
|
|||||||
String signature = "";
|
String signature = "";
|
||||||
for (String i : items)
|
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)
|
if (item.ordinal() == id)
|
||||||
{
|
{
|
||||||
signature = i;
|
signature = i;
|
||||||
|
@ -6,8 +6,10 @@ import org.bukkit.Material;
|
|||||||
|
|
||||||
public enum ShopItem
|
public enum ShopItem
|
||||||
{
|
{
|
||||||
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 100, ChatColor.GREEN),
|
GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 100, ChatColor.GREEN, true),
|
||||||
THOR_STAR("Thor's Star", Material.NETHER_STAR, 10000, ChatColor.LIGHT_PURPLE);
|
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
|
@Getter
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -17,13 +19,16 @@ public enum ShopItem
|
|||||||
private final int cost;
|
private final int cost;
|
||||||
@Getter
|
@Getter
|
||||||
private final ChatColor color;
|
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.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.purchaseable = purchaseable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColoredName()
|
public String getColoredName()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.totalfreedom.totalfreedommod.util;
|
package me.totalfreedom.totalfreedommod.util;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -22,6 +23,7 @@ import java.util.TimeZone;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -535,14 +537,25 @@ public class FUtil
|
|||||||
player.getInventory().setItem(player.getInventory().firstEmpty(), stack);
|
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();
|
give(player, item.getMaterial(), item.getColoredName(), 1, lore);
|
||||||
for (int i = 0; i < length; i++)
|
}
|
||||||
|
|
||||||
|
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()
|
public static Player getRandomPlayer()
|
||||||
|
Loading…
Reference in New Issue
Block a user