diff --git a/TotalFreedomMod.iml b/TotalFreedomMod.iml
index a17c989b..e145fbf4 100644
--- a/TotalFreedomMod.iml
+++ b/TotalFreedomMod.iml
@@ -49,6 +49,7 @@
+
@@ -80,8 +81,6 @@
-
-
@@ -163,5 +162,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 788a6761..28c5f343 100644
--- a/pom.xml
+++ b/pom.xml
@@ -205,6 +205,14 @@
jsonmessage
1.0.0
+
+
+ com.github.vexsoftware
+ votifier
+ v1.9
+ provided
+
+
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
index 89afe07a..a9fc3708 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
@@ -4,12 +4,10 @@ import com.google.common.base.Strings;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
-import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FSync;
import me.totalfreedom.totalfreedommod.util.FUtil;
-import me.totalfreedom.totalfreedommod.admin.Admin;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -68,26 +66,12 @@ public class ChatManager extends FreedomService
return;
}
- if (message.equals("Connected using PickaxeChat for Android"))
+ if (message.startsWith("Connected using PickaxeChat for "))
{
event.setCancelled(true);
return;
}
- if (message.contains("nigger") || message.contains("nigga"))
- {
- event.setCancelled(true);
- player.sendMessage(ChatColor.RED + "This is racist and therefore is prohibited.");
- return;
- }
-
- if (message.contains("dyke") || message.contains("fag") || message.contains("kike"))
- {
- event.setCancelled(true);
- player.sendMessage(ChatColor.RED + "This is homophobic and therefore is prohibited.");
- return;
- }
-
// Truncate messages that are too long - 256 characters is vanilla client max
if (message.length() > 256)
{
@@ -95,7 +79,7 @@ public class ChatManager extends FreedomService
FSync.playerMsg(player, "Message was shortened because it was too long to send.");
}
- // Check for adminchat
+
final FPlayer fPlayer = plugin.pl.getPlayerSync(player);
if (fPlayer.isLockedUp())
{
@@ -103,6 +87,8 @@ public class ChatManager extends FreedomService
event.setCancelled(true);
return;
}
+
+ // Check for adminchat
if (fPlayer.inAdminChat())
{
FSync.adminChatMessage(player, message);
@@ -129,7 +115,7 @@ public class ChatManager extends FreedomService
event.setMessage(message);
// Make format
- String format = "%1$s §8» §f%2$s";
+ String format = "%1$s §8\u00BB §f%2$s";
String tag = fPlayer.getTag();
if (tag != null && !tag.isEmpty())
@@ -233,6 +219,7 @@ public class ChatManager extends FreedomService
if (plugin.al.isAdmin(player))
{
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reported.getName() + " for " + report);
+ FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reported.getName() + " for " + report);
}
}
}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java
index 65f37c4f..33050e97 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java
@@ -22,6 +22,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.LeavesDecayEvent;
+import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
@@ -172,6 +173,12 @@ public class EventBlocker extends FreedomService
event.setCancelled(true);
}
+ @EventHandler(priority = EventPriority.NORMAL)
+ public void onBlockGrowth(BlockGrowEvent event)
+ {
+ event.setCancelled(true);
+ }
+
@EventHandler(priority = EventPriority.HIGH)
public void onFireworkExplode(FireworkExplodeEvent event)
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java
index e632a398..d5b12c38 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java
@@ -49,7 +49,7 @@ public class Command_coins extends FreedomCommand
}
}
ShopData sd = plugin.sh.getData(p);
- msg(prefix + ChatColor.GREEN + (args.length > 0 ? p.getName() + " has " : "You have ") + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins." + " This will be in use shortly.");
+ msg(prefix + ChatColor.GREEN + (args.length > 0 ? p.getName() + " has " : "You have ") + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java
index d538271b..4a38db0a 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java
@@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
-@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
+@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Makes random sounds to everyone online.", usage = "/")
public class Command_deafen extends FreedomCommand
{
@@ -20,7 +20,6 @@ public class Command_deafen extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
- for (final Player player : server.getOnlinePlayers())
{
for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS))
{
@@ -31,7 +30,7 @@ public class Command_deafen extends FreedomCommand
@Override
public void run()
{
- player.playSound(randomOffset(player.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
+ playerSender.playSound(randomOffset(playerSender.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
}
}.runTaskLater(plugin, Math.round(20.0 * percent * 2.0));
}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
index 2ed1ee36..85b1cb1f 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java
@@ -9,6 +9,7 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
import net.pravian.aero.util.Ips;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -19,14 +20,14 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
-@CommandParameters(description = "Sends the specified player to their doom.", usage = "/ ")
+@CommandParameters(description = "Sends the specified player to their doom.", usage = "/ [reason]")
public class Command_doom extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
- if (args.length != 1)
+ if (args.length == 0)
{
return false;
}
@@ -89,8 +90,17 @@ public class Command_doom extends FreedomCommand
// Shoot the player in the sky
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
+ String reason = null;
+
+ if (args.length > 1)
+ {
+ reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
+ }
+
+ final String kickReason = (reason == null ? "FUCKOFF, and get your shit together!" : reason);
+
// Log doom
- plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.DOOM, null));
+ plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.DOOM, reason));
new BukkitRunnable()
{
@@ -115,10 +125,10 @@ public class Command_doom extends FreedomCommand
msg(sender, player.getName() + " has been banned and IP is: " + ip);
// generate explosion
- player.getWorld().createExplosion(player.getLocation(), 0F, false);
+ player.getWorld().createExplosion(player.getLocation(), 0F, false);;
// kick player
- player.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
+ player.kickPlayer(ChatColor.RED + kickReason);
}
}.runTaskLater(plugin, 3L * 20L);
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java
new file mode 100644
index 00000000..8cd14f59
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java
@@ -0,0 +1,29 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.shop.ShopItem;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
+@CommandParameters(description = "Obtain a fire ball", usage = "/")
+public class Command_fireball extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (plugin.sh.getData(playerSender).hasItem(ShopItem.FIRE_BALL))
+ {
+ playerSender.getInventory().addItem(plugin.sh.getFireBall());
+ msg("You have been given a Fire Ball", ChatColor.GREEN);
+ }
+ else
+ {
+ msg("You do not own a Fire Ball! Purchase one from the shop.", ChatColor.RED);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java
new file mode 100644
index 00000000..c423ab3e
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java
@@ -0,0 +1,29 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.shop.ShopItem;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
+@CommandParameters(description = "Obtain a grappling hook", usage = "/")
+public class Command_grapplinghook extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (plugin.sh.getData(playerSender).hasItem(ShopItem.GRAPPLING_HOOK))
+ {
+ playerSender.getInventory().addItem(plugin.sh.getGrapplingHook());
+ msg("You have been given a Grappling Hook", ChatColor.GREEN);
+ }
+ else
+ {
+ msg("You do not own a Grappling Hook! Purchase one from the shop.", ChatColor.RED);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_idfk.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_idfk.java
deleted file mode 100644
index d8b7e61b..00000000
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_idfk.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package me.totalfreedom.totalfreedommod.command;
-
-import me.totalfreedom.totalfreedommod.rank.Rank;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.util.Vector;
-import java.util.Random;
-
-@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
-@CommandParameters(description = "i dont fucking know, what even", usage = "thot if you dont know what this does then dont use it")
-public class Command_idfk extends FreedomCommand
-{
-
- public static final String[] DRUNK_LINES = new String[]{"i is thy best bitch in teh world xD xD xD",
- "ooga boga ooga boga ooga boga ooga boga", "jake u dog fukr", "nero is a nice black pussy",
- "robin has a perfect penis", "ABABABABABABABABABA ABAOBOABOBA", "agge is a fuckin egg",
- "explosive errors == explosive arrows", "sync; echo 3 > /proc/sys/vm/drop_caches", "yeet",
- "si", "bubble bass thicc :weary::sweat_drops: :ok_hand:", "diabeetus", "McDiabeto", "oh",
- "say heck to diabetes im having chocolate cake"};
-
- private static final Random random = new Random();
-
- @Override
- public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
- {
- if (args.length == 0)
- {
- return false;
- }
-
- switch (args[0])
- {
- case "killmepls":
- playerSender.setHealth(0);
- msg("ok u wanted die u now die");
- break;
- case "robin":
- msg("robin is a meme xD xD xD");
- break;
- case "succ":
- playerSender.chat("mmmmm *suckle* *suckle* daddy");
- break;
- case "drunk":
- msg(DRUNK_LINES[random.nextInt(DRUNK_LINES.length)]);
- break;
- case "zero":
- msg("WATCH ZERO KARA HAJIMERU MAHOU NO SHO (GRIMOIRE OF ZERO) TODAY! https://kissanime.ru/anime/zero-kara-hajimeru-mahou-no-sho");
- break;
- case "boom":
- msg("allahu akbar bitch");
- playerSender.getWorld().createExplosion(playerSender.getLocation(), 0F);
- break;
- case "rocket":
- playerSender.setVelocity(new Vector(0, 1000, 0));
- msg("*insert shooting stars meme here*");
- break;
- case "fuck":
- playerSender.chat("wow robin is gay xdxdxd");
- msg("i tried");
- msg("and as in i tried as in robin tried to code this in");
- msg("lol xd");
- break;
- default:
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java
new file mode 100644
index 00000000..358a188c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java
@@ -0,0 +1,29 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.shop.ShopItem;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
+@CommandParameters(description = "Obtain a lightning rod", usage = "/")
+public class Command_lightningrod extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (plugin.sh.getData(playerSender).hasItem(ShopItem.LIGHTNING_ROD))
+ {
+ playerSender.getInventory().addItem(plugin.sh.getLightningRod());
+ msg("You have been given a Lightning Rod", ChatColor.GREEN);
+ }
+ else
+ {
+ msg("You do not own a Lightning Rod! Purchase one from the shop.", ChatColor.RED);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java
index 5040e976..8251bf82 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java
@@ -1,212 +1,200 @@
package me.totalfreedom.totalfreedommod.command;
-import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopData;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
-import me.totalfreedom.totalfreedommod.util.FUtil;
-import org.bukkit.Bukkit;
+import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
-@CommandParameters(description = "Manage the shop", usage = "/ | items: - >", aliases = "ms")
+@CommandParameters(description = "Manage the shop", usage = "/ | items:
- ", aliases = "ms")
public class Command_manageshop extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
- final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
- if (args.length > 3)
+ if (args.length < 2)
{
- if (args[0].equalsIgnoreCase("coins"))
+ return false;
+ }
+ if (args[0].equals("coins"))
+ {
+ if (args.length < 4)
{
- if (getPlayer(args[3]) != null || args[3].equals("all"))
- {
- Player p = null;
- ShopData sd = null;
- if (!args[3].equals("all"))
+ return false;
+ }
+ switch (args[1])
+ {
+
+ case "add":
+ try
{
- p = getPlayer(args[3]);
- sd = plugin.sh.getData(p);
+ int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
+ if (!args[3].equals("all"))
+ {
+ Player player = getPlayer(args[3]);
+ if (player == null)
+ {
+ msg(PLAYER_NOT_FOUND);
+ return true;
+ }
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.setCoins(shopData.getCoins() + amount);
+ plugin.sh.save(shopData);
+ msg("Successfully added " + amount + " coins to " + player.getName() + ". Their new balance is " + shopData.getCoins(), ChatColor.GREEN);
+ player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + shopData.getCoins());
+ return true;
+ }
+ else
+ {
+ for (Player player : server.getOnlinePlayers())
+ {
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.setCoins(shopData.getCoins() + amount);
+ plugin.sh.save(shopData);
+ player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + shopData.getCoins());
+ }
+ msg("Successfully added " + amount + " coins to all online players.", ChatColor.GREEN);
+ return true;
+ }
}
- int newAmount;
- int num;
- switch (args[1])
+ catch (NumberFormatException ex)
{
- case "add":
- try
- {
- num = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
- if (!args[3].equals("all"))
- {
- newAmount = sd.getCoins() + num;
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.GREEN + "Gave " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins to " + p.getName() + ", " + p.getName() + " now has " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- p.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " gave you " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins, you now have " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- return true;
- }
- else
- {
- for (Player player : server.getOnlinePlayers())
- {
- sd = plugin.sh.getData(player);
- newAmount = sd.getCoins() + num;
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- player.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " gave you " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins, you now have " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- }
- msg(prefix + ChatColor.GREEN + "Gave " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins to everyone.");
- return true;
- }
- }
- catch (NumberFormatException ex)
- {
- msg("Invalid number: " + args[2], ChatColor.RED);
- return true;
- }
- case "set":
- try
- {
- newAmount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
- if (!args[3].equals("all"))
- {
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.GREEN + "Set " + p.getName() + "'s coin amount to " + ChatColor.RED + newAmount + ChatColor.GREEN + ".");
- p.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " set your coin amount to " + args[2] + ChatColor.GREEN + ".");
- return true;
- }
- else
- {
- newAmount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
- for (Player player : server.getOnlinePlayers())
- {
- sd = plugin.sh.getData(player);
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- player.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " set your coin amount to " + args[2] + ChatColor.GREEN + ".");
- }
- msg(prefix + ChatColor.GREEN + "Set everyones's coin amount to " + ChatColor.RED + newAmount + ChatColor.GREEN + ".");
- return true;
- }
- }
- catch (NumberFormatException ex)
- {
- msg("Invalid number: " + args[2], ChatColor.RED);
- return true;
- }
- case "remove":
- try
- {
- num = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
- if (!args[3].equals("all"))
- {
- if (num > sd.getCoins())
- {
- msg(prefix + "You can't give a player a negative amount of coins, I'm sorry, you can't put anyone in debt.", ChatColor.RED);
- return true;
- }
- newAmount = sd.getCoins() - num;
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.GREEN + "Took " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins from " + p.getName() + ", " + p.getName() + " now has " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- p.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " took " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins from you, you now have " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- return true;
- }
- else
- {
- for (Player player : server.getOnlinePlayers())
- {
- sd = plugin.sh.getData(player);
- if (num > sd.getCoins())
- {
- sd.setCoins(0);
- }
- newAmount = sd.getCoins() - num;
- sd.setCoins(newAmount);
- plugin.sh.save(sd);
- player.sendMessage(prefix + ChatColor.GREEN + sender.getName() + " took " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins from you, you now have " + ChatColor.RED + sd.getCoins() + ChatColor.GREEN + " coins.");
- }
- msg(prefix + ChatColor.GREEN + "Took " + ChatColor.RED + args[2] + ChatColor.GREEN + " coins from everyone.");
- return true;
- }
- }
- catch (NumberFormatException ex)
- {
- msg("Invalid number: " + args[2], ChatColor.RED);
- return true;
- }
- default:
- break;
+ msg("Invalid number: " + args[2], ChatColor.RED);
+ return true;
}
- }
- else
+ case "remove":
+ try
+ {
+ int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
+ if (!args[3].equals("all"))
+ {
+ Player player = getPlayer(args[3]);
+ if (player == null)
+ {
+ msg(PLAYER_NOT_FOUND);
+ return true;
+ }
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.setCoins(shopData.getCoins() + amount);
+ if (shopData.getCoins() < 0)
+ {
+ shopData.setCoins(0);
+ }
+ plugin.sh.save(shopData);
+ msg("Successfully removed " + amount + " coins from " + player.getName() + ". Their new balance is " + shopData.getCoins(), ChatColor.GREEN);
+ player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + shopData.getCoins());
+ return true;
+ }
+ else
+ {
+ for (Player player : server.getOnlinePlayers())
+ {
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.setCoins(shopData.getCoins() - amount);
+ if (shopData.getCoins() < 0)
+ {
+ shopData.setCoins(0);
+ }
+ plugin.sh.save(shopData);
+ player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + shopData.getCoins());
+ }
+ msg("Successfully took " + amount + " coins from all online players.", ChatColor.GREEN);
+ return true;
+ }
+ }
+ catch (NumberFormatException ex)
+ {
+ msg("Invalid number: " + args[2], ChatColor.RED);
+ return true;
+ }
+ case "set":
+ try
+ {
+ int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
+ Player player = getPlayer(args[3]);
+ if (player == null)
+ {
+ msg(PLAYER_NOT_FOUND);
+ return true;
+ }
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.setCoins(amount);
+ plugin.sh.save(shopData);
+ msg("Successfully set " + player.getName() + "'s coins to " + amount, ChatColor.GREEN);
+ player.sendMessage(ChatColor.GREEN + sender.getName() + " set your coin balance to " + amount);
+ return true;
+ }
+ catch (NumberFormatException ex)
+ {
+ msg("Invalid number: " + args[2], ChatColor.RED);
+ return true;
+ }
+ }
+ }
+ else if (args[0].equals("items"))
+ {
+ if (args[1].equals("list"))
+ {
+ msg("List of all shop items: " + StringUtils.join(ShopItem.values(), ", "));
+ return true;
+ }
+
+ if (args.length < 4)
+ {
+ return false;
+ }
+
+ if (args[1].equals("give"))
+ {
+ ShopItem item = ShopItem.findItem(args[2].toUpperCase());
+ if (item == null)
{
- msg(FreedomCommand.PLAYER_NOT_FOUND);
+ msg(args[2] + " is not a valid item.", ChatColor.RED);
return true;
}
- }
- if (args[0].equalsIgnoreCase("items"))
- {
- switch (args[1])
+
+ Player player = getPlayer(args[3]);
+ if (player == null)
{
- case "give":
- {
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- msg(FreedomCommand.PLAYER_NOT_FOUND);
- return true;
- }
- ShopItem item = ShopItem.findItem(args[3]);
- if (item == null)
- {
- msg("Invalid item: " + item);
- return true;
- }
- ShopData sd = plugin.sh.getData(player);
- if (sd.hasItem(item))
- {
- msg("That player already has a(n) " + item.getName() + "!");
- return true;
- }
- String key = sd.giveItem(item);
- plugin.sh.save(sd);
- FUtil.give(player, item, ChatColor.DARK_GRAY + key);
- msg(prefix + ChatColor.GREEN + "Gave " + ChatColor.RED + player.getName() + ChatColor.GREEN + " a(n) " + item.getColoredName());
- return true;
- }
- case "remove":
- {
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- msg(FreedomCommand.PLAYER_NOT_FOUND);
- return true;
- }
- ShopItem item = ShopItem.findItem(args[3]);
- if (item == null)
- {
- msg("Invalid item: " + item);
- return true;
- }
- ShopData sd = plugin.sh.getData(player);
- if (!sd.hasItem(item))
- {
- msg("That player doesn't have a(n) " + item.getName() + "!");
- return true;
- }
- sd.takeItem(item);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.GREEN + "Took " + ChatColor.RED + player.getName() + ChatColor.GREEN + "'s " + item.getColoredName());
- return true;
- }
+ msg(PLAYER_NOT_FOUND);
+ return true;
}
+
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.giveItem(item);
+ plugin.sh.save(shopData);
+ msg("Successfully gave the " + item.getName() + " to " + player.getName(), ChatColor.GREEN);
+ player.sendMessage(ChatColor.GREEN + sender.getName() + " gave the " + item.getName() + " to you");
+ return true;
}
+ else if (args[1].equals("take"))
+ {
+ ShopItem item = ShopItem.findItem(args[2].toUpperCase());
+ if (item == null)
+ {
+ msg(args[2] + " is not a valid item.", ChatColor.RED);
+ return true;
+ }
+
+ Player player = getPlayer(args[3]);
+ if (player == null)
+ {
+ msg(PLAYER_NOT_FOUND);
+ return true;
+ }
+
+ ShopData shopData = plugin.sh.getData(player);
+ shopData.removeItem(item);
+ plugin.sh.save(shopData);
+ msg("Successfully took the " + item.getName() + " from " + player.getName(), ChatColor.GREEN);
+ player.sendMessage(ChatColor.RED + sender.getName() + " took the " + item.getName() + " from you");
+ return true;
+ }
+
}
return false;
}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java
index fa561eb1..1cba5af2 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java
@@ -104,13 +104,19 @@ public class Command_ride extends FreedomCommand
return true;
}
+ if (player.getName().equals("Catholic_Mario"))
+ {
+ msg("no", ChatColor.RED);
+ return true;
+ }
+
if (vPlayer.getRideMode().equals("ask") && !isAdmin(sender))
{
- msg("Sent a request to the player.");
- player.sendMessage(ChatColor.GRAY + sender.getName() + " has requested to ride you.");
- player.sendMessage(ChatColor.GRAY + "Type " + ChatColor.DARK_GRAY + "/ride accept" + ChatColor.GRAY + " to allow the player to ride you.");
- player.sendMessage(ChatColor.GRAY + "Type " + ChatColor.DARK_GRAY + "/ride deny" + ChatColor.GRAY + " to deny the player permission.");
- player.sendMessage(ChatColor.GRAY + "Request will expire after 30 seconds.");
+ msg("Sent a request to the player.", ChatColor.GREEN);
+ player.sendMessage(ChatColor.AQUA + sender.getName() + " has requested to ride you.");
+ player.sendMessage(ChatColor.AQUA + "Type " + ChatColor.GREEN + "/ride accept" + ChatColor.AQUA + " to allow the player to ride you.");
+ player.sendMessage(ChatColor.AQUA + "Type " + ChatColor.RED + "/ride deny" + ChatColor.AQUA + " to deny the player permission.");
+ player.sendMessage(ChatColor.AQUA + "Request will expire after 30 seconds.");
RIDE_REQUESTS.put(player, playerSender);
FreedomCommandExecutor.timer.schedule(new TimerTask()
{
@@ -122,8 +128,8 @@ public class Command_ride extends FreedomCommand
return;
}
RIDE_REQUESTS.remove(player);
- msg("Request expired.");
- player.sendMessage(ChatColor.GRAY + "Request expired.");
+ msg("Request expired.", ChatColor.RED);
+ player.sendMessage(ChatColor.RED + "Request expired.");
}
}, 30000);
return true;
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java
new file mode 100644
index 00000000..23923be1
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java
@@ -0,0 +1,29 @@
+package me.totalfreedom.totalfreedommod.command;
+
+import me.totalfreedom.totalfreedommod.rank.Rank;
+import me.totalfreedom.totalfreedommod.shop.ShopItem;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
+@CommandParameters(description = "Obtain a rideable ender pearl", usage = "/")
+public class Command_rideablepearl extends FreedomCommand
+{
+
+ @Override
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ {
+ if (plugin.sh.getData(playerSender).hasItem(ShopItem.RIDEABLE_PEARL))
+ {
+ playerSender.getInventory().addItem(plugin.sh.getRideablePearl());
+ msg("You have been given a Rideable Ender Pearl", ChatColor.GREEN);
+ }
+ else
+ {
+ msg("You do not own a Rideable Ender Pearl! Purchase one from the shop.", ChatColor.RED);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java
index 91bd0d19..ae3e5fff 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java
@@ -1,175 +1,26 @@
package me.totalfreedom.totalfreedommod.command;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
-import me.totalfreedom.totalfreedommod.shop.ShopData;
-import me.totalfreedom.totalfreedommod.shop.ShopItem;
-import me.totalfreedom.totalfreedommod.util.FUtil;
+import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
-@CommandParameters(description = "Access the shop - this will be much simplified in the future.", usage = "/ | action | list>")
+@CommandParameters(description = "Open the shop GUI", usage = "/", aliases = "sh")
public class Command_shop extends FreedomCommand
{
- private final List locations = Arrays.asList("Sofa", "Car", "Bed", "Kitchen", "Garage", "Basement", "Home Study");
- private Map featureCooldown = new HashMap<>();
@Override
- public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
+ public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
msg("The shop is currently disabled!", ChatColor.RED);
return true;
}
- final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
- ShopData sd = plugin.sh.getData(playerSender);
- if (args.length == 0)
- {
- msg(prefix + ChatColor.GREEN + "Balance: " + ChatColor.RED + sd.getCoins());
- return true;
- }
- if (args.length == 1)
- {
- if (featureCooldown.containsKey(sender) && featureCooldown.containsValue(args[0]))
- {
- msg("You're on cooldown for this feature.", ChatColor.RED);
- return true;
- }
- Random r = new Random();
- switch (args[0])
- {
- case "daily":
- {
- sd.setCoins(sd.getCoins() + 100);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.GREEN + "You received your 100 coins!");
- cooldown(86400, sender, args[0]);
- return true;
- }
- case "search":
- {
- int amount = FUtil.random(5, 10);
- String location = locations.get(r.nextInt(locations.size()));
- sd.setCoins(sd.getCoins() + amount);
- plugin.sh.save(sd);
- msg(prefix + ChatColor.AQUA + location + ChatColor.GREEN + " - Found " + ChatColor.RED + amount + ChatColor.GREEN + " coins!");
- cooldown(30, sender, args[0]);
- return true;
- }
- case "list":
- case "items":
- {
- msg(prefix + ChatColor.GREEN + "Available items:");
- for (ShopItem item : ShopItem.values())
- {
- if (!item.isPurchaseable())
- {
- continue;
- }
- msg(prefix + ChatColor.AQUA + item.getName() + ChatColor.GREEN + " - " + ChatColor.RED + item.getCost());
- }
- return true;
- }
- }
- Player player = getPlayer(args[0]);
- if (player == null)
- {
- msg(PLAYER_NOT_FOUND);
- return true;
- }
- ShopData psd = plugin.sh.getData(player);
- msg(prefix + ChatColor.AQUA + player.getName() + ChatColor.GREEN + "'s balance: " + ChatColor.RED + psd.getCoins());
- return true;
- }
- if (args.length != 2)
- {
- return false;
- }
- switch (args[0])
- {
- case "buy":
- {
- ShopItem item = ShopItem.findItem(args[1]);
- if (item == null || !item.isPurchaseable())
- {
- msg("Invalid item: " + item);
- return true;
- }
- if (sd.hasItem(item))
- {
- msg(prefix + ChatColor.GREEN + "You already have that item! To get it, use " + ChatColor.RED + "/shop get " + item.name() + ChatColor.GREEN + "!");
- return true;
- }
- if (item.getCost() > sd.getCoins())
- {
- msg(prefix + ChatColor.GREEN + "You don't have enough money for this item!");
- return true;
- }
- String signature = sd.giveItem(item);
- sd.setCoins(sd.getCoins() - item.getCost());
- plugin.sh.save(sd);
- ItemStack stack = new ItemStack(item.getMaterial(), 1);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(item.getColoredName());
- List lore = new ArrayList<>();
- lore.add(ChatColor.DARK_GRAY + signature);
- meta.setLore(lore);
- stack.setItemMeta(meta);
- Inventory inv = playerSender.getInventory();
- inv.setItem(inv.firstEmpty(), stack);
- msg(prefix + ChatColor.GREEN + "You bought a " + item.getColoredName() + ChatColor.GREEN + "!");
- return true;
- }
- case "get":
- {
- ShopItem item = ShopItem.findItem(args[1]);
- if (item == null)
- {
- msg("Invalid item: " + item);
- return true;
- }
- if (!sd.hasItem(item))
- {
- msg(prefix + ChatColor.GREEN + "You don't have that item! To buy it, use " + ChatColor.RED + "/shop buy " + item.name() + ChatColor.GREEN + "!");
- return true;
- }
- Inventory inv = playerSender.getInventory();
- inv.setItem(inv.firstEmpty(), sd.getItem(item));
- msg(prefix + ChatColor.GREEN + "You got your " + item.getColoredName() + ChatColor.GREEN + "!");
- return true;
- }
- default:
- {
- return false;
- }
- }
+ playerSender.openInventory(plugin.sh.generateShopGUI(plugin.sh.getData(playerSender)));
+ return true;
}
-
- private void cooldown(int seconds, CommandSender sender, String feature)
- {
- featureCooldown.put(sender, feature);
- new BukkitRunnable()
- {
- @Override
- public void run()
- {
- featureCooldown.remove(sender);
- }
- }.runTaskLater(plugin, seconds * 20);
- }
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
index 6d5bc1e9..b7fc533a 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java
@@ -81,7 +81,13 @@ public enum ConfigEntry
DISCORD_SERVER_OWNER_ROLE_ID(String.class, "discord.server_owner_role_id"),
//
SHOP_ENABLED(Boolean.class, "shop.enabled"),
+ SHOP_TITLE(String.class, "shop.title"),
SHOP_PREFIX(String.class, "shop.prefix"),
+ SHOP_COINS_PER_VOTE(Integer.class, "shop.coins_per_vote"),
+ SHOP_PRICES_GRAPPLING_HOOK(Integer.class, "shop.prices.grappling_hook"),
+ SHOP_PRICES_LIGHTNING_ROD(Integer.class, "shop.prices.lightning_rod"),
+ SHOP_PRICES_FIRE_BALL(Integer.class, "shop.prices.fire_ball"),
+ SHOP_PRICES_RIDEABLE_PEARL(Integer.class, "shop.prices.rideable_pearl"),
//
ADMINLIST_CLEAN_THESHOLD_HOURS(Integer.class, "adminlist.clean_threshold_hours"),
ADMINLIST_CONSOLE_IS_SENIOR(Boolean.class, "adminlist.console_is_senior"),
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java
index 35d08602..c6d3484d 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java
@@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.UUID;
import javax.security.auth.login.FailedLoginException;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
@@ -19,11 +20,18 @@ import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import org.bukkit.Color;
+import org.bukkit.FireworkEffect;
+import org.bukkit.SoundCategory;
import org.bukkit.entity.Arrow;
+import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
+import org.bukkit.entity.Firework;
+import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.ProjectileHitEvent;
+import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@@ -37,7 +45,9 @@ import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
+import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
public class ItemFun extends FreedomService
@@ -47,41 +57,41 @@ public class ItemFun extends FreedomService
private final Random random = new Random();
- private static final String COOLDOWN_MESSAGE = ChatColor.RED + "You're on cooldown for this feature.";
-
private final Map> cooldownTracker = new HashMap<>();
private final Map orientationTracker = new HashMap<>();
- private void cooldown(Player player, String feature, int seconds)
+ private final List FIRE_BALL_UUIDS = new ArrayList<>();
+
+ private void cooldown(Player player, ShopItem item, int seconds)
{
if (cooldownTracker.get(player.getName()) == null)
{
List featureList = new ArrayList<>();
- featureList.add(feature);
+ featureList.add(item.getDataName());
cooldownTracker.put(player.getName(), featureList);
}
else
{
- cooldownTracker.get(player.getName()).add(feature);
+ cooldownTracker.get(player.getName()).add(item.getDataName());
}
- new BukkitRunnable()
+ BukkitTask thing = new BukkitRunnable()
{
@Override
public void run()
{
- cooldownTracker.get(player.getName()).remove(feature);
+ cooldownTracker.get(player.getName()).remove(item.getDataName());
}
}.runTaskLater(plugin, seconds * 20);
}
- public boolean onCooldown(Player player, String feature)
+ public boolean onCooldown(Player player, ShopItem item)
{
if (cooldownTracker.get(player.getName()) == null)
{
return false;
}
- return cooldownTracker.get(player.getName()).contains(feature);
+ return cooldownTracker.get(player.getName()).contains(item.getDataName());
}
public ItemFun(TotalFreedomMod plugin)
@@ -193,11 +203,6 @@ public class ItemFun extends FreedomService
{
break;
}
-
- /*if (player.getWorld().equals(plugin.wm.hubworld.getWorld()) && plugin.hwr.doRestrict(player))
- {
- break;
- }*/
Location location = player.getLocation().clone();
@@ -292,58 +297,14 @@ public class ItemFun extends FreedomService
case BLAZE_ROD:
{
- if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
+ if (!plugin.sh.isRealItem(plugin.sh.getData(player), ShopItem.LIGHTNING_ROD, player.getInventory().getItemInMainHand(), plugin.sh.getLightningRod()))
{
break;
}
- if (!plugin.al.isSeniorAdmin(player))
- {
- break;
- }
-
- if (player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld()) && plugin.mbwr.doRestrict(player))
- {
- break;
- }
-
- event.setCancelled(true);
- Block targetBlock;
-
- if (event.getAction().equals(Action.LEFT_CLICK_AIR))
- {
- targetBlock = DepreciationAggregator.getTargetBlock(player, null, 120);
- }
- else
- {
- targetBlock = event.getClickedBlock();
- }
-
- if (targetBlock == null)
- {
- player.sendMessage("Can't resolve target block.");
- break;
- }
-
- player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
- player.getWorld().strikeLightning(targetBlock.getLocation());
-
- break;
- }
-
- case NETHER_STAR:
- {
- if (onCooldown(player, "nether_star"))
- {
- FUtil.playerMsg(player, COOLDOWN_MESSAGE);
- break;
- }
-
- ShopData sd = plugin.sh.getData(player);
- ItemStack stack = player.getInventory().getItemInMainHand();
-
- if (!sd.validate(stack, ShopItem.THOR_STAR))
+ if (onCooldown(player, ShopItem.LIGHTNING_ROD))
{
+ player.sendMessage(ChatColor.RED + "You're are currently on a cooldown for 10 seconds.");
break;
}
@@ -354,65 +315,43 @@ public class ItemFun extends FreedomService
{
player.getWorld().strikeLightning(targetBlock.getLocation());
}
-
- boolean superior = FUtil.random(1, 100) == 50;
- Player rplayer = FUtil.getRandomPlayer();
- ShopData psd = plugin.sh.getData(rplayer);
- 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, 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, ShopItem.ELECTRICAL_DIAMOND_SWORD, "&7RMB - Strike lightning", ChatColor.DARK_GRAY + key);
- }
- plugin.sh.save(psd);
- cooldown(player, "nether_star", 600);
+ cooldown(player, ShopItem.LIGHTNING_ROD, 10);
break;
}
- case DIAMOND_SWORD:
+ case FIRE_CHARGE:
{
- if (onCooldown(player, "eds"))
+ if (!plugin.sh.isRealItem(plugin.sh.getData(player), ShopItem.FIRE_BALL, player.getInventory().getItemInMainHand(), plugin.sh.getFireBall()))
{
- FUtil.playerMsg(player, COOLDOWN_MESSAGE);
break;
}
- ShopData sd = plugin.sh.getData(player);
- ItemStack stack = player.getInventory().getItemInMainHand();
- if (sd.validate(stack, "Electrical Diamond Sword"))
+ if (onCooldown(player, ShopItem.FIRE_BALL))
{
- player.getWorld().strikeLightning(player.getTargetBlock(null, 20).getLocation());
- cooldown(player, "eds", 15);
+ player.sendMessage(ChatColor.RED + "You're are currently on a cooldown for 5 seconds.");
+ break;
}
+
+ event.setCancelled(true);
+ Entity fireball = player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREBALL);
+ FIRE_BALL_UUIDS.add(fireball.getUniqueId());
+ fireball.setVelocity(player.getLocation().getDirection().multiply(2));
+ cooldown(player, ShopItem.FIRE_BALL, 5);
break;
}
+ }
+ }
- case GOLDEN_SWORD:
+ @EventHandler
+ public void onProjectileLaunch(ProjectileLaunchEvent event)
+ {
+ Projectile entity = event.getEntity();
+ if (entity instanceof EnderPearl && entity.getShooter() instanceof Player)
+ {
+ Player player = (Player)entity.getShooter();
+ if (plugin.sh.isRealItem(plugin.sh.getData(player), ShopItem.RIDEABLE_PEARL, player.getInventory().getItemInMainHand(), plugin.sh.getRideablePearl()))
{
- if (onCooldown(player, "ss"))
- {
- FUtil.playerMsg(player, COOLDOWN_MESSAGE);
- break;
- }
-
- ShopData sd = plugin.sh.getData(player);
- ItemStack stack = player.getInventory().getItemInMainHand();
- if (sd.validate(stack, "Superior Sword"))
- {
- Entity fireball = player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREBALL);
- fireball.setVelocity(player.getLocation().getDirection());
- cooldown(player, "ss", 3);
- }
+ entity.addPassenger(player);
}
}
}
@@ -434,6 +373,24 @@ public class ItemFun extends FreedomService
arrow.remove();
}
}
+
+ if (entity instanceof Fireball)
+ {
+ if (FIRE_BALL_UUIDS.contains(entity.getUniqueId()))
+ {
+ FIRE_BALL_UUIDS.remove(entity.getUniqueId());
+ Firework firework = (Firework)entity.getWorld().spawnEntity(entity.getLocation(), EntityType.FIREWORK);
+ firework.setSilent(true);
+ FireworkMeta meta = firework.getFireworkMeta();
+ FireworkEffect explosionEffect = FireworkEffect.builder().withColor(Color.ORANGE).withFade(Color.YELLOW).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
+ meta.addEffect(explosionEffect);
+ meta.setPower(0);
+ firework.setFireworkMeta(meta);
+ entity.remove();
+ firework.detonate();
+ entity.getWorld().playSound(firework.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 10f, 1f);
+ }
+ }
}
private Location randomOffset(Location a, double magnitude)
@@ -453,7 +410,7 @@ public class ItemFun extends FreedomService
ShopData sd = plugin.sh.getData(player);
PlayerInventory inv = event.getPlayer().getInventory();
ItemStack rod = inv.getItemInMainHand();
- if (sd.validate(rod, ShopItem.GRAPPLING_HOOK))
+ if (plugin.sh.isRealItem(plugin.sh.getData(player), ShopItem.GRAPPLING_HOOK, player.getInventory().getItemInMainHand(), plugin.sh.getGrapplingHook()))
{
if (event.getState() == PlayerFishEvent.State.REEL_IN || event.getState() == PlayerFishEvent.State.IN_GROUND)
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java
index 867b0a96..0b27e205 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java
@@ -24,6 +24,7 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_permbans;
import me.totalfreedom.totalfreedommod.httpd.module.Module_players;
import me.totalfreedom.totalfreedommod.httpd.module.Module_punishments;
import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic;
+import me.totalfreedom.totalfreedommod.httpd.module.Module_vpnbans;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
@@ -69,6 +70,7 @@ public class HTTPDaemon extends FreedomService
module("players", Module_players.class, false);
module("punishments", Module_punishments.class, true);
module("schematic", Module_schematic.class, true);
+ module("vpnbans", Module_vpnbans.class, true);
try
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_vpnbans.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_vpnbans.java
new file mode 100644
index 00000000..c5d0bd9b
--- /dev/null
+++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_vpnbans.java
@@ -0,0 +1,32 @@
+package me.totalfreedom.totalfreedommod.httpd.module;
+
+import java.io.File;
+import me.totalfreedom.totalfreedommod.TotalFreedomMod;
+import me.totalfreedom.totalfreedommod.banning.VPNBanList;
+import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
+import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
+
+public class Module_vpnbans extends HTTPDModule
+{
+
+ public Module_vpnbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
+ {
+ super(plugin, session);
+ }
+
+ @Override
+ public NanoHTTPD.Response getResponse()
+ {
+ File vpnbanFile = new File(plugin.getDataFolder(), VPNBanList.CONFIG_FILENAME);
+
+ if (vpnbanFile.exists())
+ {
+ return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), VPNBanList.CONFIG_FILENAME));
+ }
+ else
+ {
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
+ "Error 404: Not Found - The requested resource was not found on this server.");
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java
index ea6120e2..6ddb455a 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java
@@ -61,12 +61,6 @@ public class RankManager extends FreedomService
{
return Title.DEVELOPER;
}
-
- // Contributors always show up
- if (FUtil.CONTRIBUTORS.contains(player.getName()))
- {
- return Title.CONTRIBUTOR;
- }
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && plugin.al.isAdmin(player))
{
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java
index 4061dbeb..b5fd00f4 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java
@@ -11,7 +11,6 @@ public enum Title implements Displayable
ASSISTANT_EXECUTIVE("an", "Assistant Executive", ChatColor.RED, "Asst Exec"),
EXECUTIVE("an", "Executive", ChatColor.RED, "Exec"),
DEVELOPER("a", "Developer", ChatColor.DARK_PURPLE, "Dev"),
- CONTRIBUTOR("a", "TotalFreedom Contributor", ChatColor.DARK_PURPLE, "Contributor"),
OWNER("the", "Owner", ChatColor.DARK_RED, "Owner");
private final String determiner;
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java
index 53a1c388..c31f53e5 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java
@@ -1,9 +1,15 @@
package me.totalfreedom.totalfreedommod.shop;
import com.google.common.collect.Maps;
+import com.vexsoftware.votifier.model.Vote;
+import com.vexsoftware.votifier.model.VotifierEvent;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
@@ -12,18 +18,22 @@ import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.config.YamlConfig;
import net.pravian.aero.util.Ips;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.OfflinePlayer;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
+import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
public class Shop extends FreedomService
{
@Getter
- public final Map dataMap = Maps.newHashMap(); // ip,dataMap
+ public final Map dataMap = Maps.newHashMap(); // uuid, dataMap
@Getter
private final File configFolder;
@@ -54,37 +64,32 @@ public class Shop extends FreedomService
YamlConfig config = getConfig(data);
data.saveTo(config);
config.save();
- }
-
- public String getIp(OfflinePlayer player)
- {
- if (player.isOnline())
- {
- return Ips.getIp(player.getPlayer());
- }
-
- final ShopData entry = getData(player.getName());
-
- return (entry == null ? null : entry.getIps().iterator().next());
+ dataMap.remove(data.getUUID());
+ dataMap.put(data.getUUID(), data);
}
public String getShopPrefix()
{
- return FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
+ return FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString());
+ }
+
+ public String getShopTitle()
+ {
+ return FUtil.colorize(ConfigEntry.SHOP_TITLE.getString());
}
// May not return null
public ShopData getData(Player player)
{
// Check already loaded
- ShopData data = dataMap.get(Ips.getIp(player));
+ ShopData data = dataMap.get(player.getUniqueId());
if (data != null)
{
return data;
}
// Load data
- data = getData(player.getName());
+ data = getData(player.getUniqueId());
// Create data if nonexistent
if (data == null)
@@ -92,15 +97,14 @@ public class Shop extends FreedomService
FLog.info("Creating new shop data entry for " + player.getName());
// Create new player
- final long unix = FUtil.getUnixTime();
data = new ShopData(player);
- data.addIp(Ips.getIp(player));
+ data.setUsername(player.getName());
// Set defaults
data.setCoins(0);
// Store player
- dataMap.put(player.getName().toLowerCase(), data);
+ dataMap.put(player.getUniqueId(), data);
// Save player
YamlConfig config = getConfig(data);
@@ -108,46 +112,231 @@ public class Shop extends FreedomService
config.save();
}
+ dataMap.put(player.getUniqueId(), data);
+
return data;
}
- // May return null
public ShopData getData(String username)
{
- username = username.toLowerCase();
+ UUID uuid = FUtil.nameToUUID(username);
+ if (uuid != null)
+ {
+ return getData(uuid);
+ }
+ return null;
+ }
+ public ShopData getData(UUID uuid)
+ {
// Check if the player is a known player
- final File configFile = getConfigFile(username);
+ final File configFile = getConfigFile(uuid);
if (!configFile.exists())
{
return null;
}
- // Create and load entry
- final ShopData data = new ShopData(username);
+ // Load entry
+ final ShopData data = new ShopData(uuid);
data.loadFrom(getConfig(data));
+ return data;
+ }
- if (!data.isValid())
+ public Inventory generateShopGUI(ShopData shopData)
+ {
+ Inventory gui = server.createInventory(null, 36, getShopTitle());
+ for (int slot = 0; slot < 36; slot++)
{
- FLog.warning("Could not load shop data entry: " + username + ". Entry is not valid!");
- configFile.delete();
- return null;
+ ItemStack blank = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
+ ItemMeta meta = blank.getItemMeta();
+ meta.setDisplayName(" ");
+ blank.setItemMeta(meta);
+ gui.setItem(slot, blank);
+ }
+ for (ShopItem shopItem : ShopItem.values())
+ {
+ ItemStack item = shopGUIItem(shopItem, shopData);
+ gui.setItem(shopItem.getSlot(), item);
+ }
+ // Coins
+ ItemStack coins = new ItemStack(Material.GOLD_NUGGET);
+ ItemMeta meta = coins.getItemMeta();
+ meta.setDisplayName(FUtil.colorize("&c&lYou have &e&l" + shopData.getCoins() + "&c&l coins"));
+ coins.setItemMeta(meta);
+ gui.setItem(35, coins);
+ return gui;
+ }
+
+ public boolean isRealItem(ShopData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem)
+ {
+ if (!data.hasItem(shopItem) || !givenItem.getType().equals(realItem.getType()))
+ {
+ return false;
}
- // Only store data if the player is online
- for (String ip : data.getIps())
+ ItemMeta givenMeta = givenItem.getItemMeta();
+ ItemMeta realMeta = realItem.getItemMeta();
+
+ if (givenMeta.getDisplayName().equals(realMeta.getDisplayName()) && givenMeta.getLore().equals(realMeta.getLore()))
{
- for (Player onlinePlayer : Bukkit.getOnlinePlayers())
+ return true;
+ }
+
+ return false;
+ }
+
+ public ItemStack getLightningRod()
+ {
+ ItemStack itemStack = new ItemStack(Material.BLAZE_ROD);
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ itemMeta.setDisplayName(FUtil.colorize("&bL&3i&bg&3h&bt&3i&bn&3g &b&bR&3o&bd"));
+ itemMeta.setLore(Arrays.asList(ChatColor.AQUA + "Strike others down with the power of lightning.", ChatColor.RED + ChatColor.ITALIC.toString() + "The classic way to exterminate annoyances."));
+ itemMeta.addEnchant(Enchantment.CHANNELING, 1, false);
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
+
+ public ItemStack getGrapplingHook()
+ {
+ ItemStack itemStack = new ItemStack(Material.FISHING_ROD);
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ itemMeta.setDisplayName(ChatColor.YELLOW + "Grappling Hook");
+ itemMeta.setLore(Arrays.asList(ChatColor.GREEN + "be spider-man but ghetto"));
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
+
+ public ItemStack getFireBall()
+ {
+ ItemStack itemStack = new ItemStack(Material.FIRE_CHARGE);
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ itemMeta.setDisplayName(ChatColor.RED + "Fire Ball");
+ itemMeta.setLore(Arrays.asList(ChatColor.GOLD+ "Yeet this at people"));
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
+
+ public ItemStack getRideablePearl()
+ {
+ ItemStack itemStack = new ItemStack(Material.ENDER_PEARL);
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ itemMeta.setDisplayName(ChatColor.DARK_PURPLE + "Rideable Ender Pearl");
+ itemMeta.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "What the title says.", "", ChatColor.WHITE + ChatColor.ITALIC.toString() + "TotalFreedom is not responsible for any injuries", ChatColor.WHITE + ChatColor.ITALIC.toString() + "sustained while using this item."));
+ itemMeta.addEnchant(Enchantment.BINDING_CURSE, 1, false);
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
+
+
+ public boolean canAfford(int price, int coins)
+ {
+ if (coins >= price)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public int amountNeeded(int price, int coins)
+ {
+ return price - coins;
+ }
+
+ public ItemStack shopGUIItem(ShopItem item, ShopData data)
+ {
+ ItemStack itemStack = new ItemStack(item.getIcon());
+ ItemMeta itemMeta = itemStack.getItemMeta();
+ itemMeta.setDisplayName(item.getColoredName());
+ int price = item.getCost();
+ int coins = data.getCoins();
+ Boolean canAfford = canAfford(price, coins);
+ List lore = new ArrayList();
+ if (!data.hasItem(item))
+ {
+ lore.add(ChatColor.GOLD + "Price: " + (canAfford ? ChatColor.DARK_GREEN : ChatColor.RED) + price);
+ if (!canAfford)
{
- if (Ips.getIp(onlinePlayer).equals(ip))
- {
- dataMap.put(ip, data);
- return data;
- }
+ lore.add(ChatColor.RED + "You can not afford this item!");
+ lore.add(ChatColor.RED + "You need " + amountNeeded(price, coins) + " more coins to buy this item.");
}
}
+ else
+ {
+ lore.add(ChatColor.RED + "You already purchased this item.");
+ }
+ itemMeta.setLore(lore);
+ itemStack.setItemMeta(itemMeta);
+ return itemStack;
+ }
- return data;
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onInventoryClick(InventoryClickEvent event)
+ {
+ if (!(event.getWhoClicked() instanceof Player))
+ {
+ return;
+ }
+
+ Inventory inventory = event.getInventory();
+ if (inventory.getSize() != 36 || !event.getView().getTitle().equals(plugin.sh.getShopTitle()))
+ {
+ return;
+ }
+ event.setCancelled(true);
+
+ ShopItem shopItem = getShopItem(event.getSlot());
+ if (shopItem == null)
+ {
+ return;
+ }
+
+ Player player = (Player) event.getWhoClicked();
+ ShopData shopData = plugin.sh.getData(player);
+ int price = shopItem.getCost();
+ int coins = shopData.getCoins();
+
+ if (shopData.hasItem(shopItem) || !plugin.sh.canAfford(price, coins))
+ {
+ return;
+ }
+
+ shopData.giveItem(shopItem);
+ shopData.setCoins(coins - price);
+ save(shopData);
+
+ player.closeInventory();
+
+ player.sendMessage(plugin.sh.getShopPrefix() + " " + ChatColor.GREEN + "Successfully purchased the \"" + shopItem.getColoredName() + ChatColor.GREEN + "\" for " + ChatColor.GOLD + price + ChatColor.GREEN + "!");
+
+ if (shopItem.equals(ShopItem.GRAPPLING_HOOK))
+ {
+ player.sendMessage(ChatColor.GREEN + "Run /grapplinghook to get one!");
+ }
+ else if (shopItem.equals(ShopItem.LIGHTNING_ROD))
+ {
+ player.sendMessage(ChatColor.GREEN + "Run /lightningrod to get one!");
+ }
+ else if (shopItem.equals(ShopItem.FIRE_BALL))
+ {
+ player.sendMessage(ChatColor.GREEN + "Run /fireball to get one!");
+ }
+ else if (shopItem.equals(ShopItem.RIDEABLE_PEARL))
+ {
+ player.sendMessage(ChatColor.GREEN + "Run /rideablepearl to get one!");
+ }
+
+ }
+
+ public ShopItem getShopItem(int slot)
+ {
+ for (ShopItem shopItem : ShopItem.values())
+ {
+ if (shopItem.getSlot() == slot)
+ {
+ return shopItem;
+ }
+ }
+ return null;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@@ -157,19 +346,50 @@ public class Shop extends FreedomService
dataMap.remove(ip);
}
+ @EventHandler(priority = EventPriority.NORMAL)
+ public void onPlayerVote(VotifierEvent event)
+ {
+ Vote vote = event.getVote();
+ String name = vote.getUsername();
+ int coinsPerVote = ConfigEntry.SHOP_COINS_PER_VOTE.getInteger();
+ Player player = server.getPlayer(name);
+ ShopData data = null;
+ if (player != null)
+ {
+ data = plugin.sh.getData(player);
+ }
+ else
+ {
+ data = plugin.sh.getData(name);
+ }
+
+ if (data != null)
+ {
+ data.setCoins(data.getCoins() + coinsPerVote);
+ data.setTotalVotes(data.getTotalVotes() + 1);
+ save(data);
+ FUtil.bcastMsg(ChatColor.GREEN + name + ChatColor.AQUA + " has voted for us on " + ChatColor.GREEN + vote.getServiceName() + ChatColor.AQUA + "!");
+ }
+
+ if (player != null)
+ {
+ player.sendMessage(ChatColor.GREEN + "Thank you for voting for us! Here are " + coinsPerVote + " coins!");
+ }
+ }
+
public Collection getLoadedData()
{
return dataMap.values();
}
- protected File getConfigFile(String name)
+ protected File getConfigFile(UUID uuid)
{
- return new File(getConfigFolder(), name + ".yml");
+ return new File(getConfigFolder(), uuid + ".yml");
}
protected YamlConfig getConfig(ShopData data)
{
- final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUsername().toLowerCase()), false);
+ final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUUID()), false);
config.load();
return config;
}
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java
index 3820a33a..3460fb78 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopData.java
@@ -1,22 +1,17 @@
package me.totalfreedom.totalfreedommod.shop;
import com.google.common.collect.Lists;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
-import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.base.ConfigLoadable;
import net.pravian.aero.base.ConfigSavable;
import net.pravian.aero.base.Validatable;
-import org.apache.commons.lang3.Validate;
-import org.bukkit.ChatColor;
+import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.ItemMeta;
public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
{
@@ -24,30 +19,33 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
@Getter
@Setter
private String username;
- private final List ips = Lists.newArrayList();
+ private String uuid;
@Getter
@Setter
private int coins;
private List items = Lists.newArrayList();
+ @Getter
+ @Setter
+ private int totalVotes;
public ShopData(Player player)
{
- this(player.getName());
+ this(player.getUniqueId());
}
- public ShopData(String username)
+ public ShopData(UUID uuid)
{
- this.username = username;
+ this.uuid = uuid.toString();
}
@Override
public void loadFrom(ConfigurationSection cs)
{
this.username = cs.getString("username", username);
- this.ips.clear();
- this.ips.addAll(cs.getStringList("ips"));
+ this.uuid = cs.getString("uuid", uuid);
this.coins = cs.getInt("coins", coins);
this.items.addAll(cs.getStringList("items"));
+ this.totalVotes = cs.getInt("totalVotes");
}
@Override
@@ -55,25 +53,10 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
{
Validate.isTrue(isValid(), "Could not save shop entry: " + username + ". Entry not valid!");
cs.set("username", username);
- cs.set("ips", ips);
+ cs.set("uuid", uuid);
cs.set("coins", coins);
cs.set("items", items);
- }
-
- public List getIps()
- {
- return Collections.unmodifiableList(ips);
- }
-
- // IP utils
- public boolean addIp(String ip)
- {
- return ips.contains(ip) ? false : ips.add(ip);
- }
-
- public boolean removeIp(String ip)
- {
- return ips.remove(ip);
+ cs.set("totalVotes", totalVotes);
}
public List getItems()
@@ -81,165 +64,38 @@ public class ShopData implements ConfigLoadable, ConfigSavable, Validatable
return Collections.unmodifiableList(items);
}
- public String giveItem(ShopItem item)
+ public void setUUID(UUID id)
{
- String signature = FUtil.generateSignature(item);
- items.add(signature);
- return signature;
+ uuid = id.toString();
}
- public void giveRawItem(String signature)
+ public UUID getUUID()
{
- items.add(signature);
+ return UUID.fromString(uuid);
+ }
+
+ public void giveItem(ShopItem item)
+ {
+ items.add(item.getDataName());
}
public boolean hasItem(ShopItem item)
{
- for (String i : items)
+ if (items.contains(item.getDataName()))
{
- int id;
- try
- {
- id = Integer.valueOf(i.substring(0, i.indexOf("A")));
- }
- catch (NumberFormatException ex)
- {
- continue;
- }
- if (item.ordinal() == id)
- {
- return true;
- }
+ return true;
}
return false;
}
- public ItemStack getItem(ShopItem item)
+ public void removeItem(ShopItem item)
{
- String signature = "";
- for (String i : items)
- {
- int id;
- try
- {
- id = Integer.valueOf(i.substring(0, i.indexOf("A")));
- }
- catch (NumberFormatException ex)
- {
- continue;
- }
- if (item.ordinal() == id)
- {
- signature = i;
- }
- }
- ItemStack stack = new ItemStack(item.getMaterial(), 1);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(item.getColoredName());
- List lore = new ArrayList<>();
- lore.add(ChatColor.DARK_GRAY + signature);
- meta.setLore(lore);
- stack.setItemMeta(meta);
- return stack;
- }
-
- public boolean validate(ItemStack stack, String nameSegment)
- {
- if (!stack.hasItemMeta())
- {
- return false;
- }
-
- if (!stack.getItemMeta().hasDisplayName())
- {
- return false;
- }
-
- if (!stack.getItemMeta().getDisplayName().contains(nameSegment))
- {
- return false;
- }
-
- if (!stack.getItemMeta().hasLore())
- {
- return false;
- }
-
- boolean loreValid = false;
-
- for (String i : items)
- {
- if (stack.getItemMeta().getLore().contains(ChatColor.DARK_GRAY + i))
- {
- loreValid = true;
- }
- }
-
- if (!loreValid)
- {
- return false;
- }
-
- return true;
- }
-
- public boolean validate(ItemStack stack, ShopItem item)
- {
- if (!stack.hasItemMeta())
- {
- return false;
- }
-
- if (!stack.getItemMeta().hasDisplayName())
- {
- return false;
- }
-
- if (!stack.getItemMeta().getDisplayName().contains(item.getName()))
- {
- return false;
- }
-
- if (!stack.getItemMeta().hasLore())
- {
- return false;
- }
-
- boolean loreValid = false;
-
- for (String i : items)
- {
- if (stack.getItemMeta().getLore().contains(ChatColor.DARK_GRAY + i))
- {
- loreValid = true;
- }
- }
-
- if (!loreValid)
- {
- return false;
- }
-
- return true;
- }
-
- public void takeItem(ShopItem item)
- {
- Iterator it = items.iterator();
- while (it.hasNext())
- {
- String i = it.next();
- if (i.startsWith(item.ordinal() + ""))
- {
- it.remove();
- }
- }
+ items.remove(item.getDataName());
}
@Override
public boolean isValid()
{
- return username != null
- && !ips.isEmpty();
+ return username != null;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java
index a2f38cc9..09986512 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java
@@ -1,34 +1,49 @@
package me.totalfreedom.totalfreedommod.shop;
import lombok.Getter;
+import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.Material;
public enum ShopItem
{
- 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);
+ GRAPPLING_HOOK("Grappling Hook", Material.FISHING_ROD, 10, ConfigEntry.SHOP_PRICES_GRAPPLING_HOOK, ChatColor.GREEN, "grapplingHook"),
+ LIGHTNING_ROD("Lightning Rod", Material.BLAZE_ROD, 12, ConfigEntry.SHOP_PRICES_LIGHTNING_ROD, ChatColor.LIGHT_PURPLE, "lightningRod"),
+ FIRE_BALL("Fire Ball", Material.FIRE_CHARGE, 14, ConfigEntry.SHOP_PRICES_FIRE_BALL, ChatColor.RED, "fireBall"),
+ RIDEABLE_PEARL("Rideable Ender Pearl", Material.ENDER_PEARL, 16, ConfigEntry.SHOP_PRICES_RIDEABLE_PEARL, ChatColor.DARK_PURPLE, "rideablePearl");
+
+ /*
+ Shop GUI Layout:
+
+ Dimensions: 9x4 = 36
+ Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, $ = Coins}
+
+ ---------
+ -g-l-f-r-
+ ---------
+ --------$
+ */
@Getter
private final String name;
@Getter
- private final Material material;
+ private final Material icon;
@Getter
- private final int cost;
+ private final int slot;
+ private final ConfigEntry cost;
@Getter
private final ChatColor color;
@Getter
- private final boolean purchaseable;
+ private final String dataName;
- ShopItem(String name, Material material, int cost, ChatColor color, boolean purchaseable)
+ ShopItem(String name, Material icon, int slot, ConfigEntry cost, ChatColor color, String dataName)
{
this.name = name;
- this.material = material;
+ this.icon = icon;
+ this.slot = slot;
this.cost = cost;
this.color = color;
- this.purchaseable = purchaseable;
+ this.dataName = dataName;
}
public String getColoredName()
@@ -36,6 +51,11 @@ public enum ShopItem
return color + name;
}
+ public int getCost()
+ {
+ return cost.getInteger();
+ }
+
public static ShopItem findItem(String string)
{
try
diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
index dc485179..cab4d758 100644
--- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
+++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java
@@ -1,10 +1,13 @@
package me.totalfreedom.totalfreedommod.util;
-import com.comphenix.protocol.PacketType;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.FileFilter;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.reflect.Field;
-import java.security.SecureRandom;
+import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -20,10 +23,11 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.net.ssl.HttpsURLConnection;
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.apache.commons.lang.WordUtils;
@@ -31,8 +35,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
-import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -40,6 +42,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.Material;
+import org.json.simple.JSONArray;
public class FUtil
{
@@ -48,8 +51,7 @@ public class FUtil
//
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
// See https://github.com/TotalFreedom/License - None of the listed names may be removed.
- public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "Catholic_Mario", "Arcaknight", "smartnt");
- public static final List CONTRIBUTORS = Arrays.asList("supernt", "OxLemonxO", "AcidicCyanide", "aggelosQQ");
+ public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "Demonic_Mario", "RobinGall2910", "smartnt");
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
public static final Map CHAT_COLOR_NAMES = new HashMap<>();
public static final List CHAT_COLOR_POOL = Arrays.asList(
@@ -160,6 +162,54 @@ public class FUtil
return names;
}
+ public static UUID nameToUUID(String name)
+ {
+ try
+ {
+ JSONArray json = new JSONArray();
+ json.add(name);
+ String response = postRequestToEndpoint("https://api.mojang.com/profiles/minecraft", json.toString());
+ // Don't care how stupid this looks, couldn't find anything to parse a json string to something readable in java with something not horrendously huge, maybe im just retarded
+ Pattern pattern = Pattern.compile("(?<=\"id\":\")[a-f0-9].{31}");
+ Matcher matcher = pattern.matcher(response);
+ if (matcher.find())
+ {
+ String rawUUID = matcher.group(0).replaceFirst("([a-f0-9]{8})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]+)", "$1-$2-$3-$4-$5");
+ return UUID.fromString(rawUUID);
+ }
+ }
+ catch (Exception e)
+ {
+ FLog.severe("Failed to convert name to UUID:\n" + e.toString());
+ }
+ return null;
+ }
+
+ public static String postRequestToEndpoint(String endpoint, String body) throws IOException
+ {
+ URL url = new URL(endpoint);
+ HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Accept", "application/json");
+ connection.setRequestProperty("Content-Type", "application/json");
+ connection.setDoOutput(true);
+ DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
+ outputStream.writeBytes(body);
+ outputStream.flush();
+ outputStream.close();
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String inputLine;
+ StringBuffer response = new StringBuffer();
+
+ while ((inputLine = in.readLine()) != null)
+ {
+ response.append(inputLine);
+ }
+
+ in.close();
+ return response.toString();
+ }
+
public static void bcastMsg(String message, ChatColor color)
{
FLog.info(message, true);
@@ -553,27 +603,6 @@ public class FUtil
player.getInventory().setItem(player.getInventory().firstEmpty(), stack);
}
- public static void give(Player player, ShopItem item, String... lore)
- {
- 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++)
- {
- char c = FUtil.getRandomCharacter();
- while (c == 'A')
- {
- c = FUtil.getRandomCharacter();
- }
- signature += FUtil.getRandomCharacter();
- }
- return signature;
- }
-
public static Player getRandomPlayer()
{
List players = new ArrayList<>(Bukkit.getOnlinePlayers());
@@ -612,4 +641,10 @@ public class FUtil
{
return tz < -12 || tz > 12;
}
+
+ private static class MojangResponse
+ {
+ String id;
+ String name;
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 795ea10e..fbe229d5 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -32,7 +32,7 @@ server:
# All players who show up as owner
owners:
- - Catholic_Mario
+ - Demonic_Mario
# All players who show up as executive
executives: []
@@ -88,9 +88,22 @@ discord:
shop:
# Enable the shop
enabled: true
+
+ # Shop title
+ title: '&e&lTotalFreedom Shop'
# Shop prefix
- prefix: '&7&l[&8&lTF Shop&7&l]'
+ prefix: '&8[&eTF Shop&8]'
+
+ # How many coins to voters get per vote?
+ coins_per_vote: 20
+
+ # Item prices
+ prices:
+ grappling_hook: 100
+ lightning_rod: 1000
+ fire_ball: 500
+ rideable_pearl: 700
# Admin list
adminlist: