mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
my end of the bargain
This commit is contained in:
parent
3b666f1fde
commit
0367d9fd3a
2
pom.xml
2
pom.xml
@ -156,7 +156,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -30,6 +30,7 @@ public class LoginProcess extends FreedomService
|
||||
private static boolean lockdownEnabled = false;
|
||||
public List<String> TELEPORT_ON_JOIN = new ArrayList<>();
|
||||
public List<String> CLEAR_ON_JOIN = new ArrayList<>();
|
||||
public List<String> CLOWNFISH_TOGGLE = new ArrayList<>();
|
||||
|
||||
public static boolean isLockdownEnabled()
|
||||
{
|
||||
|
@ -1,61 +1,61 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class EditBlocker extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer());
|
||||
if (!fPlayer.isEditBlocked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdminSync(event.getPlayer()))
|
||||
{
|
||||
fPlayer.setEditBlocked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "Your ability to place blocks has been disabled!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer());
|
||||
if (!fPlayer.isEditBlocked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdminSync(event.getPlayer()))
|
||||
{
|
||||
fPlayer.setEditBlocked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "Your ability to destroy blocks has been disabled!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class EditBlocker extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer());
|
||||
if (!fPlayer.isEditBlocked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdminSync(event.getPlayer()))
|
||||
{
|
||||
fPlayer.setEditBlocked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "Your ability to place blocks has been disabled!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer());
|
||||
if (!fPlayer.isEditBlocked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdminSync(event.getPlayer()))
|
||||
{
|
||||
fPlayer.setEditBlocked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "Your ability to destroy blocks has been disabled!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import me.totalfreedom.totalfreedommod.LoginProcess;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Obtain a clown fish", usage = "/<command>")
|
||||
@ -15,14 +16,14 @@ public class Command_clownfish extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH))
|
||||
if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH) && (!plugin.lp.CLOWNFISH_TOGGLE.contains(playerSender.getName())))
|
||||
{
|
||||
playerSender.getInventory().addItem(plugin.sh.getClownFish());
|
||||
msg("You have been given a Clown Fish", ChatColor.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("You do not own a Clown Fish! Purchase one from the shop.", ChatColor.RED);
|
||||
msg("You do not own a Clown Fish or an admin has toggled your ability to use it. Purchase one from the shop.", ChatColor.RED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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.BOTH)
|
||||
@CommandParameters(description = "Shows the amount of coins you have or another player has", usage = "/<command> [playername]")
|
||||
public class Command_coins extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
Player p;
|
||||
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (getPlayer(args[0]) != null)
|
||||
{
|
||||
p = getPlayer(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
msg(prefix + ChatColor.RED + "You are not a player, use /coins <playername>");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = playerSender;
|
||||
}
|
||||
}
|
||||
PlayerData playerData = plugin.pl.getData(p);
|
||||
msg(prefix + ChatColor.GREEN + (args.length > 0 ? p.getName() + " has " : "You have ") + ChatColor.RED + playerData.getCoins() + ChatColor.GREEN + " coins.");
|
||||
return true;
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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.BOTH)
|
||||
@CommandParameters(description = "Shows the amount of coins you have or another player has", usage = "/<command> [playername]")
|
||||
public class Command_coins extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
Player p;
|
||||
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (getPlayer(args[0]) != null)
|
||||
{
|
||||
p = getPlayer(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
msg(prefix + ChatColor.RED + "You are not a player, use /coins <playername>");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = playerSender;
|
||||
}
|
||||
}
|
||||
PlayerData playerData = plugin.pl.getData(p);
|
||||
msg(prefix + ChatColor.GREEN + (args.length > 0 ? p.getName() + " has " : "You have ") + ChatColor.RED + playerData.getCoins() + ChatColor.GREEN + " coins.");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,69 +1,69 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Surprise someone.", usage = "/<command> <player>")
|
||||
public class Command_explode extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
player.setFlying(false);
|
||||
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 50, 0)));
|
||||
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
FUtil.createExplosionOnDelay(player.getLocation(), 2L, i * 10);
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
player.getWorld().strikeLightning(player.getLocation());
|
||||
player.getWorld().createExplosion(player.getLocation(), 4L);
|
||||
}
|
||||
player.setHealth(0.0);
|
||||
msg("Exploded " + player.getName());
|
||||
}
|
||||
}.runTaskLater(plugin, 40);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1 && plugin.al.isAdmin(sender))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Surprise someone.", usage = "/<command> <player>")
|
||||
public class Command_explode extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
player.setFlying(false);
|
||||
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 50, 0)));
|
||||
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
FUtil.createExplosionOnDelay(player.getLocation(), 2L, i * 10);
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
player.getWorld().strikeLightning(player.getLocation());
|
||||
player.getWorld().createExplosion(player.getLocation(), 4L);
|
||||
}
|
||||
player.setHealth(0.0);
|
||||
msg("Exploded " + player.getName());
|
||||
}
|
||||
}.runTaskLater(plugin, 40);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1 && plugin.al.isAdmin(sender))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -21,8 +21,13 @@ public class Command_fuckoff extends FreedomCommand
|
||||
|
||||
FPlayer player = plugin.pl.getPlayer(playerSender);
|
||||
|
||||
if (args[0].equalsIgnoreCase("off"))
|
||||
if (!args[0].equals("on"))
|
||||
{
|
||||
player.disableFuckoff();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
double radius = 25.0;
|
||||
if (args.length >= 2)
|
||||
{
|
||||
@ -34,14 +39,12 @@ public class Command_fuckoff extends FreedomCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
player.setFuckoff(radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.disableFuckoff();
|
||||
}
|
||||
|
||||
msg("Fuckoff " + (player.isFuckOff() ? ("enabled. Radius: " + player.getFuckoffRadius() + ".") : "disabled."));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,219 +1,219 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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 = "/<command> <coins: <add | set | remove> <amount> <player | all> | items: <give | take> <item> <player>", 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)
|
||||
{
|
||||
|
||||
if (!FUtil.isExecutive(sender.getName()))
|
||||
{
|
||||
return noPerms();
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (args[0].equals("coins"))
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (args[1])
|
||||
{
|
||||
|
||||
case "add":
|
||||
try
|
||||
{
|
||||
int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
|
||||
if (!args[3].equals("all"))
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(playerData.getCoins() + amount);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully added " + amount + " coins to " + args[3] + ". Their new balance is " + playerData.getCoins(), ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
playerData.setCoins(playerData.getCoins() + amount);
|
||||
plugin.pl.save(playerData);
|
||||
player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
msg("Successfully added " + amount + " coins to all online players.", ChatColor.GREEN);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
msg("Invalid number: " + args[2], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
case "remove":
|
||||
try
|
||||
{
|
||||
int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
|
||||
if (!args[3].equals("all"))
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(playerData.getCoins() - amount);
|
||||
if (playerData.getCoins() < 0)
|
||||
{
|
||||
playerData.setCoins(0);
|
||||
}
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully removed " + amount + " coins from " + args[3] + ". Their new balance is " + playerData.getCoins(), ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
playerData.setCoins(playerData.getCoins() - amount);
|
||||
if (playerData.getCoins() < 0)
|
||||
{
|
||||
playerData.setCoins(0);
|
||||
}
|
||||
plugin.pl.save(playerData);
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + playerData.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])));
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(amount);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully set " + args[3] + "'s coins to " + amount, ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
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(args[2] + " is not a valid item.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.giveItem(item);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully gave the " + item.getName() + " to " + args[3], ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.removeItem(item);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully took the " + item.getName() + " from " + args[3], ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took the " + item.getName() + " from you");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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.ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage the shop", usage = "/<command> <coins: <add | set | remove> <amount> <player | all> | items: <give | take> <item> <player>", 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)
|
||||
{
|
||||
|
||||
if (!FUtil.isExecutive(sender.getName()))
|
||||
{
|
||||
return noPerms();
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (args[0].equals("coins"))
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (args[1])
|
||||
{
|
||||
|
||||
case "add":
|
||||
try
|
||||
{
|
||||
int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
|
||||
if (!args[3].equals("all"))
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(playerData.getCoins() + amount);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully added " + amount + " coins to " + args[3] + ". Their new balance is " + playerData.getCoins(), ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
playerData.setCoins(playerData.getCoins() + amount);
|
||||
plugin.pl.save(playerData);
|
||||
player.sendMessage(ChatColor.GREEN + sender.getName() + " gave you " + amount + " coins. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
msg("Successfully added " + amount + " coins to all online players.", ChatColor.GREEN);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
msg("Invalid number: " + args[2], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
case "remove":
|
||||
try
|
||||
{
|
||||
int amount = Math.max(0, Math.min(1000000, Integer.parseInt(args[2])));
|
||||
if (!args[3].equals("all"))
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(playerData.getCoins() - amount);
|
||||
if (playerData.getCoins() < 0)
|
||||
{
|
||||
playerData.setCoins(0);
|
||||
}
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully removed " + amount + " coins from " + args[3] + ". Their new balance is " + playerData.getCoins(), ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + playerData.getCoins());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
playerData.setCoins(playerData.getCoins() - amount);
|
||||
if (playerData.getCoins() < 0)
|
||||
{
|
||||
playerData.setCoins(0);
|
||||
}
|
||||
plugin.pl.save(playerData);
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took " + amount + " coins from you. Your new balance is " + playerData.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])));
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.setCoins(amount);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully set " + args[3] + "'s coins to " + amount, ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
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(args[2] + " is not a valid item.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.giveItem(item);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully gave the " + item.getName() + " to " + args[3], ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(args[3]);
|
||||
if (playerData == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
playerData.removeItem(item);
|
||||
plugin.pl.save(playerData);
|
||||
msg("Successfully took the " + item.getName() + " from " + args[3], ChatColor.GREEN);
|
||||
Player player = getPlayer(args[3]);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + sender.getName() + " took the " + item.getName() + " from you");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.History;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Check the name history of a specified player.", usage = "/<command> <username>", aliases = "nh")
|
||||
public class Command_namehistory extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
History.reportHistory(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.History;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Check the name history of a specified player.", usage = "/<command> <username>", aliases = "nh")
|
||||
public class Command_namehistory extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
History.reportHistory(sender, args[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,62 +1,62 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Sends a guardian particle effect with an enderman scream to the specified player.", usage = "/<command> <player>")
|
||||
public class Command_scare extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!FUtil.isPaper())
|
||||
{
|
||||
msg("This command won't work without Paper!", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
msg("Scared " + player.getName());
|
||||
player.sendMessage(ChatColor.RED + "ZING");
|
||||
|
||||
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1 && plugin.al.isAdmin(sender))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Sends a guardian particle effect with an enderman scream to the specified player.", usage = "/<command> <player>")
|
||||
public class Command_scare extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!FUtil.isPaper())
|
||||
{
|
||||
msg("This command won't work without Paper!", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
msg("Scared " + player.getName());
|
||||
player.sendMessage(ChatColor.RED + "ZING");
|
||||
|
||||
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1 && plugin.al.isAdmin(sender))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
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.BOTH)
|
||||
@CommandParameters(description = "Check the status of the server, including opped players, admins, etc.", usage = "/<command>", aliases = "ss")
|
||||
public class Command_serverstats extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
msg("-==" + ConfigEntry.SERVER_NAME.getString() + " server stats==-", ChatColor.GOLD);
|
||||
msg("Total opped players: " + server.getOperators().size(), ChatColor.RED);
|
||||
msg("Total admins: " + plugin.al.getAllAdmins().size() + " (" + plugin.al.getActiveAdmins().size() + " active)", ChatColor.BLUE);
|
||||
int bans = plugin.im.getIndefBans().size();
|
||||
int nameBans = plugin.im.getNameBanCount();
|
||||
int uuidBans = plugin.im.getUuidBanCount();
|
||||
int ipBans = plugin.im.getIpBanCount();
|
||||
msg("Total indefinite ban entries: " + bans + " (" + nameBans + " name bans, " + uuidBans + " UUID bans, and " + ipBans + " IP bans)", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
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.BOTH)
|
||||
@CommandParameters(description = "Check the status of the server, including opped players, admins, etc.", usage = "/<command>", aliases = "ss")
|
||||
public class Command_serverstats extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
msg("-==" + ConfigEntry.SERVER_NAME.getString() + " server stats==-", ChatColor.GOLD);
|
||||
msg("Total opped players: " + server.getOperators().size(), ChatColor.RED);
|
||||
msg("Total admins: " + plugin.al.getAllAdmins().size() + " (" + plugin.al.getActiveAdmins().size() + " active)", ChatColor.BLUE);
|
||||
int bans = plugin.im.getIndefBans().size();
|
||||
int nameBans = plugin.im.getNameBanCount();
|
||||
int uuidBans = plugin.im.getUuidBanCount();
|
||||
int ipBans = plugin.im.getIpBanCount();
|
||||
msg("Total indefinite ban entries: " + bans + " (" + nameBans + " name bans, " + uuidBans + " UUID bans, and " + ipBans + " IP bans)", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
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;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Toggle whether or not a player has the ability to use clownfish", usage = "/<command> <player>", aliases = "togglecf")
|
||||
public class Command_toggleclownfish extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean enabled = plugin.lp.CLOWNFISH_TOGGLE.contains(args[0]);
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
plugin.lp.CLOWNFISH_TOGGLE.remove(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.lp.CLOWNFISH_TOGGLE.add(args[0]);
|
||||
}
|
||||
|
||||
msg(args[0] + " will " + (enabled ? "now" : "no longer") + " have the ability to use clownfish.");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,34 +1,34 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Information on how to vote", usage = "/<command>")
|
||||
public class Command_vote extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
List<String> voteInfo = ConfigEntry.VOTING_INFO.getStringList();
|
||||
|
||||
if (voteInfo.isEmpty())
|
||||
{
|
||||
msg("The voting information section of the config.yml file has not been configured.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg(FUtil.colorize(StringUtils.join(voteInfo, "\n")));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
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.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Information on how to vote", usage = "/<command>")
|
||||
public class Command_vote extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
List<String> voteInfo = ConfigEntry.VOTING_INFO.getStringList();
|
||||
|
||||
if (voteInfo.isEmpty())
|
||||
{
|
||||
msg("The voting information section of the config.yml file has not been configured.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg(FUtil.colorize(StringUtils.join(voteInfo, "\n")));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public enum ConfigEntry
|
||||
SERVER_LOGIN_SUBTITLE(String.class, "server.login_title.subtitle"),
|
||||
SERVER_OWNERS(List.class, "server.owners"),
|
||||
SERVER_EXECUTIVES(List.class, "server.executives"),
|
||||
SERVER_ASSTISTANT_EXECUTIVES(List.class, "server.assistant_executives"),
|
||||
SERVER_MASTER_BUILDER_MANAGEMENT(List.class, "server.master_builder_management"),
|
||||
SERVER_BAN_URL(String.class, "server.ban_url"),
|
||||
SERVER_INDEFBAN_URL(String.class, "server.indefban_url"),
|
||||
|
@ -402,6 +402,11 @@ public class Discord extends FreedomService
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
message = StringUtils.remove(message, "§");
|
||||
}
|
||||
|
||||
if (enabled && !chat_channel_id.isEmpty())
|
||||
{
|
||||
@ -422,6 +427,11 @@ public class Discord extends FreedomService
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
message = StringUtils.remove(message, "§");
|
||||
}
|
||||
|
||||
if (enabled && !chat_channel_id.isEmpty())
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.LoginProcess;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@ -247,6 +248,12 @@ public class ItemFun extends FreedomService
|
||||
{
|
||||
final int RADIUS_HIT = 5;
|
||||
final int STRENGTH = 4;
|
||||
|
||||
if (plugin.lp.CLOWNFISH_TOGGLE.contains(player.getName()))
|
||||
{
|
||||
player.sendMessage(ChatColor.GRAY + "An admin has disabled your ability to use clownfish.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!plugin.sh.isRealItem(plugin.pl.getData(player), ShopItem.CLOWN_FISH, player.getInventory(), plugin.sh.getClownFish()))
|
||||
{
|
||||
|
@ -8,8 +8,9 @@ public enum Title implements Displayable
|
||||
MASTER_BUILDER("a", "Master Builder", ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, "MB", true, true),
|
||||
VERIFIED_ADMIN("a", "Verified Admin", ChatColor.LIGHT_PURPLE, org.bukkit.ChatColor.LIGHT_PURPLE, "VA", false, true),
|
||||
EXECUTIVE("an", "Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Exec", true, true),
|
||||
ASSTEXEC("an", "Assistant Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Asst Exec", true, true),
|
||||
DEVELOPER("a", "Developer", ChatColor.DARK_PURPLE, org.bukkit.ChatColor.DARK_PURPLE, "Dev", true, true),
|
||||
OWNER("the", "Owner", ChatColor.of("#ff0000"), org.bukkit.ChatColor.DARK_RED, "Owner", true, true);
|
||||
OWNER("the", "Owner", ChatColor.DARK_RED, org.bukkit.ChatColor.DARK_RED, "Owner", true, true);
|
||||
|
||||
|
||||
private final String article;
|
||||
|
@ -1,425 +1,425 @@
|
||||
package me.totalfreedom.totalfreedommod.shop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Shop extends FreedomService
|
||||
{
|
||||
public final int coinsPerReactionWin = ConfigEntry.SHOP_REACTIONS_COINS_PER_WIN.getInteger();
|
||||
public final String prefix = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "Reaction" + ChatColor.DARK_GRAY + "] ";
|
||||
private final String LOGIN_MESSAGE_GUI_TITLE = ChatColor.DARK_GREEN + ChatColor.BOLD.toString() + "Login Messages";
|
||||
public String reactionString = "";
|
||||
public Date reactionStartTime;
|
||||
public BukkitTask countdownTask;
|
||||
private BukkitTask reactions;
|
||||
private BossBar countdownBar = null;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
startReactionTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public void startReactionTimer()
|
||||
{
|
||||
long interval = ConfigEntry.SHOP_REACTIONS_INTERVAL.getInteger() * 20L;
|
||||
|
||||
reactions = new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
startReaction();
|
||||
}
|
||||
}.runTaskLater(plugin, interval);
|
||||
}
|
||||
|
||||
public void forceStartReaction()
|
||||
{
|
||||
reactions.cancel();
|
||||
startReaction();
|
||||
}
|
||||
|
||||
public void startReaction()
|
||||
{
|
||||
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
|
||||
{
|
||||
FLog.debug("The shop is not enabled, therefore a reaction did not start.");
|
||||
return;
|
||||
}
|
||||
|
||||
reactionString = FUtil.randomAlphanumericString(ConfigEntry.SHOP_REACTIONS_STRING_LENGTH.getInteger());
|
||||
|
||||
FUtil.bcastMsg(prefix + ChatColor.AQUA + "Enter the code above to win " + ChatColor.GOLD + coinsPerReactionWin + ChatColor.AQUA + " coins!", false);
|
||||
|
||||
reactionStartTime = new Date();
|
||||
|
||||
countdownBar = server.createBossBar(reactionString, BarColor.GREEN, BarStyle.SOLID);
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
countdownBar.addPlayer(player);
|
||||
}
|
||||
countdownBar.setVisible(true);
|
||||
countdownTask = new BukkitRunnable()
|
||||
{
|
||||
double seconds = 30;
|
||||
final double max = seconds;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if ((seconds -= 1) == 0)
|
||||
{
|
||||
endReaction(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
countdownBar.setProgress(seconds / max);
|
||||
if (!countdownBar.getColor().equals(BarColor.YELLOW) && seconds / max <= 0.25)
|
||||
{
|
||||
countdownBar.setColor(BarColor.YELLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 20);
|
||||
}
|
||||
|
||||
public void endReaction(String winner)
|
||||
{
|
||||
countdownTask.cancel();
|
||||
countdownBar.removeAll();
|
||||
countdownBar = null;
|
||||
reactionString = "";
|
||||
|
||||
if (winner != null)
|
||||
{
|
||||
Date currentTime = new Date();
|
||||
long seconds = (currentTime.getTime() - reactionStartTime.getTime()) / 1000;
|
||||
FUtil.bcastMsg(prefix + ChatColor.GREEN + winner + ChatColor.AQUA + " won in " + seconds + " seconds!", false);
|
||||
startReactionTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(prefix + ChatColor.RED + "No one reacted fast enough", false);
|
||||
startReactionTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
reactions.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public String getShopPrefix()
|
||||
{
|
||||
return FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString());
|
||||
}
|
||||
|
||||
public String getShopTitle()
|
||||
{
|
||||
return FUtil.colorize(ConfigEntry.SHOP_TITLE.getString());
|
||||
}
|
||||
|
||||
public Inventory generateShopGUI(PlayerData playerData)
|
||||
{
|
||||
Inventory gui = server.createInventory(null, 36, getShopTitle());
|
||||
for (int slot = 0; slot < 36; slot++)
|
||||
{
|
||||
ItemStack blank = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
|
||||
ItemMeta meta = blank.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(" ");
|
||||
blank.setItemMeta(meta);
|
||||
gui.setItem(slot, blank);
|
||||
}
|
||||
for (ShopItem shopItem : ShopItem.values())
|
||||
{
|
||||
ItemStack item = shopGUIItem(shopItem, playerData);
|
||||
gui.setItem(shopItem.getSlot(), item);
|
||||
}
|
||||
// Coins
|
||||
ItemStack coins = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta meta = coins.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(FUtil.colorize("&c&lYou have &e&l" + playerData.getCoins() + "&c&l coins"));
|
||||
coins.setItemMeta(meta);
|
||||
gui.setItem(35, coins);
|
||||
return gui;
|
||||
}
|
||||
|
||||
public Inventory generateLoginMessageGUI(Player player)
|
||||
{
|
||||
Inventory gui = server.createInventory(null, 36, LOGIN_MESSAGE_GUI_TITLE);
|
||||
int slot = 0;
|
||||
for (String loginMessage : ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList())
|
||||
{
|
||||
ItemStack icon = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta = icon.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(FUtil.colorize(plugin.rm.craftLoginMessage(player, loginMessage)));
|
||||
icon.setItemMeta(meta);
|
||||
gui.setItem(slot, icon);
|
||||
slot++;
|
||||
}
|
||||
ItemStack clear = new ItemStack(Material.BARRIER);
|
||||
ItemMeta meta = clear.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(ChatColor.RED + "Clear login message");
|
||||
clear.setItemMeta(meta);
|
||||
gui.setItem(35, clear);
|
||||
return gui;
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem)
|
||||
{
|
||||
return isRealItem(data, shopItem, inventory.getItemInMainHand(), realItem) || isRealItem(data, shopItem, inventory.getItemInOffHand(), realItem);
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem)
|
||||
{
|
||||
if (!data.hasItem(shopItem) || !givenItem.getType().equals(realItem.getType()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemMeta givenMeta = givenItem.getItemMeta();
|
||||
ItemMeta realMeta = realItem.getItemMeta();
|
||||
|
||||
assert givenMeta != null;
|
||||
assert realMeta != null;
|
||||
return givenMeta.getDisplayName().equals(realMeta.getDisplayName()) && Objects.equals(givenMeta.getLore(), realMeta.getLore());
|
||||
}
|
||||
|
||||
public ItemStack getLightningRod()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.BLAZE_ROD);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
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();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.YELLOW + "Grappling Hook");
|
||||
itemMeta.setLore(Collections.singletonList(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();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.RED + "Fire Ball");
|
||||
itemMeta.setLore(Collections.singletonList(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();
|
||||
assert itemMeta != null;
|
||||
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 ItemStack getStackingPotato()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.POTATO);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.YELLOW + "Stacking Potato");
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GREEN + "Left click to ride a mob, right click to put a mob on your head."));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public ItemStack getClownFish()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.TROPICAL_FISH);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.GOLD + "Clown Fish");
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.AQUA + ":clown:"));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public boolean canAfford(int price, int coins)
|
||||
{
|
||||
return coins >= price;
|
||||
}
|
||||
|
||||
public int amountNeeded(int price, int coins)
|
||||
{
|
||||
return price - coins;
|
||||
}
|
||||
|
||||
public ItemStack shopGUIItem(ShopItem item, PlayerData data)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(item.getIcon());
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(item.getColoredName());
|
||||
int price = item.getCost();
|
||||
int coins = data.getCoins();
|
||||
boolean canAfford = canAfford(price, coins);
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (!data.hasItem(item))
|
||||
{
|
||||
lore.add(ChatColor.GOLD + "Price: " + (canAfford ? ChatColor.DARK_GREEN : ChatColor.RED) + price);
|
||||
if (!canAfford)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onShopGUIClick(InventoryClickEvent event)
|
||||
{
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
if (inventory.getSize() != 36 || !event.getView().getTitle().equals(getShopTitle()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
ShopItem shopItem = getShopItem(event.getSlot());
|
||||
if (shopItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
int price = shopItem.getCost();
|
||||
int coins = playerData.getCoins();
|
||||
|
||||
if (playerData.hasItem(shopItem) || !canAfford(price, coins))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
playerData.giveItem(shopItem);
|
||||
playerData.setCoins(coins - price);
|
||||
plugin.pl.save(playerData);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
player.sendMessage(getShopPrefix() + " " + ChatColor.GREEN + "Successfully purchased the \"" + shopItem.getColoredName() + ChatColor.GREEN + "\" for " + ChatColor.GOLD + price + ChatColor.GREEN + "!");
|
||||
|
||||
if (shopItem.getCommand() != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.GREEN + "Run " + shopItem.getCommand() + " to get one!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLoginMessageGUIClick(InventoryClickEvent event)
|
||||
{
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
if (inventory.getSize() != 36 || !event.getView().getTitle().equals(LOGIN_MESSAGE_GUI_TITLE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
int slot = event.getSlot();
|
||||
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
PlayerData data = plugin.pl.getData(player);
|
||||
|
||||
if (slot == 35)
|
||||
{
|
||||
data.setLoginMessage(null);
|
||||
plugin.pl.save(data);
|
||||
player.sendMessage(ChatColor.GREEN + "Removed your login message");
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList().get(slot);
|
||||
data.setLoginMessage(message);
|
||||
plugin.pl.save(data);
|
||||
player.sendMessage(ChatColor.GREEN + "Your login message is now the following:\n" + plugin.rm.craftLoginMessage(player, message));
|
||||
}
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
public ShopItem getShopItem(int slot)
|
||||
{
|
||||
for (ShopItem shopItem : ShopItem.values())
|
||||
{
|
||||
if (shopItem.getSlot() == slot)
|
||||
{
|
||||
return shopItem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.shop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Shop extends FreedomService
|
||||
{
|
||||
public final int coinsPerReactionWin = ConfigEntry.SHOP_REACTIONS_COINS_PER_WIN.getInteger();
|
||||
public final String prefix = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "Reaction" + ChatColor.DARK_GRAY + "] ";
|
||||
private final String LOGIN_MESSAGE_GUI_TITLE = ChatColor.DARK_GREEN + ChatColor.BOLD.toString() + "Login Messages";
|
||||
public String reactionString = "";
|
||||
public Date reactionStartTime;
|
||||
public BukkitTask countdownTask;
|
||||
private BukkitTask reactions;
|
||||
private BossBar countdownBar = null;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
startReactionTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public void startReactionTimer()
|
||||
{
|
||||
long interval = ConfigEntry.SHOP_REACTIONS_INTERVAL.getInteger() * 20L;
|
||||
|
||||
reactions = new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
startReaction();
|
||||
}
|
||||
}.runTaskLater(plugin, interval);
|
||||
}
|
||||
|
||||
public void forceStartReaction()
|
||||
{
|
||||
reactions.cancel();
|
||||
startReaction();
|
||||
}
|
||||
|
||||
public void startReaction()
|
||||
{
|
||||
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
|
||||
{
|
||||
FLog.debug("The shop is not enabled, therefore a reaction did not start.");
|
||||
return;
|
||||
}
|
||||
|
||||
reactionString = FUtil.randomAlphanumericString(ConfigEntry.SHOP_REACTIONS_STRING_LENGTH.getInteger());
|
||||
|
||||
FUtil.bcastMsg(prefix + ChatColor.AQUA + "Enter the code above to win " + ChatColor.GOLD + coinsPerReactionWin + ChatColor.AQUA + " coins!", false);
|
||||
|
||||
reactionStartTime = new Date();
|
||||
|
||||
countdownBar = server.createBossBar(reactionString, BarColor.GREEN, BarStyle.SOLID);
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
countdownBar.addPlayer(player);
|
||||
}
|
||||
countdownBar.setVisible(true);
|
||||
countdownTask = new BukkitRunnable()
|
||||
{
|
||||
double seconds = 30;
|
||||
final double max = seconds;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if ((seconds -= 1) == 0)
|
||||
{
|
||||
endReaction(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
countdownBar.setProgress(seconds / max);
|
||||
if (!countdownBar.getColor().equals(BarColor.YELLOW) && seconds / max <= 0.25)
|
||||
{
|
||||
countdownBar.setColor(BarColor.YELLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 20);
|
||||
}
|
||||
|
||||
public void endReaction(String winner)
|
||||
{
|
||||
countdownTask.cancel();
|
||||
countdownBar.removeAll();
|
||||
countdownBar = null;
|
||||
reactionString = "";
|
||||
|
||||
if (winner != null)
|
||||
{
|
||||
Date currentTime = new Date();
|
||||
long seconds = (currentTime.getTime() - reactionStartTime.getTime()) / 1000;
|
||||
FUtil.bcastMsg(prefix + ChatColor.GREEN + winner + ChatColor.AQUA + " won in " + seconds + " seconds!", false);
|
||||
startReactionTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(prefix + ChatColor.RED + "No one reacted fast enough", false);
|
||||
startReactionTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
reactions.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public String getShopPrefix()
|
||||
{
|
||||
return FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString());
|
||||
}
|
||||
|
||||
public String getShopTitle()
|
||||
{
|
||||
return FUtil.colorize(ConfigEntry.SHOP_TITLE.getString());
|
||||
}
|
||||
|
||||
public Inventory generateShopGUI(PlayerData playerData)
|
||||
{
|
||||
Inventory gui = server.createInventory(null, 36, getShopTitle());
|
||||
for (int slot = 0; slot < 36; slot++)
|
||||
{
|
||||
ItemStack blank = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
|
||||
ItemMeta meta = blank.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(" ");
|
||||
blank.setItemMeta(meta);
|
||||
gui.setItem(slot, blank);
|
||||
}
|
||||
for (ShopItem shopItem : ShopItem.values())
|
||||
{
|
||||
ItemStack item = shopGUIItem(shopItem, playerData);
|
||||
gui.setItem(shopItem.getSlot(), item);
|
||||
}
|
||||
// Coins
|
||||
ItemStack coins = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta meta = coins.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(FUtil.colorize("&c&lYou have &e&l" + playerData.getCoins() + "&c&l coins"));
|
||||
coins.setItemMeta(meta);
|
||||
gui.setItem(35, coins);
|
||||
return gui;
|
||||
}
|
||||
|
||||
public Inventory generateLoginMessageGUI(Player player)
|
||||
{
|
||||
Inventory gui = server.createInventory(null, 36, LOGIN_MESSAGE_GUI_TITLE);
|
||||
int slot = 0;
|
||||
for (String loginMessage : ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList())
|
||||
{
|
||||
ItemStack icon = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta = icon.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(FUtil.colorize(plugin.rm.craftLoginMessage(player, loginMessage)));
|
||||
icon.setItemMeta(meta);
|
||||
gui.setItem(slot, icon);
|
||||
slot++;
|
||||
}
|
||||
ItemStack clear = new ItemStack(Material.BARRIER);
|
||||
ItemMeta meta = clear.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(ChatColor.RED + "Clear login message");
|
||||
clear.setItemMeta(meta);
|
||||
gui.setItem(35, clear);
|
||||
return gui;
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem)
|
||||
{
|
||||
return isRealItem(data, shopItem, inventory.getItemInMainHand(), realItem) || isRealItem(data, shopItem, inventory.getItemInOffHand(), realItem);
|
||||
}
|
||||
|
||||
public boolean isRealItem(PlayerData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem)
|
||||
{
|
||||
if (!data.hasItem(shopItem) || !givenItem.getType().equals(realItem.getType()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemMeta givenMeta = givenItem.getItemMeta();
|
||||
ItemMeta realMeta = realItem.getItemMeta();
|
||||
|
||||
assert givenMeta != null;
|
||||
assert realMeta != null;
|
||||
return givenMeta.getDisplayName().equals(realMeta.getDisplayName()) && Objects.equals(givenMeta.getLore(), realMeta.getLore());
|
||||
}
|
||||
|
||||
public ItemStack getLightningRod()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.BLAZE_ROD);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
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();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.YELLOW + "Grappling Hook");
|
||||
itemMeta.setLore(Collections.singletonList(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();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.RED + "Fire Ball");
|
||||
itemMeta.setLore(Collections.singletonList(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();
|
||||
assert itemMeta != null;
|
||||
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 ItemStack getStackingPotato()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.POTATO);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.YELLOW + "Stacking Potato");
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GREEN + "Left click to ride a mob, right click to put a mob on your head."));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public ItemStack getClownFish()
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(Material.TROPICAL_FISH);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(ChatColor.GOLD + "Clown Fish");
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.AQUA + ":clown:"));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public boolean canAfford(int price, int coins)
|
||||
{
|
||||
return coins >= price;
|
||||
}
|
||||
|
||||
public int amountNeeded(int price, int coins)
|
||||
{
|
||||
return price - coins;
|
||||
}
|
||||
|
||||
public ItemStack shopGUIItem(ShopItem item, PlayerData data)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(item.getIcon());
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setDisplayName(item.getColoredName());
|
||||
int price = item.getCost();
|
||||
int coins = data.getCoins();
|
||||
boolean canAfford = canAfford(price, coins);
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (!data.hasItem(item))
|
||||
{
|
||||
lore.add(ChatColor.GOLD + "Price: " + (canAfford ? ChatColor.DARK_GREEN : ChatColor.RED) + price);
|
||||
if (!canAfford)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onShopGUIClick(InventoryClickEvent event)
|
||||
{
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
if (inventory.getSize() != 36 || !event.getView().getTitle().equals(getShopTitle()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
ShopItem shopItem = getShopItem(event.getSlot());
|
||||
if (shopItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
int price = shopItem.getCost();
|
||||
int coins = playerData.getCoins();
|
||||
|
||||
if (playerData.hasItem(shopItem) || !canAfford(price, coins))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
playerData.giveItem(shopItem);
|
||||
playerData.setCoins(coins - price);
|
||||
plugin.pl.save(playerData);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
player.sendMessage(getShopPrefix() + " " + ChatColor.GREEN + "Successfully purchased the \"" + shopItem.getColoredName() + ChatColor.GREEN + "\" for " + ChatColor.GOLD + price + ChatColor.GREEN + "!");
|
||||
|
||||
if (shopItem.getCommand() != null)
|
||||
{
|
||||
player.sendMessage(ChatColor.GREEN + "Run " + shopItem.getCommand() + " to get one!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLoginMessageGUIClick(InventoryClickEvent event)
|
||||
{
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
if (inventory.getSize() != 36 || !event.getView().getTitle().equals(LOGIN_MESSAGE_GUI_TITLE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
int slot = event.getSlot();
|
||||
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
PlayerData data = plugin.pl.getData(player);
|
||||
|
||||
if (slot == 35)
|
||||
{
|
||||
data.setLoginMessage(null);
|
||||
plugin.pl.save(data);
|
||||
player.sendMessage(ChatColor.GREEN + "Removed your login message");
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList().get(slot);
|
||||
data.setLoginMessage(message);
|
||||
plugin.pl.save(data);
|
||||
player.sendMessage(ChatColor.GREEN + "Your login message is now the following:\n" + plugin.rm.craftLoginMessage(player, message));
|
||||
}
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
public ShopItem getShopItem(int slot)
|
||||
{
|
||||
for (ShopItem shopItem : ShopItem.values())
|
||||
{
|
||||
if (shopItem.getSlot() == slot)
|
||||
{
|
||||
return shopItem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -136,7 +136,7 @@ public class FUtil
|
||||
|
||||
public static boolean isExecutive(String name)
|
||||
{
|
||||
return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name);
|
||||
return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name) || ConfigEntry.SERVER_ASSTISTANT_EXECUTIVES.getStringList().contains(name);
|
||||
}
|
||||
|
||||
public static boolean isDeveloper(Player player)
|
||||
|
@ -1,114 +1,114 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class History
|
||||
{
|
||||
|
||||
public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static void reportHistory(final CommandSender sender, final String username)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
UUID uuid = UUIDFetcher.fetch(username);
|
||||
if (uuid != null)
|
||||
{
|
||||
Gson gson = new GsonBuilder().create();
|
||||
String compactUuid = uuid.toString().replace("-", "");
|
||||
try
|
||||
{
|
||||
//UUIDs or playernames actually work with this one
|
||||
//TODO: fix the stupid api on how it's not working name histories
|
||||
//URL url = new URL("https://api.ashcon.app/mojang/v2/user/" + compactUuid);
|
||||
URL url = new URL("https://api.mojang.com/user/profiles/" + compactUuid + "/names");
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
//conn.setRequestProperty("User-Agent", "");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
FName[] oldNames = gson.fromJson(reader, FName[].class);
|
||||
if (oldNames == null)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
|
||||
return;
|
||||
}
|
||||
reader.close();
|
||||
conn.disconnect();
|
||||
Arrays.sort(oldNames);
|
||||
printHistory(sender, oldNames);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Error, see logs for more details.");
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(TotalFreedomMod.getPlugin());
|
||||
}
|
||||
|
||||
private static void printHistory(CommandSender sender, FName[] oldNames)
|
||||
{
|
||||
if (oldNames.length == 1)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.GREEN + oldNames[0].getName() + ChatColor.GOLD + " has never changed their name.");
|
||||
return;
|
||||
}
|
||||
FSync.playerMsg(sender, ChatColor.GOLD + "Original name: " + ChatColor.GREEN + oldNames[0].getName());
|
||||
for (int i = 1; i < oldNames.length; i++)
|
||||
{
|
||||
Date date = new Date(oldNames[i].getChangedToAt());
|
||||
String formattedDate = dateFormat.format(date);
|
||||
FSync.playerMsg(sender, ChatColor.BLUE + formattedDate + ChatColor.GOLD + " changed to " + ChatColor.GREEN + oldNames[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class FName implements Comparable<FName>
|
||||
{
|
||||
private final String name;
|
||||
private final long changedToAt;
|
||||
|
||||
//Added constructor because otherwise there's no way name or changedToAt would have been anything other than null.
|
||||
public FName(String name, long changedToAt)
|
||||
{
|
||||
this.name = name;
|
||||
this.changedToAt = changedToAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FName other)
|
||||
{
|
||||
return Long.compare(this.changedToAt, other.changedToAt);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getChangedToAt()
|
||||
{
|
||||
return changedToAt;
|
||||
}
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class History
|
||||
{
|
||||
|
||||
public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static void reportHistory(final CommandSender sender, final String username)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
UUID uuid = UUIDFetcher.fetch(username);
|
||||
if (uuid != null)
|
||||
{
|
||||
Gson gson = new GsonBuilder().create();
|
||||
String compactUuid = uuid.toString().replace("-", "");
|
||||
try
|
||||
{
|
||||
//UUIDs or playernames actually work with this one
|
||||
//TODO: fix the stupid api on how it's not working name histories
|
||||
//URL url = new URL("https://api.ashcon.app/mojang/v2/user/" + compactUuid);
|
||||
URL url = new URL("https://api.mojang.com/user/profiles/" + compactUuid + "/names");
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
//conn.setRequestProperty("User-Agent", "");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
FName[] oldNames = gson.fromJson(reader, FName[].class);
|
||||
if (oldNames == null)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
|
||||
return;
|
||||
}
|
||||
reader.close();
|
||||
conn.disconnect();
|
||||
Arrays.sort(oldNames);
|
||||
printHistory(sender, oldNames);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Error, see logs for more details.");
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(TotalFreedomMod.getPlugin());
|
||||
}
|
||||
|
||||
private static void printHistory(CommandSender sender, FName[] oldNames)
|
||||
{
|
||||
if (oldNames.length == 1)
|
||||
{
|
||||
FSync.playerMsg(sender, ChatColor.GREEN + oldNames[0].getName() + ChatColor.GOLD + " has never changed their name.");
|
||||
return;
|
||||
}
|
||||
FSync.playerMsg(sender, ChatColor.GOLD + "Original name: " + ChatColor.GREEN + oldNames[0].getName());
|
||||
for (int i = 1; i < oldNames.length; i++)
|
||||
{
|
||||
Date date = new Date(oldNames[i].getChangedToAt());
|
||||
String formattedDate = dateFormat.format(date);
|
||||
FSync.playerMsg(sender, ChatColor.BLUE + formattedDate + ChatColor.GOLD + " changed to " + ChatColor.GREEN + oldNames[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class FName implements Comparable<FName>
|
||||
{
|
||||
private final String name;
|
||||
private final long changedToAt;
|
||||
|
||||
//Added constructor because otherwise there's no way name or changedToAt would have been anything other than null.
|
||||
public FName(String name, long changedToAt)
|
||||
{
|
||||
this.name = name;
|
||||
this.changedToAt = changedToAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FName other)
|
||||
{
|
||||
return Long.compare(this.changedToAt, other.changedToAt);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getChangedToAt()
|
||||
{
|
||||
return changedToAt;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +1,68 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
// UUIDFetcher retrieves UUIDs from usernames via web requests to Mojang.
|
||||
public class UUIDFetcher
|
||||
{
|
||||
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
|
||||
public static UUID fetch(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
Gson gson = new GsonBuilder().create();
|
||||
UUID uuid;
|
||||
String body = gson.toJson(name);
|
||||
URL url = new URL(PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
FetchedUuid[] id = gson.fromJson(
|
||||
new InputStreamReader(connection.getInputStream()),
|
||||
FetchedUuid[].class);
|
||||
|
||||
if (id.length == 0 || id[0].getID() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String idd = id[0].getID();
|
||||
uuid = UUID.fromString(idd.substring(0, 8) + "-" + idd.substring(8, 12)
|
||||
+ "-" + idd.substring(12, 16) + "-" + idd.substring(16, 20) + "-"
|
||||
+ idd.substring(20, 32));
|
||||
return uuid;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class FetchedUuid
|
||||
{
|
||||
|
||||
private String id;
|
||||
|
||||
public String getID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
// UUIDFetcher retrieves UUIDs from usernames via web requests to Mojang.
|
||||
public class UUIDFetcher
|
||||
{
|
||||
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
|
||||
public static UUID fetch(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
Gson gson = new GsonBuilder().create();
|
||||
UUID uuid;
|
||||
String body = gson.toJson(name);
|
||||
URL url = new URL(PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
FetchedUuid[] id = gson.fromJson(
|
||||
new InputStreamReader(connection.getInputStream()),
|
||||
FetchedUuid[].class);
|
||||
|
||||
if (id.length == 0 || id[0].getID() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String idd = id[0].getID();
|
||||
uuid = UUID.fromString(idd.substring(0, 8) + "-" + idd.substring(8, 12)
|
||||
+ "-" + idd.substring(12, 16) + "-" + idd.substring(16, 20) + "-"
|
||||
+ idd.substring(20, 32));
|
||||
return uuid;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class FetchedUuid
|
||||
{
|
||||
|
||||
private String id;
|
||||
|
||||
public String getID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@ server:
|
||||
|
||||
# All players who show up as executive
|
||||
executives: [ ]
|
||||
|
||||
# All players who show up as assistant executive
|
||||
assistant_executives: []
|
||||
|
||||
# All those who can manage the master builder list
|
||||
master_builder_management: [ ]
|
||||
|
Loading…
Reference in New Issue
Block a user