This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ReefRealm/coinsystem
Add coins system to SkyPVP module
- Loading branch information
Showing
7 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
src/main/java/net/reefrealm/reefrealmskypvp/economy/CoinsSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
package net.reefrealm.reefrealmskypvp.economy; | ||
|
||
public class CoinsSystem { | ||
|
||
/*TODO | ||
- Add coins command | ||
- Add coins top command | ||
- Add coins pay command | ||
- Add coins give command | ||
- Add coins take command | ||
*/ | ||
} | ||
import net.reefrealm.reefrealmskypvp.data.MySQL; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
public class CoinsSystem{ | ||
|
||
public static void addCoins(Player player, int coins){ | ||
MySQL.addCoins(player.getUniqueId().toString(), coins); | ||
} | ||
|
||
public static void overWriteCoins(Player player, int coins){ | ||
MySQL.overrideCoinsAmount(player.getUniqueId().toString(), coins); | ||
} | ||
|
||
public static void removeCoins(Player player, int coins){ | ||
MySQL.removeCoins(player.getUniqueId().toString(), coins); | ||
} | ||
|
||
|
||
} |
157 changes: 157 additions & 0 deletions
157
src/main/java/net/reefrealm/reefrealmskypvp/economy/command/CoinsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package net.reefrealm.reefrealmskypvp.economy.command; | ||
|
||
import net.reefrealm.reefrealmskypvp.data.MySQL; | ||
import net.reefrealm.reefrealmskypvp.economy.CoinsSystem; | ||
import net.reefrealm.reefrealmskypvp.manager.CommandManager; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CoinsCommand extends CommandManager implements TabCompleter { | ||
public CoinsCommand(String commandName) { | ||
super("coins"); | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
if (!(sender instanceof Player)) { | ||
sender.sendMessage("This command can only be run by a player."); | ||
return; | ||
} | ||
|
||
Player player = (Player) sender; | ||
|
||
if (args.length == 0) { | ||
// /coins | ||
int coins = MySQL.getCoins(player.getUniqueId().toString()); | ||
player.sendMessage("You have " + coins + " coins."); | ||
} else { | ||
switch (args[0].toLowerCase()) { | ||
case "remove": | ||
if (args.length == 3) { | ||
if (!player.hasPermission("reefrealmskypvp.coins.remove")) { | ||
player.sendMessage("You do not have permission to use this command."); | ||
return; | ||
} | ||
// /coins remove <player> <value> | ||
Player target = Bukkit.getPlayer(args[1]); | ||
if (target == null) { | ||
player.sendMessage("That player is not online."); | ||
return; | ||
} | ||
|
||
int value; | ||
try { | ||
value = Integer.parseInt(args[2]); | ||
} catch (NumberFormatException e) { | ||
player.sendMessage("Invalid number."); | ||
return; | ||
} | ||
|
||
CoinsSystem.removeCoins(target, value); | ||
player.sendMessage("Removed " + value + " coins from " + target.getName() + "."); | ||
} else { | ||
player.sendMessage("Invalid usage. Use /coins remove <player> <value>."); | ||
} | ||
break; | ||
case "set": | ||
if (args.length == 3) { | ||
if (!player.hasPermission("reefrealmskypvp.coins.set")) { | ||
player.sendMessage("You do not have permission to use this command."); | ||
return; | ||
} | ||
// /coins set <player> <value> | ||
Player target = Bukkit.getPlayer(args[1]); | ||
if (target == null) { | ||
player.sendMessage("That player is not online."); | ||
return; | ||
} | ||
|
||
int value; | ||
try { | ||
value = Integer.parseInt(args[2]); | ||
} catch (NumberFormatException e) { | ||
player.sendMessage("Invalid number."); | ||
return; | ||
} | ||
|
||
CoinsSystem.overWriteCoins(target, value); | ||
player.sendMessage("Set " + target.getName() + "'s coins to " + value + "."); | ||
} else { | ||
player.sendMessage("Invalid usage. Use /coins set <player> <value>."); | ||
} | ||
break; | ||
case "add": | ||
if (args.length == 3) { | ||
if (!player.hasPermission("reefrealmskypvp.coins.add")) { | ||
player.sendMessage("You do not have permission to use this command."); | ||
return; | ||
} | ||
// /coins add <player> <value> | ||
Player target = Bukkit.getPlayer(args[1]); | ||
if (target == null) { | ||
player.sendMessage("That player is not online."); | ||
return; | ||
} | ||
|
||
int value; | ||
try { | ||
value = Integer.parseInt(args[2]); | ||
} catch (NumberFormatException e) { | ||
player.sendMessage("Invalid number."); | ||
return; | ||
} | ||
|
||
CoinsSystem.addCoins(target, value); | ||
player.sendMessage("Added " + value + " coins to " + target.getName() + "."); | ||
} else { | ||
player.sendMessage("Invalid usage. Use /coins add <player> <value>."); | ||
} | ||
break; | ||
default: | ||
player.sendMessage("Invalid command. Use /coins, /coins remove <player> <value>, /coins set <player> <value>, or /coins add <player> <value>."); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { | ||
if (args.length == 1) { | ||
// If the player has only typed "/coins ", suggest the subcommands | ||
List<String> suggestions = new ArrayList<>(); | ||
if (sender.hasPermission("reefrealmskypvp.coins.add")) { | ||
suggestions.add("add"); | ||
} | ||
if (sender.hasPermission("reefrealmskypvp.coins.remove")) { | ||
suggestions.add("remove"); | ||
} | ||
if (sender.hasPermission("reefrealmskypvp.coins.set")) { | ||
suggestions.add("set"); | ||
} | ||
return suggestions; | ||
} else if (args.length == 2) { | ||
// If the player has typed "/coins <subcommand> ", suggest online player names | ||
if ((args[0].equalsIgnoreCase("add") && sender.hasPermission("reefrealmskypvp.coins.add")) || | ||
(args[0].equalsIgnoreCase("remove") && sender.hasPermission("reefrealmskypvp.coins.remove")) || | ||
(args[0].equalsIgnoreCase("set") && sender.hasPermission("reefrealmskypvp.coins.set"))) { | ||
List<String> playerNames = new ArrayList<>(); | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
playerNames.add(player.getName()); | ||
} | ||
return playerNames; | ||
} | ||
} | ||
// If the player has typed anything else, don't suggest anything | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters