This commit is contained in:
ZeroEpoch1969
2019-11-03 14:43:29 -07:00
17 changed files with 934 additions and 109 deletions

View File

@ -0,0 +1,55 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopData;
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", 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;
}
}
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.");
return true;
}
}

View File

@ -0,0 +1,165 @@
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.util.FUtil;
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.BOTH)
@CommandParameters(description = "Manage the shop", usage = "/<command> <coins: <add | set | remove> <amount> <player | all>>", 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 (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
msg("The shop is currently disabled!", ChatColor.RED);
return true;
}
if (!FUtil.isExecutive(sender.getName()) && !sender.getName().equals("CONSOLE"))
{
msg("Only executives can use this command!", ChatColor.RED);
return true;
}
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
if (args.length > 3)
{
if (args[0].equalsIgnoreCase("coins"))
{
if (getPlayer(args[3]) != null || args[3].equals("all"))
{
Player p = null;
ShopData sd = null;
if (!args[3].equals("all"))
{
p = getPlayer(args[3]);
sd = plugin.sh.getData(p);
}
int newAmount;
int num;
switch (args[1])
{
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;
}
}
else
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
}
}
return false;
}
}

View File

@ -35,9 +35,9 @@ public class Command_nicknyan extends FreedomCommand
msg("That nickname contains invalid characters.");
return true;
}
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
else if (nickPlain.length() < 3 || nickPlain.length() > 30)
{
msg("Your nickname must be between 4 and 30 characters long.");
msg("Your nickname must be between 3 and 30 characters long.");
return true;
}

View File

@ -29,9 +29,9 @@ public class Command_rainbownick extends FreedomCommand
return true;
}
if (nickPlain.length() < 4 || nickPlain.length() > 30)
if (nickPlain.length() < 3 || nickPlain.length() > 30)
{
msg("Your nickname must be between 4 and 30 characters long.");
msg("Your nickname must be between 3 and 30 characters long.");
return true;
}
@ -56,4 +56,4 @@ public class Command_rainbownick extends FreedomCommand
return true;
}
}
}

View File

@ -39,6 +39,7 @@ public class Command_toggle extends FreedomCommand
msg("- unsafeenchs");
msg("- bells");
msg("- armorstands");
msg("- clearonjoin");
return false;
}
@ -171,6 +172,11 @@ public class Command_toggle extends FreedomCommand
toggle("The placement of armor stands is", ConfigEntry.ALLOW_ARMOR_STANDS);
return true;
}
else if (args[0].equalsIgnoreCase("clearonjoin"))
{
toggle("The clearing of inventories on join is", ConfigEntry.ALLOW_CLEAR_ON_JOIN);
return true;
}
else
{
return false;
@ -189,7 +195,7 @@ public class Command_toggle extends FreedomCommand
{
return Arrays.asList(
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs", "bells", "armorstands");
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs", "bells", "armorstands", "clearonjoin");
}
return Collections.emptyList();