diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6ee4144..54169a3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,23 +3,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
@@ -39,17 +71,18 @@
-
+
-
-
-
+
+
+
+
@@ -65,7 +98,6 @@
-
diff --git a/src/main/java/rip/tilly/bedwars/BedWars.java b/src/main/java/rip/tilly/bedwars/BedWars.java
index 0ea2ad5..22f8a49 100644
--- a/src/main/java/rip/tilly/bedwars/BedWars.java
+++ b/src/main/java/rip/tilly/bedwars/BedWars.java
@@ -7,6 +7,7 @@ import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.java.JavaPlugin;
+import rip.tilly.bedwars.listeners.RandomListeners;
import rip.tilly.bedwars.mongo.MongoManager;
import rip.tilly.bedwars.player.PlayerDataHandler;
import rip.tilly.bedwars.player.PlayerDataManager;
@@ -29,6 +30,7 @@ public final class BedWars extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
+
this.saveDefaultConfig();
Bukkit.getConsoleSender().sendMessage("------------------------------------------------");
@@ -76,7 +78,8 @@ public final class BedWars extends JavaPlugin {
private void loadListeners() {
Arrays.asList(
- new PlayerDataHandler()
+ new PlayerDataHandler(),
+ new RandomListeners()
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));
}
}
diff --git a/src/main/java/rip/tilly/bedwars/commands/BaseCommand.java b/src/main/java/rip/tilly/bedwars/commands/BaseCommand.java
new file mode 100644
index 0000000..0b17b4a
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/BaseCommand.java
@@ -0,0 +1,14 @@
+package rip.tilly.bedwars.commands;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+import java.util.List;
+
+public abstract class BaseCommand {
+
+
+ public abstract void executeAs(CommandSender sender, Command cmd, String label, String[] args);
+
+ public abstract List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args);
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/level/AddCommand.java b/src/main/java/rip/tilly/bedwars/commands/level/AddCommand.java
new file mode 100644
index 0000000..0f30365
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/level/AddCommand.java
@@ -0,0 +1,49 @@
+package rip.tilly.bedwars.commands.level;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import rip.tilly.bedwars.BedWars;
+import rip.tilly.bedwars.commands.BaseCommand;
+import rip.tilly.bedwars.player.PlayerData;
+import rip.tilly.bedwars.utils.CC;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AddCommand extends BaseCommand {
+
+ private BedWars main = BedWars.getInstance();
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(CC.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!CC.isNumeric(args[2])) {
+ player.sendMessage(CC.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Integer amount = Integer.parseInt(args[2]);
+
+ playerData.setLevel(playerData.getLevel() + amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java b/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java
new file mode 100644
index 0000000..8739800
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java
@@ -0,0 +1,52 @@
+package rip.tilly.bedwars.commands.level;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+public class LevelCommand implements CommandExecutor {
+
+ private Main main;
+
+ public LevelCommand(Main main) {
+ this.main = main;
+ }
+
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
+ player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
+
+ return true;
+ }
+
+ if (args.length == 0) {
+ player.sendMessage(Utils.translate("&cUsage:"));
+ player.sendMessage(Utils.translate(" &c/level"));
+ player.sendMessage(Utils.translate(" &c/level set "));
+ player.sendMessage(Utils.translate(" &c/level add "));
+ player.sendMessage(Utils.translate(" &c/level remove "));
+ } else {
+ switch (args[0]) {
+ case "set":
+ new SetCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ case "add":
+ new AddCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ case "remove":
+ new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java b/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java
new file mode 100644
index 0000000..299100b
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java
@@ -0,0 +1,52 @@
+package rip.tilly.bedwars.commands.level;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import rip.tilly.bedwars.BedWars;
+import rip.tilly.bedwars.player.PlayerData;
+import rip.tilly.bedwars.utils.CC;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.commands.BaseCommand;
+import xyz.trixkz.bedwarspractice.managers.user.User;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RemoveCommand extends BaseCommand {
+
+ private BedWars main = BedWars.getInstance();
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(CC.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!CC.isNumeric(args[2])) {
+ player.sendMessage(CC.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Integer amount = Integer.parseInt(args[2]);
+
+ playerData.setLevel(playerData.getLevel() - amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java b/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java
new file mode 100644
index 0000000..c0e3b1d
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java
@@ -0,0 +1,53 @@
+package rip.tilly.bedwars.commands.level;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.commands.BaseCommand;
+import xyz.trixkz.bedwarspractice.managers.user.User;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SetCommand extends BaseCommand {
+
+ private Main main;
+
+ public SetCommand(Main main) {
+ this.main = main;
+ }
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ User user = User.getByUUID(target.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(Utils.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!this.main.getUtils().isNumeric(args[2])) {
+ player.sendMessage(Utils.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Integer amount = Integer.parseInt(args[2]);
+
+ user.getSettings().setLevel(amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/setspawn/SetSpawnCommand.java b/src/main/java/rip/tilly/bedwars/commands/setspawn/SetSpawnCommand.java
new file mode 100644
index 0000000..875414b
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/setspawn/SetSpawnCommand.java
@@ -0,0 +1,40 @@
+package rip.tilly.bedwars.commands.setspawn;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import rip.tilly.bedwars.BedWars;
+import rip.tilly.bedwars.utils.CC;
+
+public class SetSpawnCommand implements CommandExecutor {
+
+ private BedWars main = BedWars.getInstance();
+
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ if (!player.hasPermission("bedwars.admin")) {
+ player.sendMessage(CC.translate("&cNo permission"));
+
+ return true;
+ }
+
+ if (args.length == 0) {
+ player.sendMessage(CC.translate("&cUsage:"));
+ player.sendMessage(CC.translate(" &c/setspawn spawn"));
+ player.sendMessage(CC.translate(" &c/setspawn holograms"));
+ } else {
+ switch (args[0]) {
+ case "spawn":
+ new SpawnCommand().executeAs(sender, cmd, label, args);
+
+ break;
+ case "holograms":
+ break;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java b/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java
new file mode 100644
index 0000000..8000f2e
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java
@@ -0,0 +1,38 @@
+package rip.tilly.bedwars.commands.setspawn;
+
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import rip.tilly.bedwars.BedWars;
+import rip.tilly.bedwars.utils.CC;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SpawnCommand extends BaseCommand {
+
+ private BedWars main = BedWars.getInstance();
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Location location = player.getLocation();
+
+ int x = location.getBlockX();
+ int y = location.getBlockY();
+ int z = location.getBlockZ();
+
+ player.getWorld().setSpawnLocation(x, y, z);
+
+ player.sendMessage(CC.translate("&aSpawn point set"));
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java b/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java
new file mode 100644
index 0000000..f4f7834
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java
@@ -0,0 +1,53 @@
+package rip.tilly.bedwars.commands.xp;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.commands.BaseCommand;
+import xyz.trixkz.bedwarspractice.managers.user.User;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AddCommand extends BaseCommand {
+
+ private Main main;
+
+ public AddCommand(Main main) {
+ this.main = main;
+ }
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ User user = User.getByUUID(target.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(Utils.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!this.main.getUtils().isNumeric(args[2])) {
+ player.sendMessage(Utils.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Double amount = Double.parseDouble(args[2]);
+
+ user.getSettings().addXp(target, amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java b/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java
new file mode 100644
index 0000000..443dc96
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java
@@ -0,0 +1,53 @@
+package rip.tilly.bedwars.commands.xp;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.commands.BaseCommand;
+import xyz.trixkz.bedwarspractice.managers.user.User;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RemoveCommand extends BaseCommand {
+
+ private Main main;
+
+ public RemoveCommand(Main main) {
+ this.main = main;
+ }
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ User user = User.getByUUID(target.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(Utils.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!this.main.getUtils().isNumeric(args[2])) {
+ player.sendMessage(Utils.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Double amount = Double.parseDouble(args[2]);
+
+ user.getSettings().removeXp(amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java b/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java
new file mode 100644
index 0000000..8098637
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java
@@ -0,0 +1,53 @@
+package rip.tilly.bedwars.commands.xp;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.commands.BaseCommand;
+import xyz.trixkz.bedwarspractice.managers.user.User;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SetCommand extends BaseCommand {
+
+ private Main main;
+
+ public SetCommand(Main main) {
+ this.main = main;
+ }
+
+ @Override
+ public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ Player target = this.main.getServer().getPlayer(args[1]);
+
+ User user = User.getByUUID(target.getUniqueId());
+
+ if (!target.isOnline()) {
+ player.sendMessage(Utils.translate("&cError: Player is not currently online"));
+
+ return;
+ }
+
+ if (!this.main.getUtils().isNumeric(args[2])) {
+ player.sendMessage(Utils.translate("&cError: Please send a valid number"));
+
+ return;
+ }
+
+ Double amount = Double.parseDouble(args[2]);
+
+ user.getSettings().setXp(amount);
+ }
+
+ @Override
+ public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
+ List tabCompletions = new ArrayList();
+
+ return tabCompletions;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java b/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java
new file mode 100644
index 0000000..d5c81a2
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java
@@ -0,0 +1,52 @@
+package rip.tilly.bedwars.commands.xp;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import xyz.trixkz.bedwarspractice.Main;
+import xyz.trixkz.bedwarspractice.utils.Utils;
+
+public class XpCommand implements CommandExecutor {
+
+ private Main main;
+
+ public XpCommand(Main main) {
+ this.main = main;
+ }
+
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+ Player player = (Player) sender;
+
+ if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
+ player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
+
+ return true;
+ }
+
+ if (args.length == 0) {
+ player.sendMessage(Utils.translate("&cUsage:"));
+ player.sendMessage(Utils.translate(" &c/xp"));
+ player.sendMessage(Utils.translate(" &c/xp set "));
+ player.sendMessage(Utils.translate(" &c/xp add "));
+ player.sendMessage(Utils.translate(" &c/xp remove "));
+ } else {
+ switch (args[0]) {
+ case "set":
+ new SetCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ case "add":
+ new AddCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ case "remove":
+ new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
+
+ break;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/listeners/RandomListeners.java b/src/main/java/rip/tilly/bedwars/listeners/RandomListeners.java
new file mode 100644
index 0000000..63e728d
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/listeners/RandomListeners.java
@@ -0,0 +1,28 @@
+package rip.tilly.bedwars.listeners;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.FoodLevelChangeEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.weather.WeatherChangeEvent;
+
+public class RandomListeners implements Listener {
+
+ @EventHandler
+ public void onFoodLevelChange(FoodLevelChangeEvent event) {
+ event.setCancelled(true);
+ }
+
+ @EventHandler
+ public void onPlayerDropItem(PlayerDropItemEvent event) {
+ // event.setCancelled(true);
+
+ // to do
+ // only be able to drop an item when the player is in a game
+ }
+
+ @EventHandler
+ public void onWeatherChange(WeatherChangeEvent event) {
+ event.setCancelled(true);
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/managers/CommandManager.java b/src/main/java/rip/tilly/bedwars/managers/CommandManager.java
new file mode 100644
index 0000000..d09fa4d
--- /dev/null
+++ b/src/main/java/rip/tilly/bedwars/managers/CommandManager.java
@@ -0,0 +1,17 @@
+package rip.tilly.bedwars.managers;
+
+import rip.tilly.bedwars.BedWars;
+import rip.tilly.bedwars.commands.setspawn.SetSpawnCommand;
+
+public class CommandManager {
+
+ private BedWars main = BedWars.getInstance();
+
+ public CommandManager() {
+ this.registerCommands();
+ }
+
+ private void registerCommands() {
+ this.main.getCommand("setspawn").setExecutor(new SetSpawnCommand());
+ }
+}
diff --git a/src/main/java/rip/tilly/bedwars/utils/CC.java b/src/main/java/rip/tilly/bedwars/utils/CC.java
index 2863b8f..78e7ccd 100644
--- a/src/main/java/rip/tilly/bedwars/utils/CC.java
+++ b/src/main/java/rip/tilly/bedwars/utils/CC.java
@@ -35,4 +35,12 @@ public class CC {
}
return strings;
}
+
+ public static boolean isNumeric(String string) {
+ return regexNumeric(string).length() == 0;
+ }
+
+ public static String regexNumeric(String string) {
+ return string.replaceAll("[0-9]", "").replaceFirst("\\.", "");
+ }
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index a1029ef..1dda7d1 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -4,3 +4,6 @@ main: rip.tilly.bedwars.BedWars
authors:
- Lucanius
- Trixkz
+
+commands:
+ setspawn:
\ No newline at end of file