This commit is contained in:
Brandon 2023-10-29 05:21:50 +00:00
parent 662848025a
commit 2fdf30e89a
116 changed files with 10335 additions and 0 deletions

BIN
lib/ProtocolLib.jar Normal file

Binary file not shown.

BIN
lib/lombok.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/server.jar Normal file

Binary file not shown.

83
pom.xml Normal file
View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/server.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>3.10.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
<groupId>me.abhi.practice</groupId>
<artifactId>mPractice</artifactId>
<version>1.0-SNAPSHOT</version>
</project>

View File

@ -0,0 +1,150 @@
package me.abhi.practice;
import lombok.Getter;
import me.abhi.practice.command.CommandFramework;
import me.abhi.practice.command.impl.hybrid.EventCommand;
import me.abhi.practice.command.impl.management.BuilderCommand;
import me.abhi.practice.command.impl.management.SetEditorCommand;
import me.abhi.practice.command.impl.management.SetSpawnCommand;
import me.abhi.practice.command.impl.management.arena.ArenaCommand;
import me.abhi.practice.command.impl.management.kit.KitCommand;
import me.abhi.practice.command.impl.management.kit.hcf.SetArcherKitCommand;
import me.abhi.practice.command.impl.management.kit.hcf.SetBardKitCommand;
import me.abhi.practice.command.impl.management.kit.hcf.SetDiamondKitCommand;
import me.abhi.practice.command.impl.management.kit.hcf.SetRogueKitCommand;
import me.abhi.practice.command.impl.player.*;
import me.abhi.practice.command.impl.player.time.DayCommand;
import me.abhi.practice.command.impl.player.time.NightCommand;
import me.abhi.practice.command.impl.player.time.SunsetCommand;
import me.abhi.practice.command.impl.staff.SetEloCommand;
import me.abhi.practice.command.impl.staff.SilentCommand;
import me.abhi.practice.command.impl.staff.TournamentCommand;
import me.abhi.practice.listener.PacketListener;
import me.abhi.practice.listener.PlayerListener;
import me.abhi.practice.listener.hcf.ArcherListener;
import me.abhi.practice.listener.hcf.BardListener;
import me.abhi.practice.listener.hcf.RogueListener;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.task.*;
import me.abhi.practice.task.player.ArcherMarkTask;
import me.abhi.practice.task.player.RogueBackstabTask;
import me.abhi.practice.util.misc.BlankObject;
import me.abhi.practice.util.misc.EntityHider;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Arrays;
@Getter
public class PracticePlugin extends JavaPlugin {
@Getter
private static PracticePlugin instance;
private EntityHider entityHider;
private ManagerHandler managerHandler;
@Override
public void onEnable() {
instance = this;
getConfig().options().copyDefaults(true);
saveConfig();
managerHandler = new ManagerHandler(this);
managerHandler.register();
registerCommands(
new SetSpawnCommand(this),
new SetEditorCommand(this),
new KitCommand(this),
new ArenaCommand(this),
new SpawnCommand(this),
new InventoryCommand(this),
new PartyCommand(this),
new DayCommand(),
new SunsetCommand(),
new NightCommand(),
new DuelCommand(this),
new LeaderboardsCommand(this),
new AcceptCommand(this),
new SetDiamondKitCommand(),
new SetArcherKitCommand(),
new SetBardKitCommand(),
new SetRogueKitCommand(),
new EventCommand(this),
(this.getConfig().getBoolean("scoreboard.enabled") ? new ToggleScoreboardCommand(this) : new BlankObject()), // Disable /togglescoreboard when scoreboard option is disabledm
new TournamentCommand(this),
new SpectateCommand(this),
new SilentCommand(this),
new BuilderCommand(this),
new ToggleDuelRequestsCommand(this),
new SetEloCommand(this),
(this.getConfig().getBoolean("settings.settings-gui") ? new SettingsCommand(this) : new BlankObject())
);
registerListeners(
new PlayerListener(this),
new PacketListener(this),
new BardListener(this),
new ArcherListener(this),
new RogueListener(this)
);
entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST);
registerTasks(
new InventoryTask(this),
new ScoreboardTask(this),
new WorldTask(this),
new ArcherMarkTask(this),
new RogueBackstabTask(this)
);
new EnderpearlTask(this).runTaskTimerAsynchronously(this, 1L, 1L); // registered separately because of different timing
new MongoTask(this).runTaskTimerAsynchronously(this, 2400, 2400); // save player data every 2 mins
this.getServer().getWorlds().stream().forEach(w -> {
w.setTime(6000L);
});
disableGameRules(
"doDaylightCycle",
"doMobSpawning",
"doFireTick");
}
@Override
public void onDisable() {
this.getServer().getOnlinePlayers().stream().forEach(p -> p.kickPlayer("Server restarting."));
managerHandler.getSettingsManager().save();
managerHandler.getKitManager().save();
managerHandler.getArenaManager().save();
managerHandler.getEventManager().save();
this.getServer().getWorlds().forEach(w -> {
w.getEntities().stream().filter(e -> e.getType() == EntityType.DROPPED_ITEM).forEach(Entity::remove);
});
}
private void registerCommands(Object... objects) {
CommandFramework commandFramework = new CommandFramework(this);
Arrays.stream(objects).forEach(o -> commandFramework.registerCommands(o));
}
private void registerListeners(Listener... listeners) {
Arrays.stream(listeners).forEach(l -> getServer().getPluginManager().registerEvents(l, this));
}
private void registerTasks(BukkitRunnable... bukkitRunnables) {
Arrays.stream(bukkitRunnables).forEach(br -> br.runTaskTimerAsynchronously(this, 0L, 0L));
}
private void disableGameRules(String... gameRules) {
Arrays.stream(gameRules).forEach(gr -> this.getServer().getWorlds().stream().forEach(w -> w.setGameRuleValue(gr, "false")));
}
}

View File

@ -0,0 +1,18 @@
package me.abhi.practice.arena;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import me.abhi.practice.kit.KitType;
import org.bukkit.Location;
@Getter
@Setter
@RequiredArgsConstructor
public class Arena {
private final String name;
private Location l1;
private Location l2;
private KitType kitType = KitType.NORMAL;
}

View File

@ -0,0 +1,98 @@
package me.abhi.practice.command;
import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.Plugin;
import java.util.List;
/**
* Command Framework - BukkitCommand <br>
* An implementation of Bukkit's Command class allowing for registering of
* commands without plugin.yml
*
* @author minnymin3
*/
public class BukkitCommand extends org.bukkit.command.Command {
private final Plugin owningPlugin;
protected BukkitCompleter completer;
private CommandExecutor executor;
/**
* A slimmed down PluginCommand
*
* @param name
* @param owner
*/
protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
super(label);
this.executor = executor;
this.owningPlugin = owner;
this.usageMessage = "";
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
boolean success = false;
if (!owningPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = executor.onCommand(sender, this, commandLabel, args);
} catch (Throwable ex) {
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin "
+ owningPlugin.getDescription().getFullName(), ex);
}
if (!success && usageMessage.length() > 0) {
for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ")
.append(owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
}

View File

@ -0,0 +1,58 @@
package me.abhi.practice.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Command Framework - BukkitCompleter <br>
* An implementation of the TabCompleter class allowing for multiple tab
* completers per command
*
* @author minnymin3
*/
public class BukkitCompleter implements TabCompleter {
private Map<String, Entry<Method, Object>> completers = new HashMap<String, Entry<Method, Object>>();
public void addCompleter(String label, Method m, Object obj) {
completers.put(label, new AbstractMap.SimpleEntry<Method, Object>(m, obj));
}
@SuppressWarnings("unchecked")
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
if (!args[x].equals("") && !args[x].equals(" ")) {
buffer.append("." + args[x].toLowerCase());
}
}
String cmdLabel = buffer.toString();
if (completers.containsKey(cmdLabel)) {
Entry<Method, Object> entry = completers.get(cmdLabel);
try {
return (List<String>) entry.getKey().invoke(entry.getValue(),
new CommandArgs(sender, command, label, args, cmdLabel.split("\\.").length - 1));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return null;
}
}

View File

@ -0,0 +1,71 @@
package me.abhi.practice.command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Command Framework - Command <br>
* The command annotation used to designate methods as commands. All methods
* should have a single CommandArgs argument
*
* @author minnymin3
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
/**
* The name of the command. If it is a sub command then its values would be
* separated by periods. ie. a command that would be a subcommand of test
* would be 'test.subcommandname'
*
* @return
*/
public String name();
/**
* Gets the required permission of the command
*
* @return
*/
public String permission() default "";
/**
* The message sent to the profile when they do not have permission to
* execute it
*
* @return
*/
public String noPerm() default "You do not have permission to perform that action.";
/**
* A list of alternate names that the command is executed under. See
* name() for details on how names work
*
* @return
*/
public String[] aliases() default {};
/**
* The description that will appear in /help of the command
*
* @return
*/
public String description() default "";
/**
* The usage that will appear in /help (commandname)
*
* @return
*/
public String usage() default "";
/**
* Whether or not the command is available to players only
*
* @return
*/
public boolean inGameOnly() default false;
}

View File

@ -0,0 +1,108 @@
package me.abhi.practice.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Command Framework - CommandArgs <br>
* This class is passed to the command methods and contains various utilities as
* well as the command info.
*
* @author minnymin3
*/
public class CommandArgs {
private CommandSender sender;
private org.bukkit.command.Command command;
private String label;
private String[] args;
protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args,
int subCommand) {
String[] modArgs = new String[args.length - subCommand];
for (int i = 0; i < args.length - subCommand; i++) {
modArgs[i] = args[i + subCommand];
}
StringBuffer buffer = new StringBuffer();
buffer.append(label);
for (int x = 0; x < subCommand; x++) {
buffer.append("." + args[x]);
}
String cmdLabel = buffer.toString();
this.sender = sender;
this.command = command;
this.label = cmdLabel;
this.args = modArgs;
}
/**
* Gets the command sender
*
* @return
*/
public CommandSender getSender() {
return sender;
}
/**
* Gets the original command object
*
* @return
*/
public org.bukkit.command.Command getCommand() {
return command;
}
/**
* Gets the label including sub command labels of this command
*
* @return Something like 'test.subcommand'
*/
public String getLabel() {
return label.replace(".", " ");
}
/**
* Gets all the arguments after the command's label. ie. if the command
* label was test.subcommand and the arguments were subcommand foo foo, it
* would only return 'foo foo' because 'subcommand' is part of the command
*
* @return
*/
public String[] getArgs() {
return args;
}
/**
* Gets the argument at the specified index
*
* @param index The index to get
* @return The string at the specified index
*/
public String getArgs(int index) {
return args[index];
}
/**
* Returns the length of the command arguments
*
* @return int length of args
*/
public int length() {
return args.length;
}
public boolean isPlayer() {
return sender instanceof Player;
}
public Player getPlayer() {
if (sender instanceof Player) {
return (Player) sender;
} else {
return null;
}
}
}

View File

@ -0,0 +1,218 @@
package me.abhi.practice.command;
import me.abhi.practice.util.misc.CC;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.help.GenericCommandHelpTopic;
import org.bukkit.help.HelpTopic;
import org.bukkit.help.HelpTopicComparator;
import org.bukkit.help.IndexHelpTopic;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.SimplePluginManager;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
/**
* Command Framework - CommandFramework <br>
* The main command framework class used for controlling the framework.
*
* @author minnymin3
*/
public class CommandFramework implements CommandExecutor {
private Map<String, Entry<Method, Object>> commandMap = new HashMap<String, Entry<Method, Object>>();
private CommandMap map;
private Plugin plugin;
/**
* Initializes the command framework and sets up the command maps
*/
public CommandFramework(Plugin plugin) {
this.plugin = plugin;
if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
try {
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
map = (CommandMap) field.get(manager);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
}
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
return handleCommand(sender, cmd, label, args);
}
/**
* Handles commands. Used in the onCommand method in your JavaPlugin class
*`
* @param sender The {@link CommandSender} parsed from
* onCommand
* @param cmd The {@link org.bukkit.command.Command} parsed from onCommand
* @param label The label parsed from onCommand
* @param args The arguments parsed from onCommand
* @return Always returns true for simplicity's sake in onCommand
*/
public boolean handleCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
buffer.append("." + args[x].toLowerCase());
}
String cmdLabel = buffer.toString();
if (commandMap.containsKey(cmdLabel)) {
Method method = commandMap.get(cmdLabel).getKey();
Object methodObject = commandMap.get(cmdLabel).getValue();
Command command = method.getAnnotation(Command.class);
if (!command.permission().equalsIgnoreCase("") && !sender.hasPermission(command.permission())) {
sender.sendMessage(CC.RED + command.noPerm());
return true;
}
if (command.inGameOnly() && !(sender instanceof Player)) {
sender.sendMessage("This command is only performable in game");
return true;
}
try {
method.invoke(methodObject, new CommandArgs(sender, cmd, label, args,
cmdLabel.split("\\.").length - 1));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return true;
}
}
defaultCommand(new CommandArgs(sender, cmd, label, args, 0));
return true;
}
/**
* Registers all command and completer methods inside of the object. Similar
* to Bukkit's registerEvents method.
*
* @param obj The object to register the commands of
*/
public void registerCommands(Object obj) {
for (Method m : obj.getClass().getMethods()) {
if (m.getAnnotation(Command.class) != null) {
Command command = m.getAnnotation(Command.class);
if (m.getParameterTypes().length > 1 || m.getParameterTypes()[0] != CommandArgs.class) {
System.out.println("Unable to register command " + m.getName() + ". Unexpected method arguments");
continue;
}
registerCommand(command, command.name(), m, obj);
for (String alias : command.aliases()) {
registerCommand(command, alias, m, obj);
}
} else if (m.getAnnotation(Completer.class) != null) {
Completer comp = m.getAnnotation(Completer.class);
if (m.getParameterTypes().length > 1 || m.getParameterTypes().length == 0
|| m.getParameterTypes()[0] != CommandArgs.class) {
System.out.println("Unable to register tab completer " + m.getName()
+ ". Unexpected method arguments");
continue;
}
if (m.getReturnType() != List.class) {
System.out.println("Unable to register tab completer " + m.getName() + ". Unexpected return type");
continue;
}
registerCompleter(comp.name(), m, obj);
for (String alias : comp.aliases()) {
registerCompleter(alias, m, obj);
}
}
}
}
/**
* Registers all the commands under the plugin's help
*/
public void registerHelp() {
Set<HelpTopic> help = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance());
for (String s : commandMap.keySet()) {
if (!s.contains(".")) {
org.bukkit.command.Command cmd = map.getCommand(s);
HelpTopic topic = new GenericCommandHelpTopic(cmd);
help.add(topic);
}
}
IndexHelpTopic topic = new IndexHelpTopic(plugin.getName(), "All commands for " + plugin.getName(), null, help,
"Below is a list of all " + plugin.getName() + " commands:");
Bukkit.getServer().getHelpMap().addTopic(topic);
}
public void registerCommand(Command command, String label, Method m, Object obj) {
commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry<Method, Object>(m, obj));
commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(), new AbstractMap.SimpleEntry<Method, Object>(m, obj));
String cmdLabel = label.split("\\.")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), cmd);
}
if (!command.description().equalsIgnoreCase("") && cmdLabel == label) {
map.getCommand(cmdLabel).setDescription(command.description());
}
if (!command.usage().equalsIgnoreCase("") && cmdLabel == label) {
map.getCommand(cmdLabel).setUsage(command.usage());
}
}
public void registerCompleter(String label, Method m, Object obj) {
String cmdLabel = label.split("\\.")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), command);
}
if (map.getCommand(cmdLabel) instanceof BukkitCommand) {
BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel);
if (command.completer == null) {
command.completer = new BukkitCompleter();
}
command.completer.addCompleter(label, m, obj);
} else if (map.getCommand(cmdLabel) instanceof PluginCommand) {
try {
Object command = map.getCommand(cmdLabel);
Field field = command.getClass().getDeclaredField("completer");
field.setAccessible(true);
if (field.get(command) == null) {
BukkitCompleter completer = new BukkitCompleter();
completer.addCompleter(label, m, obj);
field.set(command, completer);
} else if (field.get(command) instanceof BukkitCompleter) {
BukkitCompleter completer = (BukkitCompleter) field.get(command);
completer.addCompleter(label, m, obj);
} else {
System.out.println("Unable to register tab completer " + m.getName()
+ ". A tab completer is already registered for that command!");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void defaultCommand(CommandArgs args) {
args.getSender().sendMessage(args.getLabel() + " is not handled! Oh noes!");
}
}

View File

@ -0,0 +1,37 @@
package me.abhi.practice.command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Command Framework - Completer <br>
* The completer annotation used to designate methods as command completers. All
* methods should have a single CommandArgs argument and return a String List
* object
*
* @author minnymin3
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Completer {
/**
* The command that this completer completes. If it is a sub command then
* its values would be separated by periods. ie. a command that would be a
* subcommand of test would be 'test.subcommandname'
*
* @return
*/
String name();
/**
* A list of alternate names that the completer is executed under. See
* name() for details on how names work
*
* @return
*/
String[] aliases() default {};
}

View File

@ -0,0 +1,305 @@
package me.abhi.practice.command.impl.hybrid;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.hostedevent.EventState;
import me.abhi.practice.hostedevent.HostedEvent;
import me.abhi.practice.hostedevent.impl.SumoEvent;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class EventCommand {
private final PracticePlugin plugin;
@Command(name = "event", inGameOnly = true)
public void event(CommandArgs args) {
args.getSender().sendMessage(Messages.EVENT_HELP.getMessage());
return;
}
@Command(name = "event.start", permission = "practice.event.start", inGameOnly = true)
public void eventStart(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
Player player = args.getPlayer();
if (System.currentTimeMillis() - this.plugin.getManagerHandler().getEventManager().getLastEvent() <= this.plugin.getManagerHandler().getSettingsManager().getEventDelay() && !player.hasPermission("practice.event.bypass")) {
args.getSender().sendMessage(Messages.EVENT_DELAY.getMessage());
return;
}
String name = args.getArgs(0);
if (this.plugin.getManagerHandler().getEventManager().getEvent(name) == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
if (this.plugin.getManagerHandler().getEventManager().getStartedEvent(name) != null) {
args.getSender().sendMessage(Messages.EVENT_ALREADY_STARTED.getMessage());
return;
}
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
this.plugin.getManagerHandler().getEventManager().getCurrentEvents().add(event);
event.setDown(System.currentTimeMillis());
new BukkitRunnable() {
int i = 30;
public void run() {
if (!plugin.getManagerHandler().getEventManager().getCurrentEvents().contains(event)) {
this.cancel();
return;
}
if (i % 10 == 0 && i > 0) {
TextComponent clickable = new TextComponent(Messages.EVENT_STARTING.getMessage().replace("%player%", player.getName()).replace("%event%", event.getName()));
clickable.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event join " + event.getName()));
clickable.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Messages.EVENT_HOVER.getMessage().replace("%event%", event.getName())).create()));
plugin.getServer().getOnlinePlayers().stream().forEach(p -> p.spigot().sendMessage(clickable));
}
i -= 1;
if (i == 0) {
event.setStartTime(System.currentTimeMillis());
event.startRound();
event.setEventState(EventState.STARTED);
this.cancel();
}
}
}.runTaskTimer(this.plugin, 0L, 20L);
return;
}
@Command(name = "event.stop", permission = "practice.command.event", inGameOnly = true)
public void eventStop(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
Player player = args.getPlayer();
if (System.currentTimeMillis() - this.plugin.getManagerHandler().getEventManager().getLastEvent() <= this.plugin.getManagerHandler().getSettingsManager().getEventDelay() && !player.hasPermission("practice.event.bypass")) {
args.getSender().sendMessage(Messages.EVENT_DELAY.getMessage());
return;
}
String name = args.getArgs(0);
if (this.plugin.getManagerHandler().getEventManager().getEvent(name) == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
if (this.plugin.getManagerHandler().getEventManager().getStartedEvent(name) == null) {
args.getSender().sendMessage(Messages.NO_EVENT_STARTED.getMessage());
return;
}
HostedEvent hostedEvent = this.plugin.getManagerHandler().getEventManager().getStartedEvent(name);
hostedEvent.end(hostedEvent.getName(), null);
return;
}
@Command(name = "event.join", inGameOnly = true)
public void eventJoin(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
String name = args.getArgs(0);
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
if (event == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
HostedEvent currentEvent = this.plugin.getManagerHandler().getEventManager().getStartedEvent(name);
if (currentEvent == null) {
args.getSender().sendMessage(Messages.NO_EVENT_STARTED.getMessage());
return;
}
if (currentEvent.getEventState() != EventState.STARTING) {
args.getSender().sendMessage(Messages.EVENT_ALREADY_STARTED.getMessage());
return;
}
if (event.getPlayers().size() >= this.plugin.getManagerHandler().getSettingsManager().getPlayersPerEvent() && !player.hasPermission("practice.event.bypass")) {
args.getSender().sendMessage(Messages.EVENT_FULL.getMessage());
return;
}
currentEvent.getPlayers().add(player.getUniqueId());
practiceProfile.setPlayerState(PlayerState.EVENT);
currentEvent.broadcast(Messages.PLAYER_JOINED_EVENT.getMessage().replace("%player%", player.getName()));
practiceProfile.setHostedEvent(currentEvent);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
currentEvent.getPlayers().forEach(u -> {
Player players = this.plugin.getServer().getPlayer(u);
players.showPlayer(player);
player.showPlayer(players);
});
}, 1L);
player.teleport(event.getLobby());
return;
}
@Command(name = "event.spectate", aliases = {"event.spec", "event.sp"}, inGameOnly = true)
public void eventSpectate(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
String name = args.getArgs(0);
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
if (event == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
HostedEvent currentEvent = this.plugin.getManagerHandler().getEventManager().getStartedEvent(name);
if (currentEvent == null) {
args.getSender().sendMessage(Messages.NO_EVENT_STARTED.getMessage());
return;
}
event.getSpectators().add(player.getUniqueId());
practiceProfile.setHostedEvent(event);
practiceProfile.setPlayerState(PlayerState.SPECTATING_EVENT);
player.teleport(event.getLobby());
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
if (!practiceProfile.isSilentMode())
event.broadcast(Messages.PLAYER_NOW_SPECTATING.getMessage().replace("%player%", player.getName()));
player.setGameMode(GameMode.CREATIVE);
event.getPlayers().forEach(u -> player.showPlayer(this.plugin.getServer().getPlayer(u)));
return;
}
@Command(name = "event.leave", inGameOnly = true)
public void eventLeave(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.EVENT && practiceProfile.getPlayerState() != PlayerState.SPECTATING_EVENT) {
args.getSender().sendMessage(Messages.NOT_IN_EVENT.getMessage());
return;
}
HostedEvent hostedEvent = practiceProfile.getHostedEvent();
if (hostedEvent instanceof SumoEvent) {
SumoEvent sumoEvent = (SumoEvent) hostedEvent;
if (sumoEvent.getP1() == player || sumoEvent.getP2() == player) {
sumoEvent.eliminatePlayer(player);
}
}
practiceProfile.setPlayerState(PlayerState.LOBBY);
if (hostedEvent.getPlayers().contains(player.getUniqueId())) {
hostedEvent.getPlayers().remove(player.getUniqueId());
hostedEvent.broadcast(Messages.PLAYER_LEFT_EVENT.getMessage().replace("%player%", player.getName()));
args.getSender().sendMessage(Messages.LEFT_EVENT.getMessage());
}
if (hostedEvent.getSpectators().contains(player.getUniqueId())) {
hostedEvent.getSpectators().remove(player.getUniqueId());
if (!practiceProfile.isSilentMode())
hostedEvent.broadcast(Messages.PLAYER_NO_LONGER_SPECTATING.getMessage().replace("%player%", player.getName()));
args.getSender().sendMessage(Messages.NO_LONGER_SPECTATING.getMessage());
}
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
return;
}
@Command(name = "event.lobby", permission = "practice.command.event", inGameOnly = true)
public void eventLobby(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
String name = args.getArgs(0);
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
if (event == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
event.setLobby(player.getLocation());
args.getSender().sendMessage(Messages.EVENT_LOBBY_SET.getMessage().replace("%event%", event.getName()));
return;
}
@Command(name = "event.first", permission = "practice.command.event", inGameOnly = true)
public void eventFirst(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
String name = args.getArgs(0);
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
if (event == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
event.setFirst(player.getLocation());
args.getSender().sendMessage(Messages.EVENT_FIRST_SET.getMessage().replace("%event%", event.getName()));
return;
}
@Command(name = "event.second", permission = "practice.command.event", inGameOnly = true)
public void eventSecond(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <event>");
return;
}
String name = args.getArgs(0);
HostedEvent event = this.plugin.getManagerHandler().getEventManager().getEvent(name);
if (event == null) {
args.getSender().sendMessage(Messages.EVENT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
event.setSecond(player.getLocation());
args.getSender().sendMessage(Messages.EVENT_SECOND_SET.getMessage().replace("%event%", event.getName()));
return;
}
}

View File

@ -0,0 +1,25 @@
package me.abhi.practice.command.impl.management;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class BuilderCommand {
private final PracticePlugin plugin;
@Command(name = "builder", aliases = {"building", "buildmode"}, permission = "practice.command.builder", inGameOnly = true)
public void builder(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setBuildMode(!practiceProfile.isBuildMode());
args.getSender().sendMessage(practiceProfile.isBuildMode() ? Messages.BUILDER_ENABLED.getMessage() : Messages.BUILDER_DISABLED.getMessage());
return;
}
}

View File

@ -0,0 +1,23 @@
package me.abhi.practice.command.impl.management;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class SetEditorCommand {
private final PracticePlugin plugin;
@Command(name = "seteditor", permission = "practice.command.seteditor", inGameOnly = true)
public void setEditor(CommandArgs args) {
Player player = args.getPlayer();
this.plugin.getManagerHandler().getSettingsManager().setEditor(player.getLocation());
args.getSender().sendMessage(Messages.EDITOR_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,23 @@
package me.abhi.practice.command.impl.management;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class SetSpawnCommand {
private final PracticePlugin plugin;
@Command(name = "setspawn", permission = "practice.command.setspawn", inGameOnly = true)
public void setSpawn(CommandArgs args) {
Player player = args.getPlayer();
this.plugin.getManagerHandler().getSettingsManager().setSpawn(player.getLocation());
args.getSender().sendMessage(Messages.SPAWN_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,152 @@
package me.abhi.practice.command.impl.management.arena;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.arena.Arena;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.bukkit.entity.Player;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class ArenaCommand {
private final PracticePlugin plugin;
@Command(name = "arena", permission = "practice.command.arena", inGameOnly = true)
public void arena(CommandArgs args) {
args.getSender().sendMessage(new String[]{
CC.GRAY + "" + CC.STRIKE + "--------------------------------------------",
CC.GOLD + "" + CC.BOLD + "Arena Commands:",
CC.GRAY + " * " + CC.YELLOW + "/arena create <name> - Create an arena",
CC.GRAY + " * " + CC.YELLOW + "/arena delete <name> - Delete an arena",
CC.GRAY + " * " + CC.YELLOW + "/arena first <name> - Set first spawn of an arena",
CC.GRAY + " * " + CC.YELLOW + "/arena second <name> - Set second spawn of an arena",
CC.GRAY + " * " + CC.YELLOW + "/arena setType <name> <type> - Set type of an arena",
CC.GRAY + " * " + CC.YELLOW + "/arena tp <name> - Teleport to an arena",
CC.GRAY + "" + CC.STRIKE + "--------------------------------------------"
});
}
@Command(name = "arena.create", permission = "practice.command.arena", inGameOnly = true)
public void arenaCreate(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena != null) {
args.getSender().sendMessage(Messages.ARENA_ALREADY_EXISTS.getMessage());
return;
}
this.plugin.getManagerHandler().getArenaManager().addArena(new Arena(name));
args.getSender().sendMessage(Messages.ARENA_CREATED.getMessage().replace("%arena%", name));
return;
}
@Command(name = "arena.delete", permission = "practice.command.arena", inGameOnly = true)
public void arenaDelete(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
this.plugin.getManagerHandler().getArenaManager().removeArena(arena);
args.getSender().sendMessage(Messages.ARENA_DELETED.getMessage().replace("%arena%", name));
return;
}
@Command(name = "arena.first", permission = "practice.command.arena", inGameOnly = true)
public void arenaFirst(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
arena.setL1(player.getLocation());
args.getSender().sendMessage(Messages.ARENA_FIRST_SET.getMessage().replace("%arena%", arena.getName()));
return;
}
@Command(name = "arena.second", permission = "practice.command.arena", inGameOnly = true)
public void arenaSecond(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
arena.setL2(player.getLocation());
args.getSender().sendMessage(Messages.ARENA_SECOND_SET.getMessage().replace("%arena%", arena.getName()));
return;
}
@Command(name = "arena.settype", permission = "practice.command.arena", inGameOnly = true)
public void arenaSetType(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <type>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
KitType kitType = KitType.getType(args.getArgs(1));
if (kitType == null) {
args.getSender().sendMessage(Messages.KIT_TYPE_DOESNT_EXIST.getMessage());
return;
}
arena.setKitType(kitType);
args.getSender().sendMessage(Messages.ARENA_TYPE_UPDATED.getMessage().replace("%arena%", arena.getName()).replace("%type%", kitType.toString()));
return;
}
@Command(name = "arena.tp", permission = "practice.command.arena", inGameOnly = true)
public void arenaTp(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
player.teleport(arena.getL1());
return;
}
}

View File

@ -0,0 +1,36 @@
package me.abhi.practice.command.impl.management.arena.hcf;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.arena.Arena;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class SetCapZoneCommand {
private final PracticePlugin plugin;
@Command(name = "setcapzone", permission = "practice.command.setcapzone", inGameOnly = true)
public void setCapZone(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Arena arena = this.plugin.getManagerHandler().getArenaManager().getArena(name);
if (arena == null) {
args.getSender().sendMessage(Messages.ARENA_DOESNT_EXIST.getMessage());
return;
}
if (arena.getKitType() != KitType.HCF) {
args.getSender().sendMessage(Messages.NOT_HCF_ARENA.getMessage());
return;
}
/* Will end up adding koths eventually */
}
}

View File

@ -0,0 +1,332 @@
package me.abhi.practice.command.impl.management.kit;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class KitCommand {
private final PracticePlugin plugin;
@Command(name = "kit", permission = "practice.command.kit", inGameOnly = true)
public void kit(CommandArgs args) {
args.getSender().sendMessage(new String[]{
CC.GRAY + "" + CC.STRIKE + "--------------------------------------------",
CC.GOLD + "" + CC.BOLD + "Kit Commands:",
CC.GRAY + " * " + CC.YELLOW + "/kit create <name> - Create a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit delete <name> - Delete a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setDisplay <name> - Set display icon of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setKit <name> - Set inventory of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setEditChest <name> <editChest> - Set edit chest value of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setEditInv <name> - Set edit inventory a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setType <name> <type> - Set type of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setDamageTicks <name> <ticks> - Set damage ticks of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setRanked <name> <ranked> - Set ranked value of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setUnranked <name> <unranked> - Set unranked value of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit setEditable <name> <editable> - Set editable value of a kit",
CC.GRAY + " * " + CC.YELLOW + "/kit loadKit <name> - Load the inventory of a kit",
CC.GRAY + "" + CC.STRIKE + "--------------------------------------------"
});
}
@Command(name = "kit.create", permission = "practice.command.kit", inGameOnly = true)
public void kitCreate(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (name.equalsIgnoreCase("hcf")) {
args.getSender().sendMessage(CC.RED + "This kit name is reserved.");
return;
}
if (kit != null) {
args.getSender().sendMessage(Messages.KIT_ALREADY_EXISTS.getMessage());
return;
}
this.plugin.getManagerHandler().getKitManager().addKit(new Kit(name));
this.plugin.getManagerHandler().getMongoManager().getMongoDatabase().createCollection(name);
args.getSender().sendMessage(Messages.KIT_CREATED.getMessage().replace("%kit%", name));
return;
}
@Command(name = "kit.delete", permission = "practice.command.kit", inGameOnly = true)
public void kitDelete(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
this.plugin.getManagerHandler().getKitManager().removeKit(kit);
this.plugin.getManagerHandler().getMongoManager().getMongoDatabase().getCollection(kit.getName()).drop();
args.getSender().sendMessage(Messages.KIT_DELETED.getMessage().replace("%kit%", kit.getName()));
return;
}
@Command(name = "kit.setdisplay", permission = "practice.command.kit", inGameOnly = true)
public void kitSetDisplay(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
if (player.getItemInHand().getType() == Material.AIR) {
args.getSender().sendMessage(Messages.HAND_CANT_BE_AIR.getMessage());
return;
}
kit.setDisplay(player.getItemInHand());
args.getSender().sendMessage(Messages.KIT_DISPLAY_SET.getMessage().replace("%kit%", kit.getName()));
return;
}
@Command(name = "kit.setkit", permission = "practice.command.kit", inGameOnly = true)
public void kitSetKit(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
kit.setInventory(InventoryUtil.cloneInventory(player.getInventory()));
kit.setArmor(InventoryUtil.cloneArmor(player.getInventory().getArmorContents()));
args.getSender().sendMessage(Messages.KIT_INVENTORY_SET.getMessage().replace("%kit%", kit.getName()));
return;
}
@Command(name = "kit.seteditchest", permission = "practice.command.kit", inGameOnly = true)
public void kitSetEditChest(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <true:false>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
try {
boolean value = Boolean.parseBoolean(args.getArgs(1));
kit.setEditChest(value);
args.getSender().sendMessage(Messages.KIT_EDITCHEST_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%value%", String.valueOf(value)));
} catch (Exception ex) {
args.getSender().sendMessage(CC.RED + "Invalid value.");
}
return;
}
@Command(name = "kit.seteditinv", permission = "practice.command.kit", inGameOnly = true)
public void kitSetEditInv(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setEditInv(kit);
if (kit.getEditInventory() == null)
kit.setEditInventory(this.plugin.getServer().createInventory(null, 54, kit.getName()));
player.openInventory(kit.getEditInventory());
return;
}
@Command(name = "kit.settype", permission = "practice.command.kit", inGameOnly = true)
public void kitSetType(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <type>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
KitType kitType = KitType.getType(args.getArgs(1));
if (kitType == null) {
args.getSender().sendMessage(Messages.KIT_TYPE_DOESNT_EXIST.getMessage());
return;
}
if (kitType == KitType.HCF) {
args.getSender().sendMessage(CC.RED + "This type of kit is reserved.");
return;
}
kit.setKitType(kitType);
args.getSender().sendMessage(Messages.KIT_TYPE_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%type%", kitType.toString()));
return;
}
@Command(name = "kit.setdamageticks", permission = "practice.command.kit", inGameOnly = true)
public void kitSetDamageTicks(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <ticks>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
if (!NumberUtils.isDigits(args.getArgs(1))) {
args.getSender().sendMessage(CC.RED + "Invalid amount.");
return;
}
int ticks = Integer.parseInt(args.getArgs(1));
if (ticks < 0 || ticks > 20) {
args.getSender().sendMessage(CC.RED + "Please enter a valid amount between 0 and 20.");
return;
}
kit.setDamageTicks(ticks);
args.getSender().sendMessage(Messages.KIT_TICKS_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%ticks%", String.valueOf(ticks)));
return;
}
@Command(name = "kit.setranked", permission = "practice.command.kit", inGameOnly = true)
public void kitSetRanked(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <true:false>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
try {
boolean value = Boolean.parseBoolean(args.getArgs(1));
kit.setRanked(value);
args.getSender().sendMessage(Messages.KIT_RANKED_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%value%", String.valueOf(value)));
} catch (Exception ex) {
args.getSender().sendMessage(CC.RED + "Invalid value.");
}
return;
}
@Command(name = "kit.setunranked", permission = "practice.command.kit", inGameOnly = true)
public void kitSetUnranked(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <true:false>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
try {
boolean value = Boolean.parseBoolean(args.getArgs(1));
kit.setUnranked(value);
args.getSender().sendMessage(Messages.KIT_UNRANKED_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%value%", String.valueOf(value)));
} catch (Exception ex) {
args.getSender().sendMessage(CC.RED + "Invalid value.");
}
return;
}
@Command(name = "kit.seteditable", permission = "practice.command.kit", inGameOnly = true)
public void kitSetEditable(CommandArgs args) {
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name> <true:false>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
try {
boolean value = Boolean.parseBoolean(args.getArgs(1));
kit.setEditable(value);
args.getSender().sendMessage(Messages.KIT_EDITABLE_UPDATED.getMessage().replace("%kit%", kit.getName()).replace("%value%", String.valueOf(value)));
} catch (Exception ex) {
args.getSender().sendMessage(CC.RED + "Invalid value.");
}
return;
}
@Command(name = "kit.loadkit", permission = "practice.command.kit", inGameOnly = true)
public void kitLoadKit(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <name>");
return;
}
String name = args.getArgs(0);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(name);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
if (kit.getInventory() == null || kit.getArmor() == null) {
args.getSender().sendMessage(Messages.KIT_NOT_SET.getMessage());
return;
}
Player player = args.getPlayer();
player.getInventory().setContents(kit.getInventory().getContents());
player.getInventory().setArmorContents(kit.getArmor());
player.updateInventory();
args.getSender().sendMessage(Messages.LOADED_KIT.getMessage().replace("%kit%", kit.getName()));
return;
}
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.command.impl.management.kit.hcf;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class SetArcherKitCommand {
@Command(name = "setarcherkit", permission = "practice.command.setarcherkit", inGameOnly = true)
public void setArcherKit(CommandArgs args) {
Player player = args.getPlayer();
HCFKit.ARCHER.setInventory(InventoryUtil.cloneInventory(player.getInventory()));
HCFKit.ARCHER.setArmor(InventoryUtil.cloneArmor(player.getInventory().getArmorContents()));
args.getSender().sendMessage(Messages.ARCHER_KIT_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.command.impl.management.kit.hcf;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class SetBardKitCommand {
@Command(name = "setbardkit", permission = "practice.command.setbardkit", inGameOnly = true)
public void setBardKit(CommandArgs args) {
Player player = args.getPlayer();
HCFKit.BARD.setInventory(InventoryUtil.cloneInventory(player.getInventory()));
HCFKit.BARD.setArmor(InventoryUtil.cloneArmor(player.getInventory().getArmorContents()));
args.getSender().sendMessage(Messages.BARD_KIT_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.command.impl.management.kit.hcf;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class SetDiamondKitCommand {
@Command(name = "setdiamondkit", permission = "practice.command.setdiamondkit", inGameOnly = true)
public void setDiamondKit(CommandArgs args) {
Player player = args.getPlayer();
HCFKit.DIAMOND.setInventory(InventoryUtil.cloneInventory(player.getInventory()));
HCFKit.DIAMOND.setArmor(InventoryUtil.cloneArmor(player.getInventory().getArmorContents()));
args.getSender().sendMessage(Messages.DIAMOND_KIT_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.command.impl.management.kit.hcf;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class SetRogueKitCommand {
@Command(name = "setroguekit", permission = "practice.command.setroguekit", inGameOnly = true)
public void setRogueKit(CommandArgs args) {
Player player = args.getPlayer();
HCFKit.ROGUE.setInventory(InventoryUtil.cloneInventory(player.getInventory()));
HCFKit.ROGUE.setArmor(InventoryUtil.cloneArmor(player.getInventory().getArmorContents()));
args.getSender().sendMessage(Messages.ROGUE_KIT_SET.getMessage());
return;
}
}

View File

@ -0,0 +1,111 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.match.Match;
import me.abhi.practice.match.MatchRequest;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.ListUtil;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.bukkit.entity.Player;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class AcceptCommand {
private final PracticePlugin plugin;
@Command(name = "accept", inGameOnly = true)
public void accept(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY && practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
if (target == player) {
args.getSender().sendMessage(Messages.CANT_DUEL_YOURSELF.getMessage());
return;
}
PracticeProfile targetProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(target);
if (practiceProfile.getPlayerState() == PlayerState.PARTY) {
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
if (party.getPartyState() != PartyState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
if (targetProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_PARTY.getMessage().replace("%player%", target.getName()));
return;
}
Party targetParty = targetProfile.getParty();
if (targetParty.getPartyState() != PartyState.LOBBY) {
args.getSender().sendMessage(Messages.PARTY_NOT_IN_LOBBY.getMessage());
return;
}
MatchRequest matchRequest = party.getMatchRequestList().stream().filter(m -> m.isParty() && targetParty.getMembers().contains(m.getRequester()) && System.currentTimeMillis() - m.getTimestamp() <= 60000).findFirst().orElse(null);
if (matchRequest == null) {
args.getSender().sendMessage(Messages.DUEL_REQUEST_NOT_FOUND.getMessage());
return;
}
party.getMatchRequestList().remove(matchRequest);
Match match = new Match(this.plugin, matchRequest.getKit(), party.getMembers(), targetParty.getMembers(), false, false);
match.start();
party.setMatch(match);
party.setPartyState(PartyState.MATCH);
targetParty.setMatch(match);
targetParty.setPartyState(PartyState.MATCH);
return;
}
if (targetProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_LOBBY.getMessage().replace("%player%", target.getName()));
return;
}
MatchRequest matchRequest = practiceProfile.getMatchRequestList().stream().filter(m -> !m.isParty() && m.getRequester() == target.getUniqueId() && System.currentTimeMillis() - m.getTimestamp() <= 60000).findFirst().orElse(null);
if (matchRequest == null) {
args.getSender().sendMessage(Messages.DUEL_REQUEST_NOT_FOUND.getMessage());
return;
}
practiceProfile.getMatchRequestList().remove(matchRequest);
Match match = new Match(this.plugin, matchRequest.getKit(), ListUtil.newList(player.getUniqueId()), ListUtil.newList(target.getUniqueId()), false, false);
match.start();
practiceProfile.setMatch(match);
practiceProfile.setPlayerState(PlayerState.MATCH);
match.getKit().getUnrankedMatch().add(player.getUniqueId());
targetProfile.setMatch(match);
targetProfile.setPlayerState(PlayerState.MATCH);
match.getKit().getUnrankedMatch().add(target.getUniqueId());
return;
}
}

View File

@ -0,0 +1,103 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.match.MatchRequest;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Menus;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.bukkit.entity.Player;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class DuelCommand {
private final PracticePlugin plugin;
@Command(name = "duel", aliases = {"1v1"}, inGameOnly = true)
public void duel(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY && practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
if (target == player) {
args.getSender().sendMessage(Messages.CANT_DUEL_YOURSELF.getMessage());
return;
}
PracticeProfile targetProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(target);
if (targetProfile.getPlayerState() != PlayerState.LOBBY && targetProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.PARTY_NOT_IN_LOBBY.getMessage());
return;
}
if (practiceProfile.getPlayerState() == PlayerState.PARTY) {
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
if (targetProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_PARTY.getMessage().replace("%player%", target.getName()));
return;
}
if (party.getMembers().contains(target.getUniqueId())) {
args.getSender().sendMessage(Messages.CANT_DUEL_YOURSELF.getMessage());
return;
}
Party targetParty = targetProfile.getParty();
if (targetParty.getPartyState() != PartyState.LOBBY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_LOBBY.getMessage().replace("%player%", target.getName()));
return;
}
MatchRequest matchRequest = targetParty.getMatchRequestList().stream().filter(m -> m.isParty() && party.getLeader() == m.getRequester() && System.currentTimeMillis() - m.getTimestamp() <= 60000).findFirst().orElse(null);
if (matchRequest != null) {
args.getSender().sendMessage(Messages.DUEL_REQUEST_EXISTS.getMessage());
return;
}
party.setDueling(targetParty);
this.plugin.getManagerHandler().getPlayerManager().openPartyDuel(player);
return;
}
if (targetProfile.getPlayerState() == PlayerState.PARTY) {
args.getSender().sendMessage(Messages.MUST_CREATE_PARTY_TO_DUEL.getMessage().replace("%player%", target.getName()));
return;
}
if (targetProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_LOBBY.getMessage().replace("%player%", target.getName()));
return;
}
if (!targetProfile.isDuelRequests()) {
args.getSender().sendMessage(Messages.PLAYER_DISABLED_DUELS.getMessage().replace("%player%", player.getName()));
return;
}
MatchRequest matchRequest = targetProfile.getMatchRequestList().stream().filter(m -> !m.isParty() && player.getUniqueId() == m.getRequester() && System.currentTimeMillis() - m.getTimestamp() <= 60000).findFirst().orElse(null);
if (matchRequest != null) {
args.getSender().sendMessage(Messages.DUEL_REQUEST_EXISTS.getMessage());
return;
}
practiceProfile.setDueling(target);
player.openInventory(Menus.DUEL.getInventory());
return;
}
}

View File

@ -0,0 +1,38 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import me.abhi.practice.util.misc.InventorySnapshot;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class InventoryCommand {
private final PracticePlugin plugin;
@Command(name = "inventory", aliases = {"inv"}, inGameOnly = true)
public void inventory(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
OfflinePlayer target = this.plugin.getServer().getOfflinePlayer(args.getArgs(0));
if (InventorySnapshot.getByUUID(target.getUniqueId()) == null) {
args.getSender().sendMessage(Messages.INVENTORY_NOT_FOUND.getMessage());
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
player.openInventory(InventorySnapshot.getByUUID(target.getUniqueId()).getInventory());
practiceProfile.setViewingPlayerInv(true);
return;
}
}

View File

@ -0,0 +1,97 @@
package me.abhi.practice.command.impl.player;
import com.mongodb.client.MongoCursor;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.player.LeaderboardPlayer;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Menus;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.apache.commons.lang.math.NumberUtils;
import org.bson.Document;
import org.bukkit.entity.Player;
import java.util.*;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class LeaderboardsCommand {
private final PracticePlugin plugin;
@Command(name = "leaderboards", aliases = {"lbs"}, inGameOnly = true)
public void leaderboards(CommandArgs args) {
if (this.plugin.getManagerHandler().getSettingsManager().isLeaderboardsGUI()) {
Player player = args.getPlayer();
player.openInventory(Menus.LEADERBOARDS.getInventory());
return;
}
if (args.length() != 2) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <kit> <page>");
return;
}
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(args.getArgs(0));
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
if (!kit.isRanked()) {
args.getSender().sendMessage(Messages.KIT_ISNT_RANKED.getMessage());
return;
}
if (!NumberUtils.isDigits(args.getArgs(1))) {
args.getSender().sendMessage(Messages.INVALID_PAGE_NUMBER.getMessage());
return;
}
int page = Integer.parseInt(args.getArgs(1));
List<LeaderboardPlayer> leaderboardPlayers = new ArrayList<>();
this.plugin.getServer().getOnlinePlayers().forEach(p -> {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(p);
leaderboardPlayers.add(new LeaderboardPlayer(p.getName(), practiceProfile.getElo(kit)));
});
MongoCursor<Document> practiceDocuments = this.plugin.getManagerHandler().getMongoManager().getMongoDatabase().getCollection(kit.getName()).find().iterator();
while (practiceDocuments.hasNext()) {
Document playerDocument = practiceDocuments.next();
UUID uuid = UUID.fromString(playerDocument.getString("uuid"));
if (this.plugin.getServer().getPlayer(uuid) == null) {
String username = playerDocument.getString("username");
int elo = playerDocument.getInteger("elo");
leaderboardPlayers.add(new LeaderboardPlayer(username, elo));
}
}
int start = (page * 10) - 10;
int end = (page * 10) - 1;
if (leaderboardPlayers.size() < start) {
args.getSender().sendMessage(Messages.LEADERBOARDS_PAGE_DOESNT_EXIST.getMessage());
return;
}
leaderboardPlayers.sort(Comparator.comparing(LeaderboardPlayer::getElo));
Collections.reverse(leaderboardPlayers);
args.getSender().sendMessage(Messages.LEADERBOARDS_HEADER.getMessage().replace("%kit%", kit.getName()).replace("%page%", String.valueOf(page)));
for (int i = start; i <= end; i++) {
if (i < leaderboardPlayers.size()) {
LeaderboardPlayer leaderboardPlayer = leaderboardPlayers.get(i);
args.getSender().sendMessage(Messages.LEADERBOARDS_PLAYER.getMessage().replace("%place%", String.valueOf(i + 1)).replace("%player%", leaderboardPlayer.getName()).replace("%elo%", String.valueOf(leaderboardPlayer.getElo())));
}
}
return;
}
}

View File

@ -0,0 +1,349 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.match.Match;
import me.abhi.practice.match.MatchDeathReason;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyInvite;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.craftbukkit.libs.joptsimple.internal.Strings;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class PartyCommand {
private final PracticePlugin plugin;
@Command(name = "party", aliases = {"p"}, inGameOnly = true)
public void party(CommandArgs args) {
args.getSender().sendMessage(Messages.PARTY_HELP.getMessage());
return;
}
@Command(name = "party.create", aliases = {"p.create"}, inGameOnly = true)
public void partyCreate(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Party party = new Party();
party.setLeader(player.getUniqueId());
party.getMembers().add(player.getUniqueId());
practiceProfile.setParty(party);
practiceProfile.setPlayerState(PlayerState.PARTY);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
args.getSender().sendMessage(Messages.CREATED_PARTY.getMessage());
return;
}
@Command(name = "party.invite", aliases = {"p.invite"}, inGameOnly = true)
public void partyInvite(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
if (party.getPartyState() != PartyState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
PracticeProfile targetProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(target);
if (targetProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_LOBBY.getMessage().replace("%player%", target.getName()));
return;
}
PartyInvite partyInvite = targetProfile.getPartyInviteList().stream().filter(p -> p.getParty() == party && System.currentTimeMillis() - p.getTimestamp() <= 60000).findFirst().orElse(null);
if (partyInvite != null) {
args.getSender().sendMessage(Messages.EXISTING_PARTY_INVITE.getMessage());
return;
}
if (party.getMembers().size() >= this.plugin.getManagerHandler().getSettingsManager().getMaxPartyMembers()) {
args.getSender().sendMessage(Messages.PARTY_FULL.getMessage());
return;
}
targetProfile.getPartyInviteList().add(new PartyInvite(party));
party.broadcast(Messages.PARTY_INVITE_SENT.getMessage().replace("%player%", target.getName()));
TextComponent clickable = new TextComponent(Messages.PARTY_INVITE.getMessage().replace("%player%", player.getName()).replace("%amount%", String.valueOf(party.getMembers().size())));
clickable.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Messages.PARTY_INVITE_HOVER.getMessage().replace("%player%", player.getName())).create()));
clickable.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party join " + player.getName()));
target.spigot().sendMessage(clickable);
return;
}
@Command(name = "party.join", aliases = {"p.join"}, inGameOnly = true)
public void partyJoin(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
PracticeProfile targetProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(target);
if (targetProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_PARTY.getMessage().replace("%player%", target.getName()));
return;
}
Party party = targetProfile.getParty();
if (party.getPartyState() != PartyState.LOBBY) {
args.getSender().sendMessage(Messages.PLAYERS_PARTY_NOT_IN_LOBBY.getMessage().replace("%player%", target.getName()));
return;
}
PartyInvite partyInvite = practiceProfile.getPartyInviteList().stream().filter(p -> p.getParty() == party && System.currentTimeMillis() - p.getTimestamp() <= 60000).findFirst().orElse(null);
if (partyInvite == null && !party.isOpen()) {
args.getSender().sendMessage(Messages.PARTY_INVITE_NOT_FOUND.getMessage());
return;
}
if (party.getMembers().size() >= this.plugin.getManagerHandler().getSettingsManager().getMaxPartyMembers()) {
args.getSender().sendMessage(Messages.PARTY_FULL.getMessage());
return;
}
practiceProfile.getPartyInviteList().remove(partyInvite);
practiceProfile.setParty(party);
party.getMembers().add(player.getUniqueId());
practiceProfile.setPlayerState(PlayerState.PARTY);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
party.broadcast(Messages.PLAYER_JOINED_PARTY.getMessage().replace("%player%", player.getName()));
return;
}
@Command(name = "party.leave", aliases = {"p.leave"}, inGameOnly = true)
public void partyLeave(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() == player.getUniqueId()) {
args.getSender().sendMessage(Messages.LEADER_CANT_LEAVE.getMessage());
return;
}
party.getMembers().remove(player.getUniqueId());
if (party.getPartyState() == PartyState.MATCH) {
Match match = party.getMatch();
match.getExempt().add(player.getUniqueId());
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
}
practiceProfile.setPlayerState(PlayerState.LOBBY);
practiceProfile.setParty(null);
practiceProfile.setHcfKit(HCFKit.DIAMOND);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
party.broadcast(Messages.PLAYER_LEFT_PARTY.getMessage().replace("%player%", player.getName()));
args.getSender().sendMessage(Messages.LEFT_PARTY.getMessage());
return;
}
@Command(name = "party.kick", aliases = {"p.kick"}, inGameOnly = true)
public void partyKick(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
if (!party.getMembers().contains(target.getUniqueId())) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_YOUR_PARTY.getMessage().replace("%player%", target.getName()));
return;
}
this.plugin.getServer().dispatchCommand(target, "party leave");
return;
}
@Command(name = "party.open", aliases = {"p.open"}, inGameOnly = true)
public void partyOpen(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
party.setOpen(!party.isOpen());
party.broadcast(party.isOpen() ? Messages.PARTY_OPENED.getMessage() : Messages.PARTY_CLOSED.getMessage());
return;
}
@Command(name = "party.promote", aliases = {"p.promote"}, inGameOnly = true)
public void partyPromote(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
if (!party.getMembers().contains(target.getUniqueId())) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_YOUR_PARTY.getMessage().replace("%player%", target.getName()));
return;
}
if (party.getLeader() == target.getUniqueId()) {
args.getSender().sendMessage(Messages.CANT_PROMOTE_YOURSELF.getMessage());
return;
}
party.setLeader(target.getUniqueId());
if (party.getPartyState() == PartyState.LOBBY) {
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getManagerHandler().getPlayerManager().giveItems(target, true);
}
party.broadcast(Messages.PLAYER_PROMOTED.getMessage().replace("%player%", target.getName()));
return;
}
@Command(name = "party.disband", aliases = {"p.disband"}, inGameOnly = true)
public void partyDisband(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
if (party.getLeader() != player.getUniqueId()) {
args.getSender().sendMessage(Messages.MUST_BE_PARTY_LEADER.getMessage());
return;
}
party.getMembers().stream().forEach(u -> {
Player member = this.plugin.getServer().getPlayer(u);
PracticeProfile memberProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(member);
if (party.getPartyState() == PartyState.MATCH) {
Match match = party.getMatch();
match.addDeath(member, MatchDeathReason.LEFT, null);
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
}
memberProfile.setPlayerState(PlayerState.LOBBY);
memberProfile.setParty(null);
memberProfile.setHcfKit(HCFKit.DIAMOND);
this.plugin.getManagerHandler().getPlayerManager().giveItems(member, true);
member.sendMessage(Messages.PARTY_DISBANDED.getMessage());
});
party.setPartyState(PartyState.LOBBY);
party.setMatch(null);
party.getMembers().clear();
return;
}
@Command(name = "party.info", aliases = {"p.info"}, inGameOnly = true)
public void partyInfo(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.NOT_IN_PARTY.getMessage());
return;
}
Party party = practiceProfile.getParty();
Player leader = this.plugin.getServer().getPlayer(party.getLeader());
List<String> playerNames = new ArrayList<>();
party.getMembers().stream().filter(u -> u != party.getLeader()).forEach(u -> playerNames.add(this.plugin.getServer().getPlayer(u).getName()));
args.getSender().sendMessage(Messages.PARTY_INFO.getMessage().replace("%leader%", leader.getName()).replace("%amount%", String.valueOf(party.getMembers().size() - 1)).replace("%members%", Strings.join(playerNames, ", ")).replace("%status%", party.isOpen() ? "Open" : "Closed"));
return;
}
}

View File

@ -0,0 +1,25 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Menus;
import org.bukkit.entity.Player;
/**
* @author 7x6
* @since 20/09/2019
*/
@AllArgsConstructor
public class SettingsCommand {
private final PracticePlugin plugin;
@Command(name = "settings", inGameOnly = true)
public void settings(CommandArgs args) {
Player player = args.getPlayer();
player.openInventory(Menus.SETTINGS.getInventory());
return;
}
}

View File

@ -0,0 +1,42 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class SpawnCommand {
private final PracticePlugin plugin;
@Command(name = "spawn", inGameOnly = true)
public void spawn(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY && practiceProfile.getPlayerState() != PlayerState.QUEUE && practiceProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.INVALID_STATE.getMessage());
return;
}
if (practiceProfile.getPlayerState() == PlayerState.PARTY) {
Party party = practiceProfile.getParty();
if (party.getPartyState() != PartyState.LOBBY && party.getPartyState() != PartyState.QUEUE) {
args.getSender().sendMessage(Messages.INVALID_STATE.getMessage());
return;
}
}
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
args.getSender().sendMessage(Messages.TELEPORTING_TO_SPAWN.getMessage());
return;
}
}

View File

@ -0,0 +1,93 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class SpectateCommand {
private PracticePlugin plugin;
@Command(name = "spectate", aliases = {"spec", "sp"}, inGameOnly = true)
public void spectate(CommandArgs args) {
if (args.length() != 1) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player>");
return;
}
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Player target = this.plugin.getServer().getPlayer(args.getArgs(0));
if (target == null) {
args.getSender().sendMessage(Messages.COULD_NOT_FIND_PLAYER.getMessage().replace("%player%", args.getArgs(0)));
return;
}
PracticeProfile targetProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(target);
if (targetProfile.getPlayerState() != PlayerState.MATCH && targetProfile.getPlayerState() != PlayerState.PARTY) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_MATCH.getMessage().replace("%player%", target.getName()));
return;
}
if (targetProfile.getPlayerState() == PlayerState.PARTY) {
Party party = targetProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
args.getSender().sendMessage(Messages.PLAYER_NOT_IN_MATCH.getMessage());
return;
}
Match match = party.getMatch();
practiceProfile.setPlayerState(PlayerState.SPECTATING);
practiceProfile.setSpectating(match);
match.getSpectators().add(player.getUniqueId());
player.teleport(target);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
match.getTeamOne().forEach(u -> player.showPlayer(this.plugin.getServer().getPlayer(u)));
match.getTeamTwo().forEach(u -> player.showPlayer(this.plugin.getServer().getPlayer(u)));
if (!practiceProfile.isSilentMode())
match.broadcast(Messages.PLAYER_NOW_SPECTATING.getMessage().replace("%player%", player.getName()));
player.setGameMode(GameMode.CREATIVE);
return;
}
Match match = targetProfile.getMatch();
practiceProfile.setPlayerState(PlayerState.SPECTATING);
practiceProfile.setSpectating(match);
match.getSpectators().add(player.getUniqueId());
player.teleport(target);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getManagerHandler().getPlayerManager().hideAll(player);
match.getTeamOne().forEach(u -> player.showPlayer(this.plugin.getServer().getPlayer(u)));
match.getTeamOne().forEach(u -> this.plugin.getServer().getPlayer(u).hidePlayer(player));
match.getTeamTwo().forEach(u -> player.showPlayer(this.plugin.getServer().getPlayer(u)));
match.getTeamTwo().forEach(u -> this.plugin.getServer().getPlayer(u).hidePlayer(player));
if (!practiceProfile.isSilentMode())
match.broadcast(Messages.PLAYER_NOW_SPECTATING.getMessage().replace("%player%", player.getName()));
player.setGameMode(GameMode.CREATIVE);
return;
}
}

View File

@ -0,0 +1,25 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class ToggleDuelRequestsCommand {
private final PracticePlugin plugin;
@Command(name = "toggleduelrequests", aliases = {"tdr", "toggledr"}, inGameOnly = true)
public void toggleDuelRequests(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setDuelRequests(!practiceProfile.isDuelRequests());
args.getSender().sendMessage(practiceProfile.isDuelRequests() ? Messages.DUEL_REQUEST_ENABLED.getMessage() : Messages.DUEL_REQUEST_DISABLED.getMessage());
return;
}
}

View File

@ -0,0 +1,26 @@
package me.abhi.practice.command.impl.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class ToggleScoreboardCommand {
private final PracticePlugin plugin;
@Command(name = "togglescoreboard", aliases = {"togglesidebar", "tsb", "togglesb"}, inGameOnly = true)
public void toggleScoreboard(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setScoreboard(!practiceProfile.isScoreboard());
args.getSender().sendMessage(practiceProfile.isScoreboard() ? Messages.SCOREBOARD_ENABLED.getMessage() : Messages.SCOREBOARD_DISABLED.getMessage());
return;
}
}

View File

@ -0,0 +1,18 @@
package me.abhi.practice.command.impl.player.time;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class DayCommand {
@Command(name = "day", inGameOnly = true)
public void day(CommandArgs args) {
Player player = args.getPlayer();
player.setPlayerTime(0L, false);
args.getSender().sendMessage(Messages.TIME_SET_DAY.getMessage());
return;
}
}

View File

@ -0,0 +1,18 @@
package me.abhi.practice.command.impl.player.time;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class NightCommand {
@Command(name = "night", inGameOnly = true)
public void night(CommandArgs args) {
Player player = args.getPlayer();
player.setPlayerTime(12000L, true);
args.getSender().sendMessage(Messages.TIME_SET_NIGHT.getMessage());
return;
}
}

View File

@ -0,0 +1,18 @@
package me.abhi.practice.command.impl.player.time;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
public class SunsetCommand {
@Command(name = "sunset", inGameOnly = true)
public void sunset(CommandArgs args) {
Player player = args.getPlayer();
player.setPlayerTime(6750L, false);
args.getSender().sendMessage(Messages.TIME_SET_SUNSET.getMessage());
return;
}
}

View File

@ -0,0 +1,75 @@
package me.abhi.practice.command.impl.staff;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import org.apache.commons.lang.math.NumberUtils;
import org.bson.Document;
import org.bukkit.OfflinePlayer;
import java.util.HashMap;
import java.util.Map;
@AllArgsConstructor
public class SetEloCommand {
private final PracticePlugin plugin;
@Command(name = "setelo", permission = "practice.command.setelo")
public void setElo(CommandArgs args) {
if (args.length() != 3) {
args.getSender().sendMessage(CC.RED + "Usage: /" + args.getLabel() + " <player> <kit> <elo>");
return;
}
OfflinePlayer offlinePlayer = this.plugin.getServer().getOfflinePlayer(args.getArgs(0));
if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) {
args.getSender().sendMessage(Messages.NEVER_PLAYED_BEFORE.getMessage().replace("%player%", args.getArgs(0)));
return;
}
String kitName = args.getArgs(1);
Kit kit = this.plugin.getManagerHandler().getKitManager().getKit(kitName);
if (kit == null) {
args.getSender().sendMessage(Messages.KIT_DOESNT_EXIST.getMessage());
return;
}
if (!kit.isRanked()) {
args.getSender().sendMessage(Messages.KIT_ISNT_RANKED.getMessage());
return;
}
if (!NumberUtils.isDigits(args.getArgs(2))) {
args.getSender().sendMessage(Messages.INVALID_AMOUNT.getMessage());
return;
}
int newElo = Integer.parseInt(args.getArgs(2));
if (newElo < this.plugin.getManagerHandler().getSettingsManager().getMinElo() || newElo > this.plugin.getManagerHandler().getSettingsManager().getMaxElo()) {
args.getSender().sendMessage(Messages.INVALID_ELO.getMessage());
return;
}
if (offlinePlayer.isOnline()) {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(offlinePlayer.getPlayer());
practiceProfile.setElo(kit, newElo);
} else {
MongoCollection mongoCollection = this.plugin.getManagerHandler().getMongoManager().getMongoDatabase().getCollection(kit.getName());
Map<String, Object> documentMap = new HashMap<>();
Document document = (Document) mongoCollection.find(Filters.eq("uuid", offlinePlayer.getUniqueId().toString())).first();
document.keySet().forEach(v -> documentMap.put(v, document.get(v)));
documentMap.put("elo", newElo);
if (document != null) mongoCollection.deleteOne(document);
mongoCollection.insertOne(new Document(documentMap));
}
args.getSender().sendMessage(Messages.SET_ELO.getMessage().replace("%player%", offlinePlayer.getName()).replace("%kit%", kit.getName()).replace("%elo%", String.valueOf(newElo)));
return;
}
}

View File

@ -0,0 +1,26 @@
package me.abhi.practice.command.impl.staff;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class SilentCommand {
private PracticePlugin plugin;
@Command(name = "silent", aliases = {"silentmode"}, permission = "practice.command.silent", inGameOnly = true)
public void silent(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setSilentMode(!practiceProfile.isSilentMode());
args.getSender().sendMessage(practiceProfile.isSilentMode() ? Messages.SILENT_ENABLED.getMessage() : Messages.SILENT_DISABLED.getMessage());
return;
}
}

View File

@ -0,0 +1,129 @@
package me.abhi.practice.command.impl.staff;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.command.Command;
import me.abhi.practice.command.CommandArgs;
import me.abhi.practice.match.Match;
import me.abhi.practice.match.MatchDeathReason;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.tournament.Tournament;
import me.abhi.practice.tournament.TournamentState;
import me.abhi.practice.util.enums.Menus;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
@AllArgsConstructor
public class TournamentCommand {
private final PracticePlugin plugin;
@Command(name = "tournament", aliases = {"tourny"}, permission = "practice.command.tournament", inGameOnly = true)
public void tournament(CommandArgs args) {
args.getSender().sendMessage(Messages.TOURNAMENT_HELP.getMessage());
return;
}
@Command(name = "tournament.start", aliases = {"tourny.start"}, permission = "practice.command.tournament", inGameOnly = true)
public void tournamentStart(CommandArgs args) {
if (this.plugin.getManagerHandler().getTournamentManager().getTournament() != null) {
args.getSender().sendMessage(Messages.TOURNAMENT_ALREADY_STARTED.getMessage());
return;
}
Player player = args.getPlayer();
player.openInventory(Menus.TOURNAMENT.getInventory());
return;
}
@Command(name = "tournament.stop", aliases = {"tourny.stop"}, permission = "practice.command.tournament", inGameOnly = true)
public void tournamentStop(CommandArgs args) {
Tournament tournament = this.plugin.getManagerHandler().getTournamentManager().getTournament();
if (tournament == null) {
args.getSender().sendMessage(Messages.NO_TOURNAMENT_STARTED.getMessage());
return;
}
tournament.end(null);
return;
}
@Command(name = "tournament.join", aliases = {"tourny.join"}, inGameOnly = true)
public void tournamentJoin(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.LOBBY) {
args.getSender().sendMessage(Messages.MUST_BE_IN_LOBBY.getMessage());
return;
}
Tournament tournament = this.plugin.getManagerHandler().getTournamentManager().getTournament();
if (tournament == null) {
args.getSender().sendMessage(Messages.NO_TOURNAMENT_STARTED.getMessage());
return;
}
if (tournament.getTournamentState() != TournamentState.STARTING) {
args.getSender().sendMessage(Messages.TOURNAMENT_ALREADY_STARTED.getMessage());
return;
}
if (tournament.getParticipants().size() >= this.plugin.getManagerHandler().getSettingsManager().getPlayersPerTournament() && !player.hasPermission("practice.tournament.bypass")) {
args.getSender().sendMessage(Messages.TOURNAMENT_FULL.getMessage());
return;
}
practiceProfile.setTournament(tournament);
practiceProfile.setPlayerState(PlayerState.TOURNAMENT);
tournament.getParticipants().add(player.getUniqueId());
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
tournament.broadcast(Messages.PLAYER_JOINED_TOURNAMENT.getMessage().replace("%player%", player.getName()).replace("%players%", String.valueOf(tournament.getParticipants().size())).replace("%max%", String.valueOf(this.plugin.getManagerHandler().getSettingsManager().getPlayersPerTournament())));
return;
}
@Command(name = "tournament.status", aliases = {"tourny.status"}, inGameOnly = true)
public void tournamentStatus(CommandArgs args) {
Tournament tournament = this.plugin.getManagerHandler().getTournamentManager().getTournament();
if (tournament == null) {
args.getSender().sendMessage(Messages.NO_TOURNAMENT_STARTED.getMessage());
return;
}
if (tournament.getTournamentState() != TournamentState.STARTED || tournament.getMatchList().size() == 0) {
args.getSender().sendMessage(Messages.TOURNAMENT_NO_FIGHTS.getMessage());
return;
}
args.getSender().sendMessage(Messages.TOURNAMENT_STATUS_HEADER.getMessage());
tournament.getMatchList().forEach(m -> args.getSender().sendMessage(Messages.TOURNAMENT_STATUS_MATCH.getMessage().replace("%player1%", m.getT1l().getName()).replace("%player2%", m.getT2l().getName())));
args.getSender().sendMessage(Messages.TOURNAMENT_STATUS_FOOTER.getMessage());
}
@Command(name = "tournament.leave", aliases = {"tourny.leave"}, inGameOnly = true)
public void tournamentLeave(CommandArgs args) {
Player player = args.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.TOURNAMENT && practiceProfile.getPlayerState() != PlayerState.MATCH) {
args.getSender().sendMessage(Messages.NOT_IN_TOURNAMENT.getMessage());
return;
}
if (practiceProfile.getPlayerState() == PlayerState.MATCH) {
Match match = practiceProfile.getMatch();
if (!match.isTournament()) {
args.getSender().sendMessage(Messages.NOT_IN_TOURNAMENT.getMessage());
return;
}
match.addDeath(player, MatchDeathReason.LEFT, null);
return;
}
Tournament tournament = this.plugin.getManagerHandler().getTournamentManager().getTournament();
tournament.getParticipants().remove(player.getUniqueId());
tournament.broadcast(Messages.PLAYER_LEFT_TOURNAMENT.getMessage().replace("%player%", player.getName()).replace("%players%", String.valueOf(tournament.getParticipants().size())).replace("%max%", String.valueOf(this.plugin.getManagerHandler().getSettingsManager().getPlayersPerTournament())));
practiceProfile.setPlayerState(PlayerState.LOBBY);
practiceProfile.setTournament(null);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
args.getSender().sendMessage(Messages.LEFT_TOURNAMENT.getMessage());
return;
}
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.event;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@Getter
public class BaseEvent extends Event {
@Getter
private static HandlerList handlerList = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlerList;
}
public void call() {
Bukkit.getPluginManager().callEvent(this);
}
}

View File

@ -0,0 +1,12 @@
package me.abhi.practice.event;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.entity.Player;
@Getter
@AllArgsConstructor
public class PlayerEvent extends BaseEvent {
private Player player;
}

View File

@ -0,0 +1,17 @@
package me.abhi.practice.event.impl;
import lombok.Getter;
import me.abhi.practice.event.PlayerEvent;
import me.abhi.practice.kit.hcf.data.bard.BardItem;
import org.bukkit.entity.Player;
@Getter
public class BardHoldItemEvent extends PlayerEvent {
private BardItem bardItem;
public BardHoldItemEvent(Player player, BardItem bardItem) {
super(player);
this.bardItem = bardItem;
}
}

View File

@ -0,0 +1,11 @@
package me.abhi.practice.event.impl;
import me.abhi.practice.event.PlayerEvent;
import org.bukkit.entity.Player;
public class BardTaskUpdateEvent extends PlayerEvent {
public BardTaskUpdateEvent(Player player) {
super(player);
}
}

View File

@ -0,0 +1,6 @@
package me.abhi.practice.hostedevent;
public enum EventState {
STARTING, STARTED
}

View File

@ -0,0 +1,56 @@
package me.abhi.practice.hostedevent;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Setter
@Getter
public class HostedEvent {
private String name;
private Location lobby;
private Location first;
private Location second;
private EventState eventState = EventState.STARTING;
private List<UUID> players = new ArrayList<>();
private List<UUID> spectators = new ArrayList<>();
private long startTime;
private long down;
public void startRound() {
}
public void eliminatePlayer(Player player) {
if (!getPlayers().contains(player.getUniqueId())) return;
getPlayers().remove(player.getUniqueId());
getSpectators().add(player.getUniqueId());
broadcast(Messages.EVENT_PLAYER_ELIMINATED.getMessage().replace("%player%", player.getName()));
}
public void end(String name, String winner) {
PracticePlugin.getInstance().getServer().broadcastMessage(winner != null ? Messages.EVENT_WINNER.getMessage().replace("%event%", name).replace("%player%", winner) : Messages.EVENT_CANCELLED.getMessage().replace("%event%", name));
}
public void broadcast(String message) {
getPlayers().forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).sendMessage(message));
getSpectators().forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).sendMessage(message));
}
public void playSound(Sound sound) {
getPlayers().forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).playSound(PracticePlugin.getInstance().getServer().getPlayer(u).getLocation(), sound, 20f, 20f));
getSpectators().forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).playSound(PracticePlugin.getInstance().getServer().getPlayer(u).getLocation(), sound, 20f, 20f));
}
}

View File

@ -0,0 +1,172 @@
package me.abhi.practice.hostedevent.impl;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.hostedevent.EventState;
import me.abhi.practice.hostedevent.HostedEvent;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@Getter
public class SumoEvent extends HostedEvent {
private Player p1;
private Player p2;
@Setter
private SumoState sumoState = SumoState.STARTING;
@Override
public String getName() {
return "Sumo";
}
@Override
public void startRound() {
if (!check()) {
sumoState = SumoState.STARTING;
Collections.shuffle(getPlayers());
p1 = PracticePlugin.getInstance().getServer().getPlayer(getPlayers().get(0));
p2 = PracticePlugin.getInstance().getServer().getPlayer(getPlayers().get(1));
broadcast(Messages.SUMO_EVENT_MATCHUP.getMessage().replace("%player1%", p1.getName()).replace("%player2%", p2.getName()));
p1.teleport(getFirst());
p2.teleport(getSecond());
p1.getInventory().clear();
p1.updateInventory();
p2.getInventory().clear();
p2.updateInventory();
new BukkitRunnable() {
int i = 5;
public void run() {
if (sumoState != SumoState.STARTING) {
this.cancel();
return;
}
if (i > 0) {
broadcast(Messages.SUMO_EVENT_MATCH_STARTING.getMessage().replace("%time%", String.valueOf(i)));
playSound(Sound.NOTE_STICKS);
i -= 1;
} else {
sumoState = SumoState.STARTED;
broadcast(Messages.SUMO_EVENT_MATCH_STARTED.getMessage());
playSound(Sound.NOTE_PLING);
this.cancel();
}
}
}.runTaskTimer(PracticePlugin.getInstance(), 20L, 20L);
}
}
@Override
public void eliminatePlayer(Player player) {
super.eliminatePlayer(player);
p1.teleport(getLobby());
p2.teleport(getLobby());
PracticeProfile practiceProfile = PracticePlugin.getInstance().getManagerHandler().getProfileManager().getProfile(player);
getSpectators().add(player.getUniqueId());
practiceProfile.setPlayerState(PlayerState.SPECTATING_EVENT);
player.setGameMode(GameMode.CREATIVE);
PracticePlugin.getInstance().getManagerHandler().getPlayerManager().giveItems(p1, false);
PracticePlugin.getInstance().getManagerHandler().getPlayerManager().giveItems(p2, false);
PracticePlugin.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(PracticePlugin.getInstance(), () -> {
getPlayers().forEach(u -> {
Player players = PracticePlugin.getInstance().getServer().getPlayer(u);
players.hidePlayer(player);
});
}, 1L);
p1 = p2 = null;
if (!check()) {
new BukkitRunnable() {
int i = 5;
public void run() {
if (i > 0) {
broadcast(Messages.SUMO_ROUND_STARTING.getMessage().replace("%time%", String.valueOf(i)));
playSound(Sound.NOTE_STICKS);
i -= 1;
} else {
startRound();
playSound(Sound.NOTE_PLING);
this.cancel();
}
}
}.runTaskTimer(PracticePlugin.getInstance(), 20L, 20L);
}
}
@Override
public void end(String name, String winner) {
super.end(name, winner);
List<UUID> allPlayers = new ArrayList<>();
getPlayers().forEach(allPlayers::add);
getSpectators().forEach(allPlayers::add);
allPlayers.forEach(u -> {
Player player = PracticePlugin.getInstance().getServer().getPlayer(u);
PracticeProfile practiceProfile = PracticePlugin.getInstance().getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setPlayerState(PlayerState.LOBBY);
practiceProfile.setHostedEvent(null);
PracticePlugin.getInstance().getManagerHandler().getPlayerManager().giveItems(player, true);
PracticePlugin.getInstance().getManagerHandler().getPlayerManager().teleportSpawn(player);
});
getPlayers().clear();
getSpectators().clear();
setDown(0);
setStartTime(0);
sumoState = SumoState.STARTING;
setEventState(EventState.STARTING);
PracticePlugin.getInstance().getManagerHandler().getEventManager().getCurrentEvents().remove(this);
p1 = p2 = null;
}
private boolean check() {
if (getPlayers().size() == 0) {
end(getName(), null);
return true;
} else if (getPlayers().size() == 1) {
end(getName(), PracticePlugin.getInstance().getServer().getPlayer(getPlayers().get(0)).getName());
return true;
}
return false;
}
public enum SumoState {
STARTING, STARTED
}
}

View File

@ -0,0 +1,19 @@
package me.abhi.practice.kit;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@Getter
@AllArgsConstructor
public class CustomKit {
private Inventory inventory;
private ItemStack[] armor;
private int number;
@Setter
private String name;
}

View File

@ -0,0 +1,35 @@
package me.abhi.practice.kit;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Getter
@Setter
@RequiredArgsConstructor
public class Kit {
private final String name;
private ItemStack display = new ItemStack(Material.IRON_SWORD);
private Inventory inventory;
private ItemStack[] armor;
private boolean editChest;
private Inventory editInventory;
private KitType kitType = KitType.NORMAL;
private int damageTicks = 19;
private boolean ranked;
private boolean unranked;
private boolean editable;
private List<UUID> unrankedQueue = new ArrayList<>();
private List<UUID> unrankedMatch = new ArrayList<>();
private List<UUID> rankedQueue = new ArrayList<>();
private List<UUID> rankedMatch = new ArrayList<>();
}

View File

@ -0,0 +1,12 @@
package me.abhi.practice.kit;
import java.util.Arrays;
public enum KitType {
NORMAL, SUMO, HCF;
public static KitType getType(String name) {
return Arrays.stream(values()).filter(t -> t.toString().equalsIgnoreCase(name)).findFirst().orElse(null);
}
}

View File

@ -0,0 +1,25 @@
package me.abhi.practice.kit.hcf;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@Getter
@AllArgsConstructor
public enum HCFKit {
DIAMOND("Diamond", null, null),
BARD("Bard", null, null),
ARCHER("Archer", null, null),
ROGUE("Rogue", null, null);
private String name;
@Setter
private Inventory inventory;
@Setter
private ItemStack[] armor;
}

View File

@ -0,0 +1,22 @@
package me.abhi.practice.kit.hcf.data.archer;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
@Getter
public class ArcherData {
private List<ArcherItem> archerItemList;
public ArcherData() {
archerItemList = new ArrayList<>();
archerItemList.add(new ArcherItem("Speed IV", Material.SUGAR, new PotionEffect(PotionEffectType.SPEED, 200, 3)));
archerItemList.add(new ArcherItem("Jumpboost V", Material.FEATHER, new PotionEffect(PotionEffectType.JUMP, 200, 4)));
}
}

View File

@ -0,0 +1,16 @@
package me.abhi.practice.kit.hcf.data.archer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
@Getter
@AllArgsConstructor
public class ArcherItem {
private String name;
private Material material;
private PotionEffect activated;
}

View File

@ -0,0 +1,33 @@
package me.abhi.practice.kit.hcf.data.bard;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
@Getter
public class BardData {
private List<BardItem> bardItemList;
private List<PotionEffectType> blockedList;
public BardData() {
bardItemList = new ArrayList<>();
bardItemList.add(new BardItem("Speed III", Material.SUGAR, 35, new PotionEffect(PotionEffectType.SPEED, 120, 1), new PotionEffect(PotionEffectType.SPEED, 120, 2), true));
bardItemList.add(new BardItem("Resistance III", Material.IRON_INGOT, 50, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 0), new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 2), true));
bardItemList.add(new BardItem("Jumpboost VII", Material.FEATHER, 40, new PotionEffect(PotionEffectType.JUMP, 120, 1), new PotionEffect(PotionEffectType.JUMP, 120, 6), true));
bardItemList.add(new BardItem("Strength II", Material.BLAZE_POWDER, 50, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 120, 0), new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 120, 1), false));
bardItemList.add(new BardItem("Regen IV", Material.GHAST_TEAR, 50, new PotionEffect(PotionEffectType.REGENERATION, 120, 0), new PotionEffect(PotionEffectType.REGENERATION, 100, 3), true));
bardItemList.add(new BardItem("Fire Resistance", Material.MAGMA_CREAM, 40, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 120, 0), new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 400, 0), true));
blockedList = new ArrayList<>();
blockedList.add(PotionEffectType.FIRE_RESISTANCE);
blockedList.add(PotionEffectType.INCREASE_DAMAGE);
blockedList.add(PotionEffectType.JUMP);
}
}

View File

@ -0,0 +1,19 @@
package me.abhi.practice.kit.hcf.data.bard;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
@Getter
@AllArgsConstructor
public class BardItem {
private String name;
private Material material;
private double energy;
private PotionEffect held;
private PotionEffect activated;
private boolean bard;
}

View File

@ -0,0 +1,23 @@
package me.abhi.practice.kit.hcf.data.rogue;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
@Getter
public class RogueData {
private List<RogueItem> rogueItemList;
public RogueData() {
rogueItemList = new ArrayList<>();
rogueItemList.add(new RogueItem("Speed IV", Material.SUGAR, new PotionEffect(PotionEffectType.SPEED, 200, 3)));
rogueItemList.add(new RogueItem("Jumpboost V", Material.FEATHER, new PotionEffect(PotionEffectType.JUMP, 200, 4)));
}
}

View File

@ -0,0 +1,16 @@
package me.abhi.practice.kit.hcf.data.rogue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
@Getter
@AllArgsConstructor
public class RogueItem {
private String name;
private Material material;
private PotionEffect activated;
}

View File

@ -0,0 +1,107 @@
package me.abhi.practice.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.player.PracticeProfile;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
@SuppressWarnings("Duplicates")
public class PacketListener implements Listener {
private final PracticePlugin instance;
public PacketListener(PracticePlugin instance) {
this.instance = instance;
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(instance, PacketType.Play.Client.CLIENT_COMMAND) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
PracticeProfile practiceProfile = instance.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setOpenInventory(true);
}
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(instance, PacketType.Play.Server.NAMED_SOUND_EFFECT) {
@Override
public void onPacketSending(PacketEvent event) { // took this from joel
Player player = event.getPlayer();
PacketContainer packet = event.getPacket();
String name = packet.getStrings().read(0);
if (name.contains("random") || name.contains("hurt") || name.startsWith("note") || name.contains("random.successful_hit") || name.contains("weather")) {
event.setCancelled(false);
return;
}
Location soundLocation = new Location(player.getWorld(), packet.getIntegers().read(0) / 8.0, packet.getIntegers().read(1) / 8.0, packet.getIntegers().read(2) / 8.0);
Player closest = null;
double bestDistance = Double.MAX_VALUE;
for (Player p : player.getWorld().getPlayers()) {
if (p.getLocation().distance(soundLocation) < bestDistance) {
bestDistance = p.getLocation().distance(soundLocation);
closest = p;
}
}
if (closest != null) {
event.setCancelled(player.canSee(closest));
}
}
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(instance, PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
// if (!instance.getManagerHandler().getSettingsManager().isHideInvisiblesInTab()) {
event.setCancelled(false);
// }
}
});
}
@EventHandler
public void onPotionSplash(PotionSplashEvent potionSplashEvent) {
if (potionSplashEvent.getEntity().getShooter() instanceof Player) {
Player shooter = (Player) potionSplashEvent.getEntity().getShooter();
com.comphenix.protocol.events.PacketListener particleListener = new PacketAdapter(instance, PacketType.Play.Server.WORLD_EVENT) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
event.setCancelled(!player.canSee(shooter));
}
};
ProtocolLibrary.getProtocolManager().addPacketListener(particleListener);
instance.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> {
ProtocolLibrary.getProtocolManager().removePacketListener(particleListener);
}, 20L);
}
}
@EventHandler
public void onLaunch(ProjectileLaunchEvent projectileLaunchEvent) {
if (projectileLaunchEvent.getEntity().getShooter() instanceof Player) {
Player shooter = (Player) projectileLaunchEvent.getEntity().getShooter();
instance.getServer().getOnlinePlayers().stream().filter(p -> p != shooter && !p.canSee(shooter)).forEach(p -> {
instance.getEntityHider().hideEntity(p, projectileLaunchEvent.getEntity());
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,139 @@
package me.abhi.practice.listener.hcf;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.kit.hcf.data.archer.ArcherData;
import me.abhi.practice.kit.hcf.data.archer.ArcherItem;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("Duplicates")
@RequiredArgsConstructor
public class ArcherListener implements Listener {
private final PracticePlugin plugin;
private ArcherData archerData = new ArcherData();
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
return;
}
Party party = practiceProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
return;
}
Match match = party.getMatch();
if (match.getKit() != null || practiceProfile.getHcfKit() != HCFKit.ARCHER) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
ArcherItem archerItem = archerData.getArcherItemList().stream().filter(a -> a.getMaterial() == player.getItemInHand().getType()).findFirst().orElse(null);
if (archerItem == null) {
return;
}
if (System.currentTimeMillis() - (archerItem.getActivated().getType() == PotionEffectType.SPEED ? practiceProfile.getLastArcherSpeedBuff() : practiceProfile.getLastArcherJumpBuff()) <= 60000) {
event.setCancelled(true);
long timeLeft = 60 - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - (archerItem.getActivated().getType() == PotionEffectType.SPEED ? practiceProfile.getLastArcherSpeedBuff() : practiceProfile.getLastArcherJumpBuff()));
player.sendMessage(Messages.MUST_WAIT_TO_ARCHER_BUFF.getMessage().replace("%time%", String.valueOf(timeLeft)));
return;
}
player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
player.updateInventory();
if (archerItem.getActivated().getType() == PotionEffectType.SPEED) {
practiceProfile.setLastArcherSpeedBuff(System.currentTimeMillis());
} else {
practiceProfile.setLastArcherJumpBuff(System.currentTimeMillis());
}
player.removePotionEffect(archerItem.getActivated().getType());
player.addPotionEffect(archerItem.getActivated());
player.sendMessage(Messages.ACTIVATED_ARCHER_BUFF.getMessage().replace("%buff%", archerItem.getName()));
if (archerItem.getActivated().getType() == PotionEffectType.SPEED) {
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
if (party.getPartyState() != PartyState.MATCH || party.getMatch() != match || !player.isOnline() || practiceProfile.getHcfKit() != HCFKit.ARCHER) {
return;
}
player.removePotionEffect(PotionEffectType.SPEED);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
}, 195L);
}
return;
}
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntity() instanceof Player) {
Player attacked = (Player) event.getEntity();
PracticeProfile attackedProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(attacked);
if (System.currentTimeMillis() - attackedProfile.getLastArcherMark() <= 15000) {
event.setDamage(event.getDamage() * 1.3);
}
if (event.getDamager() instanceof Arrow) {
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getShooter() instanceof Player) {
Player damager = (Player) arrow.getShooter();
PracticeProfile damagerProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(damager);
if (damagerProfile.getPlayerState() != PlayerState.PARTY) {
return;
}
Party party = damagerProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
return;
}
Match match = party.getMatch();
if (match.getKit() != null || damagerProfile.getHcfKit() != HCFKit.ARCHER) {
return;
}
if (attackedProfile.getLastArcherMark() == 0) {
attacked.sendMessage(Messages.ARCHER_TAGGED.getMessage());
damager.sendMessage(Messages.PLAYER_ARCHER_TAGGED.getMessage().replace("%player%", attacked.getName()));
}
attackedProfile.setLastArcherMark(System.currentTimeMillis());
}
}
}
}
}

View File

@ -0,0 +1,163 @@
package me.abhi.practice.listener.hcf;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.event.impl.BardHoldItemEvent;
import me.abhi.practice.event.impl.BardTaskUpdateEvent;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.kit.hcf.data.bard.BardData;
import me.abhi.practice.kit.hcf.data.bard.BardItem;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("Duplicates")
@RequiredArgsConstructor
public class BardListener implements Listener {
private final PracticePlugin plugin;
private BardData bardData = new BardData();
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
return;
}
Party party = practiceProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
return;
}
Match match = party.getMatch();
if (match.getKit() != null || practiceProfile.getHcfKit() != HCFKit.BARD) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
BardItem bardItem = bardData.getBardItemList().stream().filter(b -> b.getMaterial() == player.getItemInHand().getType()).findFirst().orElse(null);
if (bardItem == null) {
return;
}
if (practiceProfile.getBardEnergy() < bardItem.getEnergy()) {
event.setCancelled(true);
player.sendMessage(Messages.NEED_MORE_ENERGY.getMessage().replace("%energy%", String.valueOf(bardItem.getEnergy())));
return;
}
if (System.currentTimeMillis() - practiceProfile.getLastBardBuff() <= 6000) {
event.setCancelled(true);
long timeLeft = 6 - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - practiceProfile.getLastBardBuff());
player.sendMessage(Messages.MUST_WAIT_TO_BARD_BUFF.getMessage().replace("%time%", String.valueOf(timeLeft)));
return;
}
practiceProfile.setBardEnergy(practiceProfile.getBardEnergy() - bardItem.getEnergy());
practiceProfile.setLastBardBuff(System.currentTimeMillis());
player.sendMessage(Messages.ACTIVATED_BARD_BUFF.getMessage().replace("%buff%", bardItem.getName()));
party.getMembers().stream().filter(u -> !match.getDead().contains(u) && this.plugin.getServer().getPlayer(u).getLocation().distanceSquared(player.getLocation()) <= 400).forEach(u -> {
Player member = this.plugin.getServer().getPlayer(u);
if ((member == player && bardItem.isBard()) || member != player) {
member.removePotionEffect(bardItem.getHeld().getType());
member.addPotionEffect(bardItem.getActivated());
}
});
return;
}
}
@EventHandler
public void onBardHold(BardHoldItemEvent event) {
Player player = event.getPlayer();
BardItem bardItem = event.getBardItem();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
Party party = practiceProfile.getParty();
Match match = party.getMatch();
party.getMembers().stream().filter(u -> !match.getDead().contains(u) && this.plugin.getServer().getPlayer(u).getLocation().distanceSquared(player.getLocation()) <= 400).forEach(u -> {
Player member = this.plugin.getServer().getPlayer(u);
PracticeProfile memberProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(member);
if (this.plugin.getManagerHandler().getPlayerManager().getPotionEffect(member, bardItem.getHeld().getType()) != null) {
PotionEffect potionEffect = this.plugin.getManagerHandler().getPlayerManager().getPotionEffect(member, bardItem.getHeld().getType());
if (potionEffect.getDuration() > 140) {
memberProfile.getPotionEffectsList().add(potionEffect);
if ((member == player && bardItem.isBard() && bardItem.getHeld().getType() != PotionEffectType.DAMAGE_RESISTANCE && bardItem.getHeld().getType() != PotionEffectType.REGENERATION) || (member != player || potionEffect.getAmplifier() <= bardItem.getHeld().getAmplifier()))
member.removePotionEffect(bardItem.getHeld().getType());
}
}
if ((member == player && bardItem.isBard() && bardItem.getHeld().getType() != PotionEffectType.DAMAGE_RESISTANCE && bardItem.getHeld().getType() != PotionEffectType.REGENERATION) || member != player)
member.addPotionEffect(bardItem.getHeld());
});
}
@EventHandler
public void onBardTask(BardTaskUpdateEvent event) {
try {
Player player = event.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
Party party = practiceProfile.getParty();
Match match = party.getMatch();
party.getMembers().stream().filter(u -> !match.getDead().contains(u)).forEach(u -> {
Player member = this.plugin.getServer().getPlayer(u);
restoreEffects(member);
});
} catch (Exception ex) {
// remove random errors :D
}
}
private void restoreEffects(Player player) {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
for (PotionEffect potionEffect : practiceProfile.getPotionEffectsList()) {
if (bardData.getBlockedList().contains(potionEffect.getType())) {
practiceProfile.getPotionEffectsList().remove(potionEffect);
return;
}
if (!player.hasPotionEffect(potionEffect.getType())) removeType(player, potionEffect.getType());
player.addPotionEffect(potionEffect);
}
}
private void removeType(Player player, PotionEffectType potionEffectType) {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
for (int i = 0; i < practiceProfile.getPotionEffectsList().size(); i++) {
PotionEffect potionEffect = practiceProfile.getPotionEffectsList().get(i);
if (potionEffect.getType() == potionEffectType && potionEffect.getDuration() <= 100) {
practiceProfile.getPotionEffectsList().remove(potionEffect);
}
}
}
}

View File

@ -0,0 +1,149 @@
package me.abhi.practice.listener.hcf;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.kit.hcf.data.rogue.RogueData;
import me.abhi.practice.kit.hcf.data.rogue.RogueItem;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("Duplicates")
@RequiredArgsConstructor
public class RogueListener implements Listener {
private final PracticePlugin plugin;
private RogueData rogueData = new RogueData();
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
return;
}
Party party = practiceProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
return;
}
Match match = party.getMatch();
if (match.getKit() != null || practiceProfile.getHcfKit() != HCFKit.ROGUE) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
RogueItem rogueItem = rogueData.getRogueItemList().stream().filter(r -> r.getMaterial() == player.getItemInHand().getType()).findFirst().orElse(null);
if (rogueItem == null) {
return;
}
if (System.currentTimeMillis() - (rogueItem.getActivated().getType() == PotionEffectType.SPEED ? practiceProfile.getLastRogueSpeedBuff() : practiceProfile.getLastRogueJumpBuff()) <= 60000) {
event.setCancelled(true);
long timeLeft = 60 - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - (rogueItem.getActivated().getType() == PotionEffectType.SPEED ? practiceProfile.getLastRogueSpeedBuff() : practiceProfile.getLastRogueJumpBuff()));
player.sendMessage(Messages.MUST_WAIT_TO_ROGUE_BUFF.getMessage().replace("%time%", String.valueOf(timeLeft)));
return;
}
player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
player.updateInventory();
if (rogueItem.getActivated().getType() == PotionEffectType.SPEED) {
practiceProfile.setLastRogueSpeedBuff(System.currentTimeMillis());
} else {
practiceProfile.setLastRogueJumpBuff(System.currentTimeMillis());
}
player.removePotionEffect(rogueItem.getActivated().getType());
player.addPotionEffect(rogueItem.getActivated());
player.sendMessage(Messages.ACTIVATED_ROGUE_BUFF.getMessage().replace("%buff%", rogueItem.getName()));
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
if (party.getPartyState() != PartyState.MATCH || party.getMatch() != match || !player.isOnline() || practiceProfile.getHcfKit() != HCFKit.ROGUE) {
return;
}
player.removePotionEffect(rogueItem.getActivated().getType());
player.addPotionEffect(new PotionEffect(rogueItem.getActivated().getType(), Integer.MAX_VALUE, 2));
}, 195L);
}
return;
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player attacked = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
PracticeProfile damagerProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(damager);
if (damagerProfile.getPlayerState() != PlayerState.PARTY) {
return;
}
Party party = damagerProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
return;
}
Match match = party.getMatch();
if (match.getKit() != null || damagerProfile.getHcfKit() != HCFKit.ROGUE) {
return;
}
if (damager.getItemInHand().getType() != Material.GOLD_SWORD) {
return;
}
if (System.currentTimeMillis() - damagerProfile.getLastRogueBackstab() <= 6000) {
long timeLeft = 6 - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - damagerProfile.getLastRogueBackstab());
damager.sendMessage(Messages.MUST_WAIT_TO_BACKSTAB.getMessage().replace("%time%", String.valueOf(timeLeft)));
return;
}
damager.setItemInHand(new ItemStack(Material.AIR, 1));
damager.playSound(damager.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
attacked.playSound(damager.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
attacked.sendMessage(Messages.BACKSTABBED.getMessage().replace("%player%", damager.getName()));
damager.sendMessage(Messages.BACKSTABBED_PLAYER.getMessage().replace("%player%", attacked.getName()));
event.setDamage(0);
attacked.setHealth(attacked.getHealth() - 5);
damagerProfile.setLastRogueBackstab(System.currentTimeMillis());
damager.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 0));
damager.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 40, 0));
return;
}
}
}

View File

@ -0,0 +1,11 @@
package me.abhi.practice.manager;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class Manager {
public ManagerHandler managerHandler;
}

View File

@ -0,0 +1,41 @@
package me.abhi.practice.manager;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.manager.impl.*;
@Getter
@RequiredArgsConstructor
public class ManagerHandler {
private final PracticePlugin plugin;
private MongoManager mongoManager;
private SettingsManager settingsManager;
private ConfigurationManager configurationManager;
private ItemsManager itemsManager;
private PlayerManager playerManager;
private ProfileManager profileManager;
private KitManager kitManager;
private MenuManager menuManager;
private ScoreboardManager scoreboardManager;
private ArenaManager arenaManager;
private EventManager eventManager;
private TournamentManager tournamentManager;
public void register() {
mongoManager = new MongoManager(this);
settingsManager = new SettingsManager(this);
configurationManager = new ConfigurationManager(this);
itemsManager = new ItemsManager(this);
playerManager = new PlayerManager(this);
profileManager = new ProfileManager(this);
kitManager = new KitManager(this);
menuManager = new MenuManager(this);
scoreboardManager = new ScoreboardManager(this);
arenaManager = new ArenaManager(this);
eventManager = new EventManager(this);
tournamentManager = new TournamentManager(this);
}
}

View File

@ -0,0 +1,73 @@
package me.abhi.practice.manager.impl;
import me.abhi.practice.arena.Arena;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.LocationUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class ArenaManager extends Manager {
private List<Arena> arenasList;
public ArenaManager(ManagerHandler managerHandler) {
super(managerHandler);
arenasList = new ArrayList<>();
fetch();
}
private void fetch() {
if (managerHandler.getConfigurationManager().getArenasFile().getConfigurationSection("arenas") == null) {
return;
}
managerHandler.getConfigurationManager().getArenasFile().getConfigurationSection("arenas").getKeys(false).stream().forEach(a -> {
Arena arena = new Arena(a);
arena.setL1(LocationUtil.getLocationFromString(managerHandler.getConfigurationManager().getArenasFile().getString("arenas." + a + ".l1")));
arena.setL2(LocationUtil.getLocationFromString(managerHandler.getConfigurationManager().getArenasFile().getString("arenas." + a + ".l2")));
arena.setKitType(KitType.getType(managerHandler.getConfigurationManager().getArenasFile().getString("arenas." + a + ".type")));
addArena(arena);
});
}
public Arena getArena(String name) {
return arenasList.stream().filter(a -> a.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
public void addArena(Arena arena) {
arenasList.add(arena);
}
public void removeArena(Arena arena) {
arenasList.remove(arena);
}
public Arena randomArena(Kit kit) {
// Cleaned up to Java 8 Standards
List<Arena> compatible = arenasList.stream().filter(a -> a.getKitType() == kit.getKitType()).collect(Collectors.toList());
return compatible.get(new Random().nextInt(compatible.size()));
}
public Arena randomArena(KitType kitType) {
List<Arena> compatible = arenasList.stream().filter(a -> a.getKitType() == kitType).collect(Collectors.toList());
return compatible.get(new Random().nextInt(compatible.size()));
}
public void save() {
managerHandler.getConfigurationManager().getArenasFile().set("arenas", null);
arenasList.stream().forEach(a -> {
if (a.getL1() != null) managerHandler.getConfigurationManager().getArenasFile().set("arenas." + a.getName() + ".l1", LocationUtil.getStringFromLocation(a.getL1()));
if (a.getL2() != null) managerHandler.getConfigurationManager().getArenasFile().set("arenas." + a.getName() + ".l2", LocationUtil.getStringFromLocation(a.getL2()));
managerHandler.getConfigurationManager().getArenasFile().set("arenas." + a.getName() + ".type", a.getKitType().toString());
});
managerHandler.getConfigurationManager().saveArenasFile();
}
}

View File

@ -0,0 +1,98 @@
package me.abhi.practice.manager.impl;
import lombok.Getter;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.Logger;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Arrays;
@Getter
public class ConfigurationManager extends Manager {
private YamlConfiguration messagesFile;
private YamlConfiguration kitsFile;
private YamlConfiguration arenasFile;
private YamlConfiguration eventsFile;
public ConfigurationManager(ManagerHandler managerHandler) {
super(managerHandler);
createFiles();
}
private void createFiles() {
try {
File mFile = new File(managerHandler.getPlugin().getDataFolder(), "messages.yml");
if (!mFile.exists()) {
mFile.createNewFile();
Logger.success("Created messages.yml");
}
messagesFile = YamlConfiguration.loadConfiguration(mFile);
Arrays.stream(Messages.values()).filter(messages -> messagesFile.get(messages.getPath()) == null).forEach(messages -> messagesFile.set(messages.getPath(), messages.getDefaultMessage()));
saveMessagesFile();
File kFile = new File(managerHandler.getPlugin().getDataFolder(), "kits.yml");
if (!kFile.exists()) {
kFile.createNewFile();
Logger.success("Created kits.yml");
}
kitsFile = YamlConfiguration.loadConfiguration(kFile);
File aFile = new File(managerHandler.getPlugin().getDataFolder(), "arenas.yml");
if (!aFile.exists()) {
aFile.createNewFile();
Logger.success("Created arenas.yml");
}
arenasFile = YamlConfiguration.loadConfiguration(aFile);
File eFile = new File(managerHandler.getPlugin().getDataFolder(), "events.yml");
if (!eFile.exists()) {
eFile.createNewFile();
Logger.success("Created events.yml");
}
eventsFile = YamlConfiguration.loadConfiguration(eFile);
} catch (Exception ex) {
Logger.error("Error loading files.");
}
}
public void saveMessagesFile() {
try {
File mFile = new File(managerHandler.getPlugin().getDataFolder(), "messages.yml");
messagesFile.save(mFile);
} catch (Exception ex) {
Logger.error("Could not save messages.yml");
}
}
public void saveKitsFile() {
try {
File kFile = new File(managerHandler.getPlugin().getDataFolder(), "kits.yml");
kitsFile.save(kFile);
} catch (Exception ex) {
Logger.error("Could not save kits.yml");
}
}
public void saveArenasFile() {
try {
File aFile = new File(managerHandler.getPlugin().getDataFolder(), "arenas.yml");
arenasFile.save(aFile);
} catch (Exception ex) {
Logger.error("Could not save arenas.yml");
}
}
public void saveEventsFile() {
try {
File eFile = new File(managerHandler.getPlugin().getDataFolder(), "events.yml");
eventsFile.save(eFile);
} catch (Exception ex) {
Logger.error("Could not save event.yml");
}
}
}

View File

@ -0,0 +1,82 @@
package me.abhi.practice.manager.impl;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.hostedevent.HostedEvent;
import me.abhi.practice.hostedevent.impl.SumoEvent;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.LocationUtil;
import java.util.ArrayList;
import java.util.List;
@Setter
@Getter
public class EventManager extends Manager {
private List<HostedEvent> currentEvents;
private long lastEvent;
private List<HostedEvent> eventList;
public EventManager(ManagerHandler managerHandler) {
super(managerHandler);
currentEvents = new ArrayList<>();
eventList = new ArrayList<>();
loadEvents();
fetch();
}
private void loadEvents() {
addEvent(new SumoEvent());
}
private void fetch() {
eventList.forEach(e -> {
if (this.managerHandler.getConfigurationManager().getEventsFile().get(e.getName()) != null) {
if (managerHandler.getConfigurationManager().getEventsFile().get(e.getName() + ".lobby") != null)
e.setLobby(LocationUtil.getLocationFromString(managerHandler.getConfigurationManager().getEventsFile().getString(e.getName() + ".lobby")));
if (managerHandler.getConfigurationManager().getEventsFile().get(e.getName() + ".first") != null)
e.setFirst(LocationUtil.getLocationFromString(managerHandler.getConfigurationManager().getEventsFile().getString(e.getName() + ".first")));
if (managerHandler.getConfigurationManager().getEventsFile().get(e.getName() + ".second") != null)
e.setSecond(LocationUtil.getLocationFromString(managerHandler.getConfigurationManager().getEventsFile().getString(e.getName() + ".second")));
}
});
}
private void addEvent(HostedEvent event) {
eventList.add(event);
}
public HostedEvent getEvent(String name) {
return eventList.stream().filter(e -> e.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
public HostedEvent getStartedEvent(String name) {
return currentEvents.stream().filter(e -> e.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
public void save() {
eventList.forEach(e -> {
this.managerHandler.getConfigurationManager().getEventsFile().set(e.getName(), null);
if (e.getLobby() != null)
this.managerHandler.getConfigurationManager().getEventsFile().set(e.getName() + ".lobby", LocationUtil.getStringFromLocation(e.getLobby()));
if (e.getFirst() != null)
this.managerHandler.getConfigurationManager().getEventsFile().set(e.getName() + ".first", LocationUtil.getStringFromLocation(e.getFirst()));
if (e.getSecond() != null)
this.managerHandler.getConfigurationManager().getEventsFile().set(e.getName() + ".second", LocationUtil.getStringFromLocation(e.getSecond()));
});
this.managerHandler.getConfigurationManager().saveEventsFile();
}
}

View File

@ -0,0 +1,36 @@
package me.abhi.practice.manager.impl;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.enums.Items;
import me.abhi.practice.util.misc.CC;
import me.abhi.practice.util.misc.ItemBuilder;
import org.bukkit.Material;
import java.util.Arrays;
import java.util.List;
public class ItemsManager extends Manager {
public ItemsManager(ManagerHandler managerHandler) {
super(managerHandler);
fetch();
}
private void fetch() {
Arrays.stream(Items.values()).forEach(item -> {
String[] material = managerHandler.getPlugin().getConfig().getString("items." + item.toString() + ".id").split(":");
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("items." + item.toString() + ".name"));
int slot = managerHandler.getPlugin().getConfig().getInt("items." + item.toString() + ".slot");
boolean loreEnabled = managerHandler.getPlugin().getConfig().getBoolean("items." + item.toString() + ".lore-enabled");
List<String> lore = managerHandler.getPlugin().getConfig().getStringList("items." + item.toString() + ".lore");
int id = Integer.parseInt(material[0]);
short durability = (short) Integer.parseInt(material[1]);
item.setItem(new ItemBuilder(Material.getMaterial(id)).setDurability(durability).setName(name).setLore(loreEnabled ? lore : null).toItemStack());
item.setSlot(slot);
});
}
}

View File

@ -0,0 +1,118 @@
package me.abhi.practice.manager.impl;
import lombok.Getter;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.misc.ItemBuilder;
import me.abhi.practice.util.misc.Logger;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Getter
public class KitManager extends Manager {
private List<Kit> kitsList;
public KitManager(ManagerHandler managerHandler) {
super(managerHandler);
kitsList = new ArrayList<>();
fetch();
}
private void fetch() {
if (managerHandler.getConfigurationManager().getKitsFile().getConfigurationSection("kits") == null) {
return;
}
managerHandler.getConfigurationManager().getKitsFile().getConfigurationSection("kits").getKeys(false).stream().forEach(k -> {
Kit kit = new Kit(k);
String[] material = managerHandler.getConfigurationManager().getKitsFile().getString("kits." + k + ".display").split(":");
int id = Integer.parseInt(material[0]);
short durability = (short) Integer.parseInt(material[1]);
kit.setDisplay(new ItemBuilder(Material.getMaterial(id)).setDurability(durability).toItemStack());
if (managerHandler.getConfigurationManager().getKitsFile().get("kits." + k + ".inventory") != null)
kit.setInventory(InventoryUtil.fromBase64(managerHandler.getConfigurationManager().getKitsFile().getString("kits." + k + ".inventory")));
if (managerHandler.getConfigurationManager().getKitsFile().get("kits." + k + ".armor") != null)
kit.setArmor(InventoryUtil.itemStackArrayFromBase64(managerHandler.getConfigurationManager().getKitsFile().getString("kits." + k + ".armor")));
if (managerHandler.getConfigurationManager().getKitsFile().get("kits." + k + ".editInventory") != null)
kit.setEditInventory(InventoryUtil.fromBase64(managerHandler.getConfigurationManager().getKitsFile().getString("kits." + k + ".editInventory")));
kit.setKitType(KitType.getType(managerHandler.getConfigurationManager().getKitsFile().getString("kits." + k + ".type")));
kit.setEditChest(managerHandler.getConfigurationManager().getKitsFile().getBoolean("kits." + k + ".editChest"));
kit.setRanked(managerHandler.getConfigurationManager().getKitsFile().getBoolean("kits." + k + ".ranked"));
kit.setUnranked(managerHandler.getConfigurationManager().getKitsFile().getBoolean("kits." + k + ".unranked"));
kit.setEditable(managerHandler.getConfigurationManager().getKitsFile().getBoolean("kits." + k + ".editable"));
addKit(kit);
if (!this.managerHandler.getMongoManager().collectionExists(k)) {
this.managerHandler.getMongoManager().getMongoDatabase().createCollection(k);
Logger.success("Created Mongo collection " + k + ".");
}
});
if (managerHandler.getConfigurationManager().getKitsFile().getConfigurationSection("hcf") == null) {
return;
}
managerHandler.getConfigurationManager().getKitsFile().getConfigurationSection("hcf").getKeys(false).stream().forEach(k -> {
HCFKit hcfKit = HCFKit.valueOf(k);
if (managerHandler.getConfigurationManager().getKitsFile().get("hcf." + k + ".inventory") != null) hcfKit.setInventory(InventoryUtil.fromBase64(managerHandler.getConfigurationManager().getKitsFile().getString("hcf." + k + ".inventory")));
if (managerHandler.getConfigurationManager().getKitsFile().get("hcf." + k + ".armor") != null) hcfKit.setArmor(InventoryUtil.itemStackArrayFromBase64(managerHandler.getConfigurationManager().getKitsFile().getString("hcf." + k + ".armor")));
});
}
public Kit getKit(String name) {
return kitsList.stream().filter(k -> k.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
public void addKit(Kit kit) {
kitsList.add(kit);
}
public void removeKit(Kit kit) {
kitsList.remove(kit);
}
public void save() {
managerHandler.getConfigurationManager().getKitsFile().set("kits", null);
kitsList.forEach(k -> {
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".display", k.getDisplay().getTypeId() + ":" + k.getDisplay().getDurability());
if (k.getInventory() != null)
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".inventory", InventoryUtil.toBase64(k.getInventory()));
if (k.getArmor() != null)
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".armor", InventoryUtil.itemStackArrayToBase64(k.getArmor()));
if (k.getEditInventory() != null)
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".editInventory", InventoryUtil.toBase64(k.getEditInventory()));
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".type", k.getKitType().toString());
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".editChest", k.isEditChest());
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".ranked", k.isRanked());
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".unranked", k.isUnranked());
managerHandler.getConfigurationManager().getKitsFile().set("kits." + k.getName() + ".editable", k.isEditable());
});
managerHandler.getConfigurationManager().getKitsFile().set("hcf", null);
Arrays.stream(HCFKit.values()).forEach(k -> {
if (k.getInventory() != null)
managerHandler.getConfigurationManager().getKitsFile().set("hcf." + k.toString() + ".inventory", InventoryUtil.toBase64(k.getInventory()));
if (k.getArmor() != null)
managerHandler.getConfigurationManager().getKitsFile().set("hcf." + k.toString() + ".armor", InventoryUtil.itemStackArrayToBase64(k.getArmor()));
});
managerHandler.getConfigurationManager().saveKitsFile();
}
}

View File

@ -0,0 +1,52 @@
package me.abhi.practice.manager.impl;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.enums.Menus;
import me.abhi.practice.util.misc.CC;
import me.abhi.practice.util.misc.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MenuManager extends Manager {
public MenuManager(ManagerHandler managerHandler) {
super(managerHandler);
fetch();
}
private void fetch() {
Arrays.stream(Menus.values()).forEach(m -> {
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("menus." + m.toString() + ".name"));
int slots = 9 * managerHandler.getPlugin().getConfig().getInt("menus." + m.toString() + ".rows");
String prefix = managerHandler.getPlugin().getConfig().getString("menus." + m.toString() + ".item-prefix");
String itemPrefix = CC.translate(prefix == null ? "" : prefix);
List<String> lore = managerHandler.getPlugin().getConfig().getStringList("menus." + m.toString() + ".item-lore");
Inventory inventory = managerHandler.getPlugin().getServer().createInventory(null, slots, name);
m.setInventory(inventory);
if (lore != null) m.setItemLore(lore);
if (m == Menus.SETTINGS) {
if (!managerHandler.getPlugin().getConfig().getBoolean("settings.settings-gui")) return;
List<String> stringList = new ArrayList<>();
stringList.addAll(managerHandler.getPlugin().getConfig().getConfigurationSection("menus.SETTINGS.items").getKeys(false));
stringList.forEach(s -> {
Menus.SETTINGS.getInventory().addItem(
new ItemBuilder(Material.getMaterial(managerHandler.getPlugin().getConfig().getInt("menus.SETTINGS.items." + s + ".id")))
.setName(CC.translate(managerHandler.getPlugin().getConfig().getString("menus.SETTINGS.items." + s + ".name")))
.toItemStack());
});
}
m.setItemPrefix(itemPrefix);
});
}
}

View File

@ -0,0 +1,56 @@
package me.abhi.practice.manager.impl;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
import lombok.Getter;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.misc.Logger;
import java.util.Collections;
@Getter
public class MongoManager extends Manager {
private MongoClient mongoClient;
private MongoDatabase mongoDatabase;
public MongoManager(ManagerHandler managerHandler) {
super(managerHandler);
establishConnection();
}
private void establishConnection() {
String ip = managerHandler.getPlugin().getConfig().getString("mongo.ip");
int port = managerHandler.getPlugin().getConfig().getInt("mongo.port");
String database = managerHandler.getPlugin().getConfig().getString("mongo.database");
boolean usePassword = managerHandler.getPlugin().getConfig().getBoolean("mongo.use-password");
String username = managerHandler.getPlugin().getConfig().getString("mongo.username");
String password = managerHandler.getPlugin().getConfig().getString("mongo.password");
try {
if (usePassword) {
mongoClient = new MongoClient(new ServerAddress(ip, port), Collections.singletonList(MongoCredential.createCredential(username, database, password.toCharArray())));
} else {
mongoClient = new MongoClient(new ServerAddress(ip, port));
}
mongoDatabase = mongoClient.getDatabase(database);
mongoClient.getAddress();
Logger.success("Successfully established Mongo connection.");
} catch (Exception ex) {
Logger.error("Could not establish Mongo connection.");
}
}
public boolean collectionExists(String collection) {
boolean exists = false;
for (String collections : mongoDatabase.listCollectionNames()) {
if (collection.equalsIgnoreCase(collections)) exists = true;
}
return exists;
}
}

View File

@ -0,0 +1,305 @@
package me.abhi.practice.manager.impl;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import me.abhi.practice.kit.CustomKit;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.party.Party;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.InventoryUtil;
import me.abhi.practice.util.enums.Items;
import me.abhi.practice.util.misc.CC;
import me.abhi.practice.util.misc.ItemBuilder;
import org.bson.Document;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.HashMap;
import java.util.Map;
public class PlayerManager extends Manager {
public PlayerManager(ManagerHandler managerHandler) {
super(managerHandler);
}
public void resetPlayer(Player player) {
if (player == null || !player.isOnline()) return;
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.updateInventory();
player.getActivePotionEffects().clear();
player.setHealth(20);
player.setFoodLevel(20);
player.setExhaustion(0);
player.setSaturation(5);
player.setLevel(0);
player.setExp(0f);
player.setFireTicks(0);
practiceProfile.setLastEnderpearl(0);
practiceProfile.setBardEnergy(0);
practiceProfile.setLastBardBuff(0);
practiceProfile.setLastArcherSpeedBuff(0);
practiceProfile.setLastArcherJumpBuff(0);
practiceProfile.setLastRogueBackstab(0);
practiceProfile.setLastRogueSpeedBuff(0);
practiceProfile.setLastRogueJumpBuff(0);
practiceProfile.getPotionEffectsList().clear();
player.getActivePotionEffects().forEach(p -> player.removePotionEffect(p.getType()));
}
public void giveItems(Player player, boolean hide) {
if (player == null || !player.isOnline()) return;
resetPlayer(player);
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
switch (practiceProfile.getPlayerState()) {
case LOBBY: {
player.getInventory().setItem(Items.UNRANKED.getSlot(), Items.UNRANKED.getItem());
player.getInventory().setItem(Items.RANKED.getSlot(), Items.RANKED.getItem());
player.getInventory().setItem(Items.PARTY.getSlot(), Items.PARTY.getItem());
player.getInventory().setItem(Items.EDITKIT.getSlot(), Items.EDITKIT.getItem());
break;
}
case QUEUE: {
player.getInventory().setItem(Items.LEAVE_QUEUE.getSlot(), Items.LEAVE_QUEUE.getItem());
break;
}
case PARTY: {
Party party = practiceProfile.getParty();
if (party.getLeader() == player.getUniqueId()) {
player.getInventory().setItem(Items.PARTY_EVENTS.getSlot(), Items.PARTY_EVENTS.getItem());
player.getInventory().setItem(Items.HCF_SELECTOR.getSlot(), Items.HCF_SELECTOR.getItem());
player.getInventory().setItem(Items.LEADER_PARTY_INFO.getSlot(), Items.LEADER_PARTY_INFO.getItem());
player.getInventory().setItem(Items.DISBAND_PARTY.getSlot(), Items.DISBAND_PARTY.getItem());
} else {
player.getInventory().setItem(Items.PLAYER_PARTY_INFO.getSlot(), Items.PLAYER_PARTY_INFO.getItem());
player.getInventory().setItem(Items.LEAVE_PARTY.getSlot(), Items.LEAVE_PARTY.getItem());
}
break;
}
case EVENT: {
player.getInventory().setItem(Items.LEAVE_EVENT.getSlot(), Items.LEAVE_EVENT.getItem());
break;
}
case TOURNAMENT: {
player.getInventory().setItem(Items.LEAVE_TOURNAMENT.getSlot(), Items.LEAVE_TOURNAMENT.getItem());
break;
}
case SPECTATING: {
player.getInventory().setItem(Items.STOP_SPECTATING.getSlot(), Items.STOP_SPECTATING.getItem());
break;
}
case SPECTATING_EVENT: {
player.getInventory().setItem(Items.LEAVE_EVENT.getSlot(), Items.LEAVE_EVENT.getItem());
break;
}
}
player.updateInventory();
player.setGameMode(GameMode.SURVIVAL);
if (hide) {
if (!this.managerHandler.getSettingsManager().isShowPlayers()) {
hideAll(player);
hideAll1(player);
} else {
showAll(player);
}
}
}
public void teleportSpawn(Player player) {
if (managerHandler.getSettingsManager().getSpawn() != null)
player.teleport(managerHandler.getSettingsManager().getSpawn());
}
public void save(Player player) {
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
this.managerHandler.getKitManager().getKitsList().forEach(kit -> {
if (managerHandler.getMongoManager().collectionExists(kit.getName())) {
MongoCollection mongoCollection = managerHandler.getMongoManager().getMongoDatabase().getCollection(kit.getName());
Map<String, Object> documentMap = new HashMap<>();
documentMap.put("uuid", player.getUniqueId().toString());
documentMap.put("username", player.getName());
documentMap.put("elo", practiceProfile.getElo(kit));
for (int i = 1; i <= 7; i++) {
CustomKit customKit = practiceProfile.getCustomKit(kit, i);
if (customKit != null) {
documentMap.put("kit-" + i + "-name", customKit.getName());
documentMap.put("kit-" + i + "-inventory", InventoryUtil.toBase64(customKit.getInventory()));
documentMap.put("kit-" + i + "-armor", InventoryUtil.itemStackArrayToBase64(customKit.getArmor()));
}
}
Document document = (Document) mongoCollection.find(Filters.eq("uuid", player.getUniqueId().toString())).first();
if (document != null) mongoCollection.deleteOne(document);
mongoCollection.insertOne(new Document(documentMap));
}
});
}
public void openEditLayoutInventory(Player player) {
Inventory inventory = this.managerHandler.getPlugin().getServer().createInventory(null, 36, CC.translate(this.managerHandler.getPlugin().getConfig().getString("menus.EDITLAYOUT.name")));
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
practiceProfile.setEditLayoutInventory(inventory);
player.openInventory(inventory);
}
public void updateEditLayout(Player player, Kit kit) {
Map<String, ItemStack> itemMap = new HashMap<>();
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
Inventory inventory = practiceProfile.getEditLayoutInventory();
this.managerHandler.getPlugin().getConfig().getConfigurationSection("menus.EDITLAYOUT.items").getKeys(false).stream().forEach(i -> {
String[] material = managerHandler.getPlugin().getConfig().getString("menus.EDITLAYOUT.items." + i + ".id").split(":");
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("menus.EDITLAYOUT.items." + i + ".name"));
itemMap.put(i, new ItemBuilder(Material.getMaterial(Integer.parseInt(material[0]))).setDurability((short) Integer.parseInt(material[1])).setName(name).toItemStack());
});
for (int i = 1; i <= 7; i++) {
String saveKitName = itemMap.get("save-kit").clone().getItemMeta().getDisplayName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
ItemStack saveKit = new ItemBuilder(itemMap.get("save-kit").clone()).setName(saveKitName).toItemStack();
inventory.setItem(i, saveKit);
String loadKitName = itemMap.get("load-kit").clone().getItemMeta().getDisplayName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
ItemStack loadKit = new ItemBuilder(itemMap.get("load-kit").clone()).setName(loadKitName).toItemStack();
String renameKitName = itemMap.get("rename-kit").clone().getItemMeta().getDisplayName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
ItemStack renameKit = new ItemBuilder(itemMap.get("rename-kit").clone()).setName(renameKitName).toItemStack();
String removeKitName = itemMap.get("remove-kit").clone().getItemMeta().getDisplayName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
ItemStack removeKit = new ItemBuilder(itemMap.get("remove-kit").clone()).setName(removeKitName).toItemStack();
if (practiceProfile.getCustomKit(kit, i) != null) {
inventory.setItem(i + 9, loadKit);
inventory.setItem(i + 18, renameKit);
inventory.setItem(i + 27, removeKit);
} else {
inventory.setItem(i + 9, new ItemStack(Material.AIR));
inventory.setItem(i + 18, new ItemStack(Material.AIR));
inventory.setItem(i + 27, new ItemStack(Material.AIR));
}
}
}
public void openPartyEvents(Player player) {
Inventory inventory = this.managerHandler.getPlugin().getServer().createInventory(null, 9 * this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYEVENTS.rows"), CC.translate(this.managerHandler.getPlugin().getConfig().getString("menus.PARTYEVENTS.name")));
Map<String, ItemStack> itemMap = new HashMap<>();
this.managerHandler.getPlugin().getConfig().getConfigurationSection("menus.PARTYEVENTS.items").getKeys(false).stream().forEach(i -> {
String[] material = managerHandler.getPlugin().getConfig().getString("menus.PARTYEVENTS.items." + i + ".id").split(":");
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("menus.PARTYEVENTS.items." + i + ".name"));
itemMap.put(i, new ItemBuilder(Material.getMaterial(Integer.parseInt(material[0]))).setDurability((short) Integer.parseInt(material[1])).setName(name).toItemStack());
});
inventory.setItem(this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYEVENTS.items.ffa.slot"), itemMap.get("ffa"));
inventory.setItem(this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYEVENTS.items.split.slot"), itemMap.get("split"));
player.openInventory(inventory);
}
public void openPartyDuel(Player player) {
Inventory inventory = this.managerHandler.getPlugin().getServer().createInventory(null, 9 * this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYDUEL.rows"), CC.translate(this.managerHandler.getPlugin().getConfig().getString("menus.PARTYDUEL.name")));
Map<String, ItemStack> itemMap = new HashMap<>();
this.managerHandler.getPlugin().getConfig().getConfigurationSection("menus.PARTYDUEL.items").getKeys(false).stream().forEach(i -> {
String[] material = managerHandler.getPlugin().getConfig().getString("menus.PARTYDUEL.items." + i + ".id").split(":");
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("menus.PARTYDUEL.items." + i + ".name"));
itemMap.put(i, new ItemBuilder(Material.getMaterial(Integer.parseInt(material[0]))).setDurability((short) Integer.parseInt(material[1])).setName(name).toItemStack());
});
inventory.setItem(this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYDUEL.items.regular.slot"), itemMap.get("regular"));
inventory.setItem(this.managerHandler.getPlugin().getConfig().getInt("menus.PARTYDUEL.items.hcf.slot"), itemMap.get("hcf"));
player.openInventory(inventory);
}
public void openHCFSelector(Player player) {
Inventory inventory = this.managerHandler.getPlugin().getServer().createInventory(null, 9 * this.managerHandler.getPlugin().getConfig().getInt("menus.HCFKITS.rows"), CC.translate(this.managerHandler.getPlugin().getConfig().getString("menus.HCFKITS.name")));
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
practiceProfile.setHcfKitSelectorInventory(inventory);
player.openInventory(inventory);
}
public void updateHCFInventory(Player player) {
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
Inventory inventory = practiceProfile.getHcfKitSelectorInventory();
inventory.clear();
Map<String, ItemStack> itemMap = new HashMap<>();
this.managerHandler.getPlugin().getConfig().getConfigurationSection("menus.HCFKITS.items").getKeys(false).stream().forEach(i -> {
String[] material = managerHandler.getPlugin().getConfig().getString("menus.HCFKITS.items." + i + ".id").split(":");
String name = CC.translate(managerHandler.getPlugin().getConfig().getString("menus.HCFKITS.items." + i + ".name"));
itemMap.put(i, new ItemBuilder(Material.getMaterial(Integer.parseInt(material[0]))).setDurability((short) Integer.parseInt(material[1])).setName(name).toItemStack());
});
Party party = practiceProfile.getParty();
party.getMembers().stream().forEach(u -> {
Player member = this.managerHandler.getPlugin().getServer().getPlayer(u);
PracticeProfile memberProfile = this.managerHandler.getProfileManager().getProfile(member);
ItemStack clone = itemMap.get("player").clone();
inventory.addItem(new ItemBuilder(clone.getType()).setDurability(clone.getDurability()).setName(clone.getItemMeta().getDisplayName().replace("%player%", member.getName()).replace("%kit%", memberProfile.getHcfKit().getName())).toItemStack());
});
}
public PotionEffect getPotionEffect(Player player, PotionEffectType potionEffectType) {
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
if (potionEffect.getType().equals(potionEffectType)) {
return potionEffect;
}
}
return null;
}
public void hideAll(Player player) {
this.managerHandler.getPlugin().getServer().getOnlinePlayers().stream().forEach(p -> {
player.hidePlayer(p);
});
}
public void hideAll1(Player player) {
this.managerHandler.getPlugin().getServer().getOnlinePlayers().stream().forEach(p -> {
p.hidePlayer(player);
});
}
public void showAll(Player player) {
this.managerHandler.getPlugin().getServer().getOnlinePlayers().stream().forEach(p -> {
player.showPlayer(p);
});
}
}

View File

@ -0,0 +1,36 @@
package me.abhi.practice.manager.impl;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.player.PracticeProfile;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ProfileManager extends Manager {
private Map<UUID, PracticeProfile> practiceProfileMap;
public ProfileManager(ManagerHandler managerHandler) {
super(managerHandler);
practiceProfileMap = new HashMap<>();
}
public void addPlayer(Player player) {
practiceProfileMap.put(player.getUniqueId(), new PracticeProfile());
}
public void removePlayer(Player player) {
practiceProfileMap.remove(player.getUniqueId());
}
public PracticeProfile getProfile(Player player) {
return practiceProfileMap.get(player.getUniqueId());
}
public boolean hasProfile(Player player) {
return practiceProfileMap.containsKey(player.getUniqueId());
}
}

View File

@ -0,0 +1,228 @@
package me.abhi.practice.manager.impl;
import me.abhi.practice.hostedevent.HostedEvent;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.queue.Queue;
import me.abhi.practice.tournament.Tournament;
import me.abhi.practice.util.DurationUtil;
import me.abhi.practice.util.misc.ScoreHelper;
import me.abhi.practice.util.reflection.BukkitReflection;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("Duplicates")
public class ScoreboardManager extends Manager {
public ScoreboardManager(ManagerHandler managerHandler) {
super(managerHandler);
}
public void update(Player player) {
try {
if (!managerHandler.getProfileManager().hasProfile(player) || !ScoreHelper.hasScore(player) || !this.managerHandler.getPlugin().getConfig().getBoolean("scoreboard.enabled")) {
return;
}
PracticeProfile practiceProfile = this.managerHandler.getProfileManager().getProfile(player);
ScoreHelper scoreHelper = ScoreHelper.getByPlayer(player);
String title = "Title";
List<String> toReturn = new ArrayList<>();
switch (practiceProfile.getPlayerState()) {
case LOBBY: {
title = managerHandler.getPlugin().getConfig().getString("scoreboard.LOBBY.title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard.LOBBY.slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
toReturn.add(line);
}
break;
}
case QUEUE: {
Queue queue = practiceProfile.getQueue();
title = managerHandler.getPlugin().getConfig().getString("scoreboard." + (queue.isRanked() ? "RANKED" : "UNRANKED") + "-QUEUE.title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard." + (queue.isRanked() ? "RANKED" : "UNRANKED") + "-QUEUE.slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%kit%", queue.getKit().getName());
line = line.replace("%time%", DurationUtil.getDuration(queue.getStartTime()));
line = line.replace("%minElo%", String.valueOf(queue.getMinElo()));
line = line.replace("%maxElo%", String.valueOf(queue.getMaxElo()));
toReturn.add(line);
}
break;
}
case MATCH: {
Match match = practiceProfile.getMatch();
Player opponent = match.getTeamOne().contains(player.getUniqueId()) ? match.getT2l() : match.getT1l();
title = managerHandler.getPlugin().getConfig().getString("scoreboard." + (match.isRanked() ? "RANKED" : "UNRANKED") + "-MATCH.title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard." + (match.isRanked() ? "RANKED" : "UNRANKED") + "-MATCH.slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%kit%", match.getKit().getName());
line = line.replace("%opponent%", opponent.getName());
line = line.replace("%ping%", String.valueOf(BukkitReflection.getPing(player)));
line = line.replace("%opponentPing%", String.valueOf(BukkitReflection.getPing(opponent)));
line = line.replace("%time%", (match.getEndTime() != 0 ? DurationUtil.getDuration(match.getStartTime(), match.getEndTime()) : DurationUtil.getDuration(match.getStartTime())));
toReturn.add(line);
}
break;
}
case EDITING: {
title = managerHandler.getPlugin().getConfig().getString("scoreboard.EDITING.title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard.EDITING.slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%kit%", practiceProfile.getEditing().getName());
toReturn.add(line);
}
break;
}
case PARTY: {
Party party = practiceProfile.getParty();
Player leader = this.managerHandler.getPlugin().getServer().getPlayer(party.getLeader());
title = managerHandler.getPlugin().getConfig().getString("scoreboard.PARTY-" + party.getPartyState().toString() + (party.getPartyState() == PartyState.MATCH && party.getMatch().getTeamTwo() == null ? "-FFA" : "") + (party.getPartyState() == PartyState.MATCH && party.getMatch().getKit() == null && practiceProfile.getHcfKit() == HCFKit.BARD ? "-BARD" : "") + ".title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard.PARTY-" + party.getPartyState().toString() + (party.getPartyState() == PartyState.MATCH && party.getMatch().getTeamTwo() == null ? "-FFA" : "") + (party.getPartyState() == PartyState.MATCH && party.getMatch().getKit() == null && practiceProfile.getHcfKit() == HCFKit.BARD ? "-BARD" : "") + ".slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%leader%", leader.getName());
line = line.replace("%members%", String.valueOf(party.getMembers().size()));
if (party.getPartyState() == PartyState.MATCH) {
Match match = party.getMatch();
if (match.getTeamTwo() != null) {
boolean t1 = match.getTeamOne().contains(player.getUniqueId());
line = line.replace("%alive%", String.valueOf(match.getAlive(t1)));
line = line.replace("%all%", String.valueOf(t1 ? match.getTeamOne().size() : match.getTeamTwo().size()));
line = line.replace("%ping%", String.valueOf(BukkitReflection.getPing(player)));
line = line.replace("%opponentAlive%", String.valueOf(match.getAlive(!t1)));
line = line.replace("%opponentAll%", String.valueOf(t1 ? match.getTeamTwo().size() : match.getTeamOne().size()));
line = line.replace("%time%", (match.getEndTime() != 0 ? DurationUtil.getDuration(match.getStartTime(), match.getEndTime()) : DurationUtil.getDuration(match.getStartTime())));
if (match.getKit() == null && practiceProfile.getHcfKit() == HCFKit.BARD) {
line = line.replace("%energy%", String.valueOf(practiceProfile.getBardEnergy()));
}
} else {
line = line.replace("%alive%", String.valueOf(match.getAlive(true)));
line = line.replace("%all%", String.valueOf(match.getTeamOne().size()));
line = line.replace("%ping%", String.valueOf(BukkitReflection.getPing(player)));
line = line.replace("%time%", (match.getEndTime() != 0 ? DurationUtil.getDuration(match.getStartTime(), match.getEndTime()) : DurationUtil.getDuration(match.getStartTime())));
}
}
toReturn.add(line);
}
break;
}
case EVENT: {
HostedEvent hostedEvent = practiceProfile.getHostedEvent();
title = managerHandler.getPlugin().getConfig().getString("scoreboard." + hostedEvent.getName().toUpperCase() + "-EVENT-" + hostedEvent.getEventState().toString() + ".title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard." + hostedEvent.getName().toUpperCase() + "-EVENT-" + hostedEvent.getEventState().toString() + ".slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%players%", String.valueOf(hostedEvent.getPlayers().size()));
line = line.replace("%max%", String.valueOf(this.managerHandler.getSettingsManager().getPlayersPerEvent()));
line = line.replace("%time%", hostedEvent.getStartTime() > 0 ? DurationUtil.getDuration(hostedEvent.getStartTime()) : DurationUtil.getDurationDown(hostedEvent.getDown(), 29));
toReturn.add(line);
}
break;
}
case SPECTATING_EVENT: {
HostedEvent hostedEvent = practiceProfile.getHostedEvent();
title = managerHandler.getPlugin().getConfig().getString("scoreboard." + hostedEvent.getName().toUpperCase() + "-EVENT-" + hostedEvent.getEventState().toString() + ".title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard." + hostedEvent.getName().toUpperCase() + "-EVENT-" + hostedEvent.getEventState().toString() + ".slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%players%", String.valueOf(hostedEvent.getPlayers().size()));
line = line.replace("%max%", String.valueOf(this.managerHandler.getSettingsManager().getPlayersPerEvent()));
line = line.replace("%time%", hostedEvent.getStartTime() > 0 ? DurationUtil.getDuration(hostedEvent.getStartTime()) : DurationUtil.getDurationDown(hostedEvent.getDown(), 29));
toReturn.add(line);
}
break;
}
case TOURNAMENT: {
Tournament tournament = practiceProfile.getTournament();
title = managerHandler.getPlugin().getConfig().getString("scoreboard.TOURNAMENT-" + tournament.getTournamentState().toString() + ".title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard.TOURNAMENT-" + tournament.getTournamentState().toString() + ".slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%players%", String.valueOf(tournament.getParticipants().size()));
line = line.replace("%max%", String.valueOf(this.managerHandler.getSettingsManager().getPlayersPerTournament()));
line = line.replace("%time%", tournament.getStartTime() > 0 ? DurationUtil.getDuration(tournament.getStartTime()) : DurationUtil.getDurationDown(tournament.getDown(), 59));
line = line.replace("%round%", String.valueOf(tournament.getRound()));
line = line.replace("%kit%", tournament.getKit().getName());
toReturn.add(line);
}
break;
}
case SPECTATING: {
Match match = practiceProfile.getSpectating();
title = managerHandler.getPlugin().getConfig().getString("scoreboard.SPECTATING.title");
for (String line : managerHandler.getPlugin().getConfig().getStringList("scoreboard.SPECTATING.slots")) {
line = line.replace("%online%", String.valueOf(this.managerHandler.getPlugin().getServer().getOnlinePlayers().size()));
line = line.replace("%queueing%", String.valueOf(getQueueing()));
line = line.replace("%fighting%", String.valueOf(getFighting()));
line = line.replace("%kit%", match.getKit().getName());
line = line.replace("%player1%", match.getT1l().getName());
line = line.replace("%player2%", match.getT2l().getName());
toReturn.add(line);
}
}
}
if (!practiceProfile.isScoreboard()) {
toReturn.clear();
}
scoreHelper.setTitle(title);
scoreHelper.setSlotsFromList(toReturn);
} catch (Exception ex) {
//remove the errors :3
}
}
private int getQueueing() {
int queueing = 0;
for (Kit kit : this.managerHandler.getKitManager().getKitsList()) {
queueing += kit.getUnrankedQueue().size() + kit.getRankedQueue().size();
}
return queueing;
}
private int getFighting() {
int fighting = 0;
for (Kit kit : this.managerHandler.getKitManager().getKitsList()) {
fighting += kit.getUnrankedMatch().size() + kit.getRankedMatch().size();
}
return fighting;
}
}

View File

@ -0,0 +1,69 @@
package me.abhi.practice.manager.impl;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.util.LocationUtil;
import org.bukkit.Location;
@Getter
@Setter
public class SettingsManager extends Manager {
private Location spawn;
private Location editor;
private int defaultElo;
private int maxElo;
private int minElo;
private int maxPartyMembers;
private boolean lightningEffect;
private boolean deleteBottles;
private long eventDelay;
private int playersPerEvent;
private int playersPerTournament;
private boolean showPlayers;
private boolean leaderboardsGUI;
private boolean voidSpawn;
private boolean hideInvisiblesInTab;
private String partyChatFormat;
public SettingsManager(ManagerHandler managerHandler) {
super(managerHandler);
fetch();
}
private void fetch() {
if (managerHandler.getPlugin().getConfig().get("spawn") != null)
spawn = LocationUtil.getLocationFromString(managerHandler.getPlugin().getConfig().getString("spawn"));
if (managerHandler.getPlugin().getConfig().get("editor") != null)
editor = LocationUtil.getLocationFromString(managerHandler.getPlugin().getConfig().getString("editor"));
defaultElo = managerHandler.getPlugin().getConfig().getInt("settings.default-elo");
maxElo = managerHandler.getPlugin().getConfig().getInt("settings.max-elo");
minElo = managerHandler.getPlugin().getConfig().getInt("settings.min-elo");
maxPartyMembers = managerHandler.getPlugin().getConfig().getInt("settings.max-party-members");
lightningEffect = managerHandler.getPlugin().getConfig().getBoolean("settings.lightning-effect");
deleteBottles = managerHandler.getPlugin().getConfig().getBoolean("settings.delete-bottles");
eventDelay = managerHandler.getPlugin().getConfig().getInt("settings.event-delay") * 60000;
playersPerEvent = managerHandler.getPlugin().getConfig().getInt("settings.players-per-event");
playersPerTournament = managerHandler.getPlugin().getConfig().getInt("settings.players-per-tournament");
showPlayers = managerHandler.getPlugin().getConfig().getBoolean("settings.show-players");
leaderboardsGUI = managerHandler.getPlugin().getConfig().getBoolean("settings.leaderboards-gui");
voidSpawn = managerHandler.getPlugin().getConfig().getBoolean("settings.void-spawn");
hideInvisiblesInTab = managerHandler.getPlugin().getConfig().getBoolean("settings.hide-invisibles-in-tab");
partyChatFormat = managerHandler.getPlugin().getConfig().getString("party-chat-format");
}
public void save() {
if (spawn != null)
managerHandler.getPlugin().getConfig().set("spawn", LocationUtil.getStringFromLocation(spawn));
if (editor != null)
managerHandler.getPlugin().getConfig().set("editor", LocationUtil.getStringFromLocation(editor));
managerHandler.getPlugin().saveConfig();
}
}

View File

@ -0,0 +1,58 @@
package me.abhi.practice.manager.impl;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.manager.Manager;
import me.abhi.practice.manager.ManagerHandler;
import me.abhi.practice.tournament.Tournament;
import me.abhi.practice.tournament.TournamentState;
import me.abhi.practice.util.enums.Messages;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.scheduler.BukkitRunnable;
@Setter
@Getter
public class TournamentManager extends Manager {
private Tournament tournament;
public TournamentManager(ManagerHandler managerHandler) {
super(managerHandler);
}
public void next() {
try {
tournament.setDown(System.currentTimeMillis());
new BukkitRunnable() {
int i = tournament.getRound() > 1 ? 30 : 60;
public void run() {
if (tournament == null || (tournament.getTournamentState() != TournamentState.STARTING && tournament.getTournamentState() != TournamentState.WAITING)) {
this.cancel();
return;
}
if (i % 10 == 0 && tournament.getTournamentState() == TournamentState.STARTING) {
TextComponent clickable = new TextComponent(Messages.TOURNAMENT_STARTING.getMessage().replace("%kit%", tournament.getKit().getName()));
clickable.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tournament join"));
clickable.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Messages.TOURNAMENT_HOVER.getMessage().replace("%kit%", tournament.getKit().getName())).create()));
managerHandler.getPlugin().getServer().getOnlinePlayers().stream().forEach(p -> p.spigot().sendMessage(clickable));
}
i -= 1;
if (i == 0) {
tournament.setStartTime(System.currentTimeMillis());
tournament.startRound();
tournament.setTournamentState(TournamentState.STARTED);
this.cancel();
}
}
}.runTaskTimer(managerHandler.getPlugin(), 0L, 20L);
} catch (Exception ex) {
// get rid of errors ;3
}
}
}

View File

@ -0,0 +1,565 @@
package me.abhi.practice.match;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.arena.Arena;
import me.abhi.practice.kit.CustomKit;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.KitType;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.task.player.BardTask;
import me.abhi.practice.tournament.Tournament;
import me.abhi.practice.tournament.TournamentState;
import me.abhi.practice.util.EloUtil;
import me.abhi.practice.util.enums.Items;
import me.abhi.practice.util.enums.Messages;
import me.abhi.practice.util.misc.CC;
import me.abhi.practice.util.misc.InventorySnapshot;
import me.abhi.practice.util.misc.ItemBuilder;
import me.abhi.practice.util.misc.ScoreHelper;
import me.abhi.practice.util.reflection.BukkitReflection;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
@SuppressWarnings("Duplicates")
@Getter
@RequiredArgsConstructor
public class Match {
private final PracticePlugin plugin;
private final Kit kit;
private final List<UUID> teamOne;
private final List<UUID> teamTwo;
private final boolean ranked;
private final boolean tournament;
private Player t1l;
private Player t2l;
private PracticeProfile t1lp;
private PracticeProfile t2lp;
private List<UUID> spectators = new ArrayList<>();
private List<UUID> dead = new ArrayList<>();
private List<Item> items = new ArrayList<>();
private List<UUID> exempt = new ArrayList<>();
private Arena arena;
private long startTime = 0;
private long endTime = 0;
private MatchState matchState = MatchState.STARTING;
private boolean party;
public void start() {
t1l = this.plugin.getServer().getPlayer(teamOne.get(0));
if (teamTwo != null) t2l = this.plugin.getServer().getPlayer(teamTwo.get(0));
t1lp = this.plugin.getManagerHandler().getProfileManager().getProfile(t1l);
if (teamTwo != null) t2lp = this.plugin.getManagerHandler().getProfileManager().getProfile(t2l);
party = t1lp.getPlayerState() == PlayerState.PARTY || teamTwo != null && t2lp.getPlayerState() == PlayerState.PARTY;
arena = (kit != null ? this.plugin.getManagerHandler().getArenaManager().randomArena(kit) : this.plugin.getManagerHandler().getArenaManager().randomArena(KitType.HCF));
arena.getL1().getChunk().load();
teamOne.forEach(u -> {
Player player = this.plugin.getServer().getPlayer(u);
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
if (teamTwo != null) {
player.sendMessage(ranked ? Messages.RANKED_MATCH_FOUND.getMessage().replace("%player%", t2l.getName() + (party ? "'s Team" : "")).replace("%elo%", String.valueOf(t2lp.getElo(kit))).replace("%kit%", kit != null ? kit.getName() : "HCF") : Messages.UNRANKED_MATCH_FOUND.getMessage().replace("%player%", t2l.getName() + (party ? "'s Team" : "")).replace("%kit%", kit != null ? kit.getName() : "HCF"));
hide(player);
} else {
player.sendMessage(Messages.PARTY_FFA_STARTING.getMessage());
}
this.plugin.getManagerHandler().getPlayerManager().resetPlayer(player);
this.plugin.getManagerHandler().getPlayerManager().hideAll(player);
if (kit != null) {
boolean hasKits = false;
for (int i = 1; i <= 7; i++) {
if (practiceProfile.getCustomKit(kit, i) != null) {
hasKits = true;
CustomKit customKit = practiceProfile.getCustomKit(kit, i);
ItemStack clone = Items.CUSTOM_KIT.getItem().clone();
String name = customKit.getName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
player.getInventory().setItem(i - 1, new ItemBuilder(clone.getType()).setDurability(clone.getDurability()).setName(name).toItemStack());
}
}
if (!hasKits) {
player.getInventory().setContents(kit.getInventory().getContents());
player.getInventory().setArmorContents(kit.getArmor());
} else {
player.getInventory().setItem(8, Items.DEFAULT_KIT.getItem());
}
} else {
player.getInventory().setContents(practiceProfile.getHcfKit().getInventory().getContents());
player.getInventory().setArmorContents(practiceProfile.getHcfKit().getArmor());
switch (practiceProfile.getHcfKit()) {
case BARD: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1));
new BardTask(this.plugin, player).runTaskTimer(this.plugin, 0L, 0L);
break;
}
case ARCHER: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
break;
}
case ROGUE: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
break;
}
}
}
player.updateInventory();
player.teleport(arena.getL1());
if (kit != null) player.setMaximumNoDamageTicks(kit.getDamageTicks());
ScoreHelper scoreHelper = ScoreHelper.getByPlayer(player);
teamOne.forEach(u1 -> {
Player player1 = this.plugin.getServer().getPlayer(u1);
player.showPlayer(player1);
if (teamTwo != null) {
scoreHelper.addFriendly(player1);
} else {
scoreHelper.addEnemy(player1);
player.showPlayer(player1);
}
});
if (teamTwo != null) teamTwo.forEach(u1 -> {
Player player1 = this.plugin.getServer().getPlayer(u1);
player.showPlayer(player1);
scoreHelper.addEnemy(player1);
});
});
if (teamTwo != null) {
arena.getL2().getChunk().load();
teamTwo.forEach(u -> {
Player player = this.plugin.getServer().getPlayer(u);
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
player.sendMessage(ranked ? Messages.RANKED_MATCH_FOUND.getMessage().replace("%player%", t1l.getName() + (party ? "'s Team" : "")).replace("%elo%", String.valueOf(t1lp.getElo(kit))).replace("%kit%", kit != null ? kit.getName() : "HCF") : Messages.UNRANKED_MATCH_FOUND.getMessage().replace("%player%", t1l.getName() + (party ? "'s Team" : "")).replace("%kit%", kit != null ? kit.getName() : "HCF"));
hide(player);
this.plugin.getManagerHandler().getPlayerManager().resetPlayer(player);
this.plugin.getManagerHandler().getPlayerManager().hideAll(player);
if (kit != null) {
boolean hasKits = false;
for (int i = 1; i <= 7; i++) {
if (practiceProfile.getCustomKit(kit, i) != null) {
hasKits = true;
CustomKit customKit = practiceProfile.getCustomKit(kit, i);
ItemStack clone = Items.CUSTOM_KIT.getItem().clone();
String name = customKit.getName().replace("%kit%", kit.getName()).replace("%number%", String.valueOf(i));
player.getInventory().setItem(i - 1, new ItemBuilder(clone.getType()).setDurability(clone.getDurability()).setName(name).toItemStack());
}
}
if (!hasKits) {
player.getInventory().setContents(kit.getInventory().getContents());
player.getInventory().setArmorContents(kit.getArmor());
} else {
player.getInventory().setItem(8, Items.DEFAULT_KIT.getItem());
}
} else {
player.getInventory().setContents(practiceProfile.getHcfKit().getInventory().getContents());
player.getInventory().setArmorContents(practiceProfile.getHcfKit().getArmor());
switch (practiceProfile.getHcfKit()) {
case BARD: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1));
new BardTask(this.plugin, player).runTaskTimer(this.plugin, 0L, 0L);
break;
}
case ARCHER: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
break;
}
case ROGUE: {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
break;
}
}
}
player.updateInventory();
player.teleport(arena.getL2());
if (kit != null) player.setMaximumNoDamageTicks(kit.getDamageTicks());
ScoreHelper scoreHelper = ScoreHelper.getByPlayer(player);
teamTwo.forEach(u1 -> {
Player player1 = this.plugin.getServer().getPlayer(u1);
player.showPlayer(player1);
scoreHelper.addFriendly(player1);
});
teamOne.forEach(u1 -> {
Player player1 = this.plugin.getServer().getPlayer(u1);
player.showPlayer(player1);
scoreHelper.addEnemy(player1);
});
});
}
new BukkitRunnable() {
int i = 5;
public void run() {
if (matchState != MatchState.STARTING) {
this.cancel();
return;
}
if (i > 0) {
broadcast(Messages.MATCH_STARTING.getMessage().replace("%time%", String.valueOf(i)));
playSound(Sound.NOTE_STICKS);
}
i--;
if (i == -1) {
this.cancel();
broadcast(Messages.MATCH_STARTED.getMessage());
playSound(Sound.NOTE_PLING);
matchState = MatchState.STARTED;
startTime = System.currentTimeMillis();
return;
}
}
}.runTaskTimerAsynchronously(this.plugin, 20L, 20L);
}
public void addDeath(Player player, MatchDeathReason matchDeathReason, Player killer) {
if (dead.contains(player.getUniqueId()) || matchState == MatchState.ENDING) return;
dead.add(player.getUniqueId());
player.setGameMode(GameMode.CREATIVE);
List<UUID> allPlayers = new ArrayList<>();
teamOne.forEach(allPlayers::add);
if (teamTwo != null) teamTwo.forEach(allPlayers::add);
spectators.forEach(allPlayers::add);
if (this.plugin.getManagerHandler().getSettingsManager().isLightningEffect())
BukkitReflection.sendLightning(player, player.getLocation());
allPlayers.stream().filter(u -> !exempt.contains(u)).forEach(u -> {
Player players = this.plugin.getServer().getPlayer(u);
players.hidePlayer(player);
if (this.plugin.getManagerHandler().getSettingsManager().isLightningEffect())
BukkitReflection.sendLightning(players, player.getLocation());
});
new InventorySnapshot(player);
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
this.plugin.getManagerHandler().getPlayerManager().resetPlayer(player);
}, 5L);
switch (matchDeathReason) {
case DISCONNECTED: {
broadcast(Messages.PLAYER_DEATH_DISCONNECTED.getMessage().replace("%player%", player.getName()));
exempt.add(player.getUniqueId());
break;
}
case KILLED: {
broadcast(Messages.PLAYER_DEATH_KILLED.getMessage().replace("%player%", player.getName()).replace("%killer%", killer.getName()));
break;
}
case DIED: {
broadcast(Messages.PLAYER_DEATH_DIED.getMessage().replace("%player%", player.getName()));
break;
}
case LEFT: {
broadcast(Messages.PLAYER_DEATH_LEFT.getMessage().replace("%player%", player.getName()));
exempt.add(player.getUniqueId());
break;
}
}
if (getAlive(true) == (teamTwo == null ? 1 : 0)) end(teamTwo == null);
if (teamTwo != null && getAlive(false) == 0) end(true);
}
public void end(boolean t1) {
if (matchState == MatchState.ENDING) return;
matchState = MatchState.ENDING;
endTime = System.currentTimeMillis();
String[] parts = Messages.MATCH_END.getMessage().split("\n");
TextComponent winnerNames = new TextComponent("");
(t1 ? teamOne : teamTwo).forEach(u -> {
if ((teamTwo == null && !dead.contains(u)) || teamTwo != null) {
OfflinePlayer offlinePlayer = this.plugin.getServer().getOfflinePlayer(u);
TextComponent winnerName = new TextComponent(CC.GREEN + offlinePlayer.getName());
winnerName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Messages.INVENTORY_HOVER.getMessage().replace("%player%", offlinePlayer.getName())).create()));
winnerName.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/inventory " + offlinePlayer.getName()));
winnerNames.addExtra(winnerName);
winnerNames.addExtra(" ");
}
});
TextComponent loserNames = new TextComponent("");
(t1 ? teamTwo != null ? teamTwo : dead : teamOne).forEach(u -> {
OfflinePlayer offlinePlayer = this.plugin.getServer().getOfflinePlayer(u);
TextComponent loserName = new TextComponent(CC.RED + offlinePlayer.getName());
loserName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Messages.INVENTORY_HOVER.getMessage().replace("%player%", offlinePlayer.getName())).create()));
loserName.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/inventory " + offlinePlayer.getName()));
loserNames.addExtra(loserName);
loserNames.addExtra(" ");
});
Map<Integer, TextComponent> excluded = new HashMap<>();
for (String part : parts) {
if (CC.strip(part).contains("%winnerNames%")) {
String[] breakdown = part.split("%winnerNames%");
TextComponent textComponent = null;
if (!CC.strip(part).equalsIgnoreCase("%winnerNames%")) {
textComponent = new TextComponent(CC.translate(breakdown[0]));
textComponent.addExtra(winnerNames);
if (breakdown.length >= 1) {
for (int i = 1; i < breakdown.length; i++) {
if (i > 1) {
textComponent.addExtra(winnerNames);
}
textComponent.addExtra(breakdown[i]);
}
}
} else {
textComponent = winnerNames;
}
excluded.put(Arrays.asList(parts).indexOf(part), textComponent);
}
}
for (String part : parts) {
if (CC.strip(part).contains("%loserNames%")) {
String[] breakdown = part.split("%loserNames%");
TextComponent textComponent = null;
if (!CC.strip(part).equalsIgnoreCase("%loserNames%")) {
textComponent = new TextComponent(CC.translate(breakdown[0]));
textComponent.addExtra(loserNames);
if (breakdown.length >= 1) {
for (int i = 1; i < breakdown.length; i++) {
if (i > 1) {
textComponent.addExtra(loserNames);
}
textComponent.addExtra(breakdown[i]);
}
}
} else {
textComponent = loserNames;
}
excluded.put(Arrays.asList(parts).indexOf(part), textComponent);
}
}
for (int i = 0; i < parts.length; i++) {
if (excluded.containsKey(i)) {
broadcast(excluded.get(i));
} else {
broadcast(parts[i]);
}
}
if (ranked) {
int[] newElo = EloUtil.getNewRankings(t1lp.getElo(kit), t2lp.getElo(kit), t1);
int eloDifference = Math.abs(newElo[0] - t1lp.getElo(kit));
t1lp.setElo(kit, newElo[0] <= this.plugin.getManagerHandler().getSettingsManager().getMinElo() ? this.plugin.getManagerHandler().getSettingsManager().getMinElo() : (newElo[0] >= this.plugin.getManagerHandler().getSettingsManager().getMaxElo() ? this.plugin.getManagerHandler().getSettingsManager().getMaxElo() : newElo[0]));
t2lp.setElo(kit, newElo[1] <= this.plugin.getManagerHandler().getSettingsManager().getMinElo() ? this.plugin.getManagerHandler().getSettingsManager().getMinElo() : (newElo[1] >= this.plugin.getManagerHandler().getSettingsManager().getMaxElo() ? this.plugin.getManagerHandler().getSettingsManager().getMaxElo() : newElo[1]));
Player winner = t1 ? t1l : t2l;
PracticeProfile wp = this.plugin.getManagerHandler().getProfileManager().getProfile(winner);
Player loser = t1 ? t2l : t1l;
PracticeProfile lp = this.plugin.getManagerHandler().getProfileManager().getProfile(loser);
String eloChanges = Messages.ELO_CHANGES.getMessage().replace("%winner%", winner.getName()).replace("%loser%", loser.getName()).replace("%newWinnerElo%", String.valueOf(wp.getElo(kit))).replace("%newLoserElo%", String.valueOf(lp.getElo(kit))).replace("%eloDifference%", String.valueOf(eloDifference));
broadcast(eloChanges);
}
List<UUID> allPlayers = new ArrayList<>();
teamOne.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
if (teamTwo != null) teamTwo.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
spectators.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
for (UUID uuid : allPlayers) {
Player player = this.plugin.getServer().getPlayer(uuid);
new InventorySnapshot(player);
}
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
items.forEach(Item::remove);
allPlayers.stream().forEach(u -> {
Player player = this.plugin.getServer().getPlayer(u);
if (kit != null) teamOne.stream().forEach(u1 -> kit.getUnrankedMatch().remove(u1));
if (kit != null) teamOne.stream().forEach(u1 -> kit.getRankedMatch().remove(u1));
if (teamTwo != null && kit != null) teamTwo.stream().forEach(u1 -> kit.getUnrankedMatch().remove(u1));
if (teamTwo != null && kit != null) teamTwo.stream().forEach(u1 -> kit.getRankedMatch().remove(u1));
if (player != null) {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setHits(0);
practiceProfile.setCombo(0);
practiceProfile.setLongestCombo(0);
practiceProfile.setThrownPots(0);
practiceProfile.setFullyLandedPots(0);
practiceProfile.setPlayerState(practiceProfile.getParty() != null ? PlayerState.PARTY : PlayerState.LOBBY);
practiceProfile.setPlayerState(practiceProfile.getParty() != null ? PlayerState.PARTY : PlayerState.LOBBY);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
ScoreHelper scoreHelper = ScoreHelper.getByPlayer(player);
scoreHelper.resetEnemy();
scoreHelper.resetFriendly();
if (party) {
Party p1 = t1lp.getParty();
if (p1 != null) {
p1.setPartyState(PartyState.LOBBY);
p1.setMatch(null);
}
if (teamTwo != null) {
Party p2 = t2lp.getParty();
if (p2 != null) {
p2.setPartyState(PartyState.LOBBY);
p2.setMatch(null);
}
}
}
return;
}
});
if (tournament) {
Tournament tournament = this.plugin.getManagerHandler().getTournamentManager().getTournament();
tournament.getMatchList().remove(this);
tournament.broadcast(Messages.PLAYER_ELIMINATED_TOURNAMENT.getMessage().replace("%player%", (t1 ? t2l : t1l).getName()));
tournament.getParticipants().remove(t1 ? t2l.getUniqueId() : t1l.getUniqueId());
(t1 ? t1lp : t2lp).setPlayerState(PlayerState.TOURNAMENT);
this.plugin.getManagerHandler().getPlayerManager().giveItems(t1 ? t1l : t2l, true);
if (tournament.getParticipants().size() == 1) {
Player winner = this.plugin.getServer().getPlayer(tournament.getParticipants().get(0));
tournament.end(winner.getName());
} else if (tournament.getParticipants().size() == 0) {
tournament.end(null);
} else if (tournament.getMatchList().size() == 0) {
tournament.setStartTime(0);
tournament.setRound(tournament.getRound() + 1);
tournament.setTournamentState(TournamentState.WAITING);
this.plugin.getServer().broadcastMessage(Messages.TOURNAMENT_NEXT_ROUND.getMessage().replace("%round%", String.valueOf(tournament.getRound())));
this.plugin.getManagerHandler().getTournamentManager().next();
}
}
}, 60L);
}
public int getAlive(boolean t1) {
int alive = 0;
for (UUID uuid : t1 ? teamOne : teamTwo) {
if (!dead.contains(uuid)) alive += 1;
}
return alive;
}
public void broadcast(String message) {
List<UUID> allPlayers = new ArrayList<>();
teamOne.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
if (teamTwo != null) teamTwo.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
spectators.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
allPlayers.stream().filter(u -> this.plugin.getServer().getPlayer(u) != null).forEach(u -> this.plugin.getServer().getPlayer(u).sendMessage(message));
}
public void broadcast(TextComponent message) {
List<UUID> allPlayers = new ArrayList<>();
teamOne.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
if (teamTwo != null) teamTwo.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
spectators.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
allPlayers.stream().filter(u -> this.plugin.getServer().getPlayer(u) != null).forEach(u -> this.plugin.getServer().getPlayer(u).spigot().sendMessage(message));
}
public void playSound(Sound sound) {
List<UUID> allPlayers = new ArrayList<>();
teamOne.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
if (teamTwo != null) teamTwo.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
spectators.stream().filter(u -> !exempt.contains(u)).forEach(allPlayers::add);
allPlayers.stream().filter(u -> this.plugin.getServer().getPlayer(u) != null).forEach(u -> this.plugin.getServer().getPlayer(u).playSound(this.plugin.getServer().getPlayer(u).getLocation(), sound, 20f, 20f));
}
private void hide(Player player) {
this.plugin.getServer().getOnlinePlayers().stream().filter(p -> !teamOne.contains(((Player) p).getUniqueId()) && !teamTwo.contains(((Player) p).getUniqueId()) && !spectators.contains(((Player) p).getUniqueId())).forEach(player::hidePlayer);
}
}

View File

@ -0,0 +1,6 @@
package me.abhi.practice.match;
public enum MatchDeathReason {
KILLED, DIED, DISCONNECTED, LEFT
}

View File

@ -0,0 +1,18 @@
package me.abhi.practice.match;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.kit.Kit;
import java.util.UUID;
@Getter
@RequiredArgsConstructor
public class MatchRequest {
private final UUID requester;
private final Kit kit;
private final boolean party;
private long timestamp = System.currentTimeMillis();
}

View File

@ -0,0 +1,7 @@
package me.abhi.practice.match;
public enum MatchState {
STARTING, STARTED, ENDING
}

View File

@ -0,0 +1,34 @@
package me.abhi.practice.party;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.match.Match;
import me.abhi.practice.match.MatchRequest;
import net.md_5.bungee.api.chat.TextComponent;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Getter
@Setter
public class Party {
private UUID leader;
private PartyState partyState = PartyState.LOBBY;
private Match match;
private List<UUID> members = new ArrayList<>();
private boolean open;
private List<MatchRequest> matchRequestList = new ArrayList<>();
private Party dueling;
public void broadcast(String message) {
members.forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).sendMessage(message));
}
public void broadcast(TextComponent message) {
members.forEach(u -> PracticePlugin.getInstance().getServer().getPlayer(u).spigot().sendMessage(message));
}
}

View File

@ -0,0 +1,12 @@
package me.abhi.practice.party;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public class PartyInvite {
private final Party party;
private long timestamp = System.currentTimeMillis();
}

View File

@ -0,0 +1,6 @@
package me.abhi.practice.party;
public enum PartyState {
LOBBY, QUEUE, MATCH
}

View File

@ -0,0 +1,12 @@
package me.abhi.practice.player;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class LeaderboardPlayer {
private String name;
private int elo;
}

View File

@ -0,0 +1,6 @@
package me.abhi.practice.player;
public enum PlayerState {
LOBBY, QUEUE, PARTY, MATCH, EDITING, EVENT, TOURNAMENT, SPECTATING, SPECTATING_EVENT
}

View File

@ -0,0 +1,113 @@
package me.abhi.practice.player;
import lombok.Getter;
import lombok.Setter;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.hostedevent.HostedEvent;
import me.abhi.practice.kit.CustomKit;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.match.Match;
import me.abhi.practice.match.MatchRequest;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyInvite;
import me.abhi.practice.queue.Queue;
import me.abhi.practice.tournament.Tournament;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
public class PracticeProfile {
private boolean openInventory;
private Kit editInv;
private boolean scoreboard = true;
private PlayerState playerState = PlayerState.LOBBY;
private Queue queue;
private Party party;
private Match match;
private long lastEnderpearl;
private Map<Kit, Integer> eloMap = new HashMap<>();
private Kit editing;
private Map<Kit, ArrayList<CustomKit>> customKitMap = new HashMap<>();
private Inventory editLayoutInventory;
private Inventory hcfKitSelectorInventory;
private CustomKit settingName;
private List<PartyInvite> partyInviteList = new ArrayList<>();
private Match spectating;
private boolean buildMode;
private HCFKit hcfKit = HCFKit.DIAMOND;
private List<MatchRequest> matchRequestList = new ArrayList<>();
private Player dueling;
private long lastBardBuff;
private double bardEnergy;
private List<String> activeBardItems = new ArrayList<>();
private List<PotionEffect> potionEffectsList = new ArrayList<>();
private long lastArcherSpeedBuff;
private long lastArcherJumpBuff;
private long lastArcherMark;
private long lastRogueSpeedBuff;
private long lastRogueJumpBuff;
private long lastRogueBackstab;
private HostedEvent hostedEvent;
private Tournament tournament;
private boolean viewingPlayerInv;
private boolean silentMode;
private boolean duelRequests = true;
private int hits;
private int combo;
private int longestCombo;
private int thrownPots;
private int fullyLandedPots;
public int getElo(Kit kit) {
return eloMap.getOrDefault(kit, PracticePlugin.getInstance().getManagerHandler().getSettingsManager().getDefaultElo());
}
public void setElo(Kit kit, int elo) {
eloMap.put(kit, elo);
}
public CustomKit getCustomKit(Kit kit, int number) {
CustomKit customKit = null;
if (customKitMap.containsKey(kit)) {
for (CustomKit customKits : customKitMap.get(kit)) {
if (customKits.getNumber() == number) customKit = customKits;
}
}
return customKit;
}
public void setCustomKit(Kit kit, CustomKit customKit) {
ArrayList<CustomKit> customKits = customKitMap.getOrDefault(kit, new ArrayList<>());
customKits.add(customKit);
customKitMap.put(kit, customKits);
}
public void removeCustomKit(Kit kit, int number) {
CustomKit customKit = getCustomKit(kit, number);
ArrayList<CustomKit> customKits = customKitMap.getOrDefault(kit, new ArrayList<>());
customKits.remove(customKit);
customKitMap.put(kit, customKits);
}
public PotionEffect getPotionEffect(PotionEffectType potionEffectType) {
PotionEffect potionEffect = null;
for (PotionEffect potionEffects : potionEffectsList) {
if (potionEffects.getType().getName().equalsIgnoreCase(potionEffectType.getName()))
potionEffect = potionEffects;
}
return potionEffect;
}
}

View File

@ -0,0 +1,21 @@
package me.abhi.practice.queue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import me.abhi.practice.kit.Kit;
@Getter
@RequiredArgsConstructor
public class Queue {
private final Kit kit;
private final boolean ranked;
private final long startTime;
@Setter
private int minElo;
@Setter
private int maxElo;
}

View File

@ -0,0 +1,38 @@
package me.abhi.practice.task;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.concurrent.TimeUnit;
@AllArgsConstructor
public class EnderpearlTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getOnlinePlayers().stream().forEach(p -> {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(p);
if (practiceProfile.getLastEnderpearl() != 0) {
int difference = 16 - (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - practiceProfile.getLastEnderpearl());
p.setLevel(difference);
p.setExp(p.getExp() - 0.003125f);
if (System.currentTimeMillis() >= practiceProfile.getLastEnderpearl() + 16000) {
practiceProfile.setLastEnderpearl(0);
p.setLevel(0);
p.setExp(0f);
p.sendMessage(Messages.MAY_PEARL_AGAIN.getMessage());
}
}
});
}
}

View File

@ -0,0 +1,181 @@
package me.abhi.practice.task;
import com.mongodb.client.MongoCursor;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.player.LeaderboardPlayer;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Menus;
import me.abhi.practice.util.misc.ItemBuilder;
import org.bson.Document;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
@SuppressWarnings("Duplicates")
@AllArgsConstructor
public class InventoryTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().filter(k -> k.isUnranked()).forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.UNRANKED.getItemLore()) {
lore.add(itemLore.replace("%queue%", String.valueOf(k.getUnrankedQueue().size())).replace("%rankedMatch%", String.valueOf(k.getRankedMatch().size())).replace("%rankedQueue%", String.valueOf(k.getRankedQueue().size())).replace("%match%", String.valueOf(k.getUnrankedMatch().size())).replace("%kit%", k.getName()));
}
Menus.UNRANKED.getInventory().setItem(getUnrankedIndex(k), new ItemBuilder(k.getDisplay().getType(), k.getUnrankedMatch().size()).setDurability(k.getDisplay().getDurability()).setName(Menus.UNRANKED.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().filter(k -> k.isRanked()).forEach(k -> {
if (k.isUnranked()) {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.RANKED.getItemLore()) {
lore.add(itemLore.replace("%queue%", String.valueOf(k.getRankedQueue().size())).replace("%unrankedMatch%", String.valueOf(k.getUnrankedMatch().size())).replace("%unrankedQueue%", String.valueOf(k.getUnrankedQueue().size())).replace("%match%", String.valueOf(k.getRankedMatch().size())).replace("%kit%", k.getName()));
}
this.plugin.getManagerHandler().getKitManager().getKitsList().indexOf(k);
Menus.RANKED.getInventory().setItem(getRankedIndex(k), new ItemBuilder(k.getDisplay().getType(), k.getRankedMatch().size()).setDurability(k.getDisplay().getDurability()).setName(Menus.RANKED.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
}
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().filter(k -> k.isEditable()).forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.EDITKIT.getItemLore()) {
lore.add(itemLore.replace("%kit%", k.getName()));
}
Menus.EDITKIT.getInventory().setItem(getEditIndex(k), new ItemBuilder(k.getDisplay().getType(), 1).setDurability(k.getDisplay().getDurability()).setName(Menus.EDITKIT.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.PARTYFFA.getItemLore()) {
lore.add(itemLore.replace("%kit%", k.getName()));
}
Menus.PARTYFFA.getInventory().setItem(this.plugin.getManagerHandler().getKitManager().getKitsList().indexOf(k), new ItemBuilder(k.getDisplay().getType(), 1).setDurability(k.getDisplay().getDurability()).setName(Menus.PARTYFFA.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.PARTYSPLIT.getItemLore()) {
lore.add(itemLore.replace("%kit%", k.getName()));
}
Menus.PARTYSPLIT.getInventory().setItem(this.plugin.getManagerHandler().getKitManager().getKitsList().indexOf(k), new ItemBuilder(k.getDisplay().getType(), 1).setDurability(k.getDisplay().getDurability()).setName(Menus.PARTYSPLIT.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.DUEL.getItemLore()) {
lore.add(itemLore.replace("%kit%", k.getName()));
}
Menus.DUEL.getInventory().setItem(this.plugin.getManagerHandler().getKitManager().getKitsList().indexOf(k), new ItemBuilder(k.getDisplay().getType(), 1).setDurability(k.getDisplay().getDurability()).setName(Menus.DUEL.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
this.plugin.getManagerHandler().getKitManager().getKitsList().stream().forEach(k -> {
List<String> lore = new ArrayList<>();
for (String itemLore : Menus.TOURNAMENT.getItemLore()) {
lore.add(itemLore.replace("%kit%", k.getName()));
}
Menus.TOURNAMENT.getInventory().setItem(this.plugin.getManagerHandler().getKitManager().getKitsList().indexOf(k), new ItemBuilder(k.getDisplay().getType(), 1).setDurability(k.getDisplay().getDurability()).setName(Menus.TOURNAMENT.getItemPrefix() + k.getName()).setLore(lore).toItemStack());
});
updateLeaderboards();
}
public int getUnrankedIndex(Kit kit) {
int i = -1;
for (Kit k : this.plugin.getManagerHandler().getKitManager().getKitsList()) {
if (k.isUnranked()) {
i += 1;
if (k == kit) {
return i;
}
}
}
return 100;
}
public int getRankedIndex(Kit kit) {
int i = -1;
for (Kit k : this.plugin.getManagerHandler().getKitManager().getKitsList()) {
if (k.isRanked()) {
i += 1;
if (k == kit) {
return i;
}
}
}
return 100;
}
public int getEditIndex(Kit kit) {
int i = -1;
for (Kit k : this.plugin.getManagerHandler().getKitManager().getKitsList()) {
if (k.isEditable()) {
i += 1;
if (k == kit) {
return i;
}
}
}
return 100;
}
private void updateLeaderboards() {
if (!this.plugin.getManagerHandler().getSettingsManager().isLeaderboardsGUI()) {
return;
}
for (Kit kit : this.plugin.getManagerHandler().getKitManager().getKitsList()) {
if (!kit.isRanked()) {
continue;
}
List<LeaderboardPlayer> leaderboardPlayers = new ArrayList<>();
this.plugin.getServer().getOnlinePlayers().forEach(p -> {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(p);
leaderboardPlayers.add(new LeaderboardPlayer(p.getName(), practiceProfile.getElo(kit)));
});
MongoCursor<Document> practiceDocuments = this.plugin.getManagerHandler().getMongoManager().getMongoDatabase().getCollection(kit.getName()).find().iterator();
while (practiceDocuments.hasNext()) {
Document playerDocument = practiceDocuments.next();
UUID uuid = UUID.fromString(playerDocument.getString("uuid"));
if (this.plugin.getServer().getPlayer(uuid) == null) {
String username = playerDocument.getString("username");
int elo = playerDocument.getInteger("elo");
leaderboardPlayers.add(new LeaderboardPlayer(username, elo));
}
}
int start = 0;
int end = 9;
leaderboardPlayers.sort(Comparator.comparing(LeaderboardPlayer::getElo));
Collections.reverse(leaderboardPlayers);
List<String> lore = new ArrayList<>();
for (int i = start; i <= end; i++) {
if (i < leaderboardPlayers.size()) {
LeaderboardPlayer leaderboardPlayer = leaderboardPlayers.get(i);
lore.add(this.plugin.getConfig().getString("leaderboards-lore").replace("%pos%", String.valueOf(i + 1)).replace("%player%", leaderboardPlayer.getName()).replace("%elo%", String.valueOf(leaderboardPlayer.getElo())));
}
}
Menus.LEADERBOARDS.getInventory().setItem(getRankedIndex(kit), new ItemBuilder(kit.getDisplay()).setName(Menus.LEADERBOARDS.getItemPrefix() + kit.getName()).setLore(lore).toItemStack());
}
}
}

View File

@ -0,0 +1,16 @@
package me.abhi.practice.task;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class MongoTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getOnlinePlayers().forEach(this.plugin.getManagerHandler().getPlayerManager()::save);
}
}

View File

@ -0,0 +1,16 @@
package me.abhi.practice.task;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class ScoreboardTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getOnlinePlayers().stream().forEach(this.plugin.getManagerHandler().getScoreboardManager()::update);
}
}

View File

@ -0,0 +1,16 @@
package me.abhi.practice.task;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class WorldTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getWorlds().stream().forEach(w -> w.setStorm(false));
}
}

View File

@ -0,0 +1,29 @@
package me.abhi.practice.task.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class ArcherMarkTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getOnlinePlayers().stream().forEach(p -> {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(p);
if (practiceProfile.getLastArcherMark() != 0) {
if (System.currentTimeMillis() >= practiceProfile.getLastArcherMark() + 15000) {
practiceProfile.setLastArcherMark(0);
p.sendMessage(Messages.NO_LONGER_ARCHER_MARKED.getMessage());
}
}
});
}
}

View File

@ -0,0 +1,65 @@
package me.abhi.practice.task.player;
import lombok.RequiredArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.event.impl.BardHoldItemEvent;
import me.abhi.practice.event.impl.BardTaskUpdateEvent;
import me.abhi.practice.kit.hcf.HCFKit;
import me.abhi.practice.kit.hcf.data.bard.BardData;
import me.abhi.practice.kit.hcf.data.bard.BardItem;
import me.abhi.practice.match.Match;
import me.abhi.practice.party.Party;
import me.abhi.practice.party.PartyState;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@RequiredArgsConstructor
public class BardTask extends BukkitRunnable {
private final PracticePlugin plugin;
private final Player player;
private int i;
private BardData bardData = new BardData();
@Override
public void run() {
if (!player.isOnline()) {
this.cancel();
return;
}
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(player);
i += 1;
if (i % 10 == 0) {
practiceProfile.setBardEnergy(practiceProfile.getBardEnergy() + 1 >= 100 ? 100 : practiceProfile.getBardEnergy() + 1);
}
BardItem bardItem = bardData.getBardItemList().stream().filter(b -> player.getItemInHand().getType() == b.getMaterial()).findFirst().orElse(null);
if (bardItem != null) {
new BardHoldItemEvent(player, bardItem).call();
}
new BardTaskUpdateEvent(player).call();
if (practiceProfile.getPlayerState() != PlayerState.PARTY) {
this.cancel();
return;
}
Party party = practiceProfile.getParty();
if (party.getPartyState() != PartyState.MATCH) {
this.cancel();
return;
}
Match match = party.getMatch();
if (match.getKit() != null || practiceProfile.getHcfKit() != HCFKit.BARD || match.getDead().contains(player.getUniqueId())) {
this.cancel();
return;
}
}
}

View File

@ -0,0 +1,29 @@
package me.abhi.practice.task.player;
import lombok.AllArgsConstructor;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class RogueBackstabTask extends BukkitRunnable {
private final PracticePlugin plugin;
@Override
public void run() {
this.plugin.getServer().getOnlinePlayers().stream().forEach(p -> {
PracticeProfile practiceProfile = this.plugin.getManagerHandler().getProfileManager().getProfile(p);
if (practiceProfile.getLastRogueBackstab() != 0) {
if (System.currentTimeMillis() >= practiceProfile.getLastRogueBackstab() + 6000) {
practiceProfile.setLastRogueBackstab(0);
p.sendMessage(Messages.MAY_BACKSTAB_AGAIN.getMessage());
}
}
});
}
}

View File

@ -0,0 +1,106 @@
package me.abhi.practice.tournament;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import me.abhi.practice.PracticePlugin;
import me.abhi.practice.kit.Kit;
import me.abhi.practice.match.Match;
import me.abhi.practice.player.PlayerState;
import me.abhi.practice.player.PracticeProfile;
import me.abhi.practice.util.ListUtil;
import me.abhi.practice.util.enums.Messages;
import org.bukkit.entity.Player;
import java.util.*;
@Setter
@Getter
@RequiredArgsConstructor
public class Tournament {
private final PracticePlugin plugin;
private final Kit kit;
private TournamentState tournamentState = TournamentState.STARTING;
private int round = 1;
private List<Match> matchList = new ArrayList<>();
private List<UUID> participants = new ArrayList<>();
private Random random = new Random();
private long down;
private long startTime;
public void startRound() {
if (participants.size() == 0) {
end(null);
return;
}
if (participants.size() == 1) {
end(this.plugin.getServer().getPlayer(participants.get(0)).getName());
return;
}
UUID sitout = null;
if (participants.size() % 2 != 0) {
sitout = participants.get(random.nextInt(participants.size()));
}
List<UUID> l1 = new ArrayList<>(participants);
List<UUID> l2 = new ArrayList<>();
if (sitout != null) {
l1.remove(sitout);
Player player = this.plugin.getServer().getPlayer(sitout);
player.sendMessage(Messages.TOURNAMENT_SITOUT.getMessage());
}
Collections.shuffle(l1);
for (int i = 0; i < (l1.size() / 2); i++) {
l2.add(l1.get(i));
l1.remove(l1.get(i));
}
if (l2.size() != l1.size()) {
end(null);
return;
}
for (int i = 0; i < l1.size(); i++) {
if (l1.get(i) != l2.get(i)) {
Match match = new Match(this.plugin, kit, ListUtil.newList(l1.get(i)), ListUtil.newList(l2.get(i)), false, true);
matchList.add(match);
match.start();
Player p1 = this.plugin.getServer().getPlayer(l1.get(i));
PracticeProfile p1p = this.plugin.getManagerHandler().getProfileManager().getProfile(p1);
p1p.setMatch(match);
p1p.setPlayerState(PlayerState.MATCH);
kit.getUnrankedMatch().add(p1.getUniqueId());
Player p2 = this.plugin.getServer().getPlayer(l2.get(i));
PracticeProfile p2p = this.plugin.getManagerHandler().getProfileManager().getProfile(p2);
p2p.setMatch(match);
p2p.setPlayerState(PlayerState.MATCH);
kit.getUnrankedMatch().add(p2.getUniqueId());
}
}
}
public void end(String winner) {
this.plugin.getServer().broadcastMessage(winner != null ? Messages.TOURNAMENT_WINNER.getMessage().replace("%player%", winner).replace("%kit%", kit.getName()) : Messages.TOURNAMENT_CANCELLED.getMessage().replace("%kit%", kit.getName()));
participants.forEach(u -> {
Player player = PracticePlugin.getInstance().getServer().getPlayer(u);
PracticeProfile practiceProfile = PracticePlugin.getInstance().getManagerHandler().getProfileManager().getProfile(player);
practiceProfile.setPlayerState(PlayerState.LOBBY);
practiceProfile.setTournament(null);
this.plugin.getManagerHandler().getPlayerManager().giveItems(player, true);
this.plugin.getManagerHandler().getPlayerManager().teleportSpawn(player);
});
this.plugin.getManagerHandler().getTournamentManager().setTournament(null);
}
public void broadcast(String message) {
participants.forEach(u -> this.plugin.getServer().getPlayer(u).sendMessage(message));
}
}

View File

@ -0,0 +1,6 @@
package me.abhi.practice.tournament;
public enum TournamentState {
STARTING, STARTED, WAITING
}

View File

@ -0,0 +1,46 @@
package me.abhi.practice.util;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("Duplicates")
public class DurationUtil {
private static DecimalFormat decimalFormat = new DecimalFormat("00");
public static String getDuration(long startTime) {
int difference = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
int h = difference / 3600;
int s = difference % 60;
int m = difference / 60 % 60;
return (startTime > 0) ? (h > 0 ? decimalFormat.format(h) + ":" : "") + decimalFormat.format(m) + ":" + decimalFormat.format(s) : "00:00";
}
public static String getDuration(long startTime, long endTime) {
int difference = (int) TimeUnit.MILLISECONDS.toSeconds(endTime - startTime);
int h = difference / 3600;
int s = difference % 60;
int m = difference / 60 % 60;
return (startTime > 0) ? (h > 0 ? decimalFormat.format(h) + ":" : "") + decimalFormat.format(m) + ":" + decimalFormat.format(s) : "00:00";
}
public static String getDurationDown(long start, int i) {
long time = i - (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start));
long seconds = time % 60;
long minutes = time / 60 % 60;
long hours = (time / 60) / 60;
DecimalFormat decimalFormat = new DecimalFormat("00");
String toReturn = decimalFormat.format(minutes) + ":" + decimalFormat.format(seconds);
if (hours > 0) {
toReturn = decimalFormat.format(hours) + ":" + toReturn;
}
return toReturn;
}
}

View File

@ -0,0 +1,35 @@
package me.abhi.practice.util;
public class EloUtil {
private static double[] getEstimations(double rankingA, double rankingB) {
double[] ret = new double[2];
double estA = 1.0 / (1.0 + Math.pow(10.0, (rankingB - rankingA) / 400.0));
double estB = 1.0 / (1.0 + Math.pow(10.0, (rankingA - rankingB) / 400.0));
ret[0] = estA;
ret[1] = estB;
return ret;
}
private static int getConstant(int ranking) {
if (ranking < 1400) {
return 32;
}
if (ranking >= 1400 && ranking < 1800) {
return 24;
}
if (ranking >= 1800 && ranking < 2400) {
return 16;
}
return 0;
}
public static int[] getNewRankings(int rankingA, int rankingB, boolean victoryA) {
int[] elo = new int[2];
double[] estimates = getEstimations(rankingA, rankingB);
int newRankA = (int) (rankingA + getConstant(rankingA) * ((victoryA ? 1 : 0) - estimates[0]));
elo[0] = Math.round((float) newRankA);
elo[1] = Math.round((float) (rankingB - (newRankA - rankingA)));
return elo;
}
}

View File

@ -0,0 +1,168 @@
package me.abhi.practice.util;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class InventoryUtil {
/**
* Converts the player inventory to a String array of Base64 strings. First string is the content and second string is the armor.
*
* @param playerInventory to turn into an array of strings.
* @return Array of strings: [ main content, armor content ]
* @throws IllegalStateException
*/
public static String[] playerInventoryToBase64(PlayerInventory playerInventory) throws IllegalStateException {
//get the main content part, this doesn't return the armor
String content = toBase64(playerInventory);
String armor = itemStackArrayToBase64(playerInventory.getArmorContents());
return new String[]{content, armor};
}
/**
* A method to serialize an {@link ItemStack} array to Base64 String.
* <p>
* <p/>
* <p>
* Based off of {@link #toBase64(Inventory)}.
*
* @param items to turn into a Base64 String.
* @return Base64 string of the items.
* @throws IllegalStateException
*/
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(items.length);
// Save every element in the list
for (int i = 0; i < items.length; i++) {
dataOutput.writeObject(items[i]);
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
/**
* A method to serialize an inventory to Base64 string.
* <p>
* <p/>
* <p>
* Special thanks to Comphenix in the Bukkit forums or also known
* as aadnk on GitHub.
*
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
*
* @param inventory to serialize
* @return Base64 string of the provided inventory
* @throws IllegalStateException
*/
public static String toBase64(Inventory inventory) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
/**
* A method to get an {@link Inventory} from an encoded, Base64, string.
* <p>
* <p/>
* <p>
* Special thanks to Comphenix in the Bukkit forums or also known
* as aadnk on GitHub.
*
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
*
* @param data Base64 string of data containing an inventory.
* @return Inventory created from the Base64 string.
* @throws IOException
*/
public static Inventory fromBase64(String data) {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
// Read the serialized inventory
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, (ItemStack) dataInput.readObject());
}
dataInput.close();
return inventory;
} catch (Exception e) {
}
return null;
}
/**
* Gets an array of ItemStacks from Base64 string.
* <p>
* <p/>
* <p>
* Base off of {@link #fromBase64(String)}.
*
* @param data Base64 string to convert to ItemStack array.
* @return ItemStack array created from the Base64 string.
* @throws IOException
*/
public static ItemStack[] itemStackArrayFromBase64(String data) {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
ItemStack[] items = new ItemStack[dataInput.readInt()];
// Read the serialized inventory
for (int i = 0; i < items.length; i++) {
items[i] = (ItemStack) dataInput.readObject();
}
dataInput.close();
return items;
} catch (Exception ex) {
}
return null;
}
public static Inventory cloneInventory(Inventory inventory) {
Inventory clone = Bukkit.createInventory(null, inventory.getSize(), inventory.getName());
clone.setContents(inventory.getContents());
return clone;
}
public static ItemStack[] cloneArmor(ItemStack[] armor) {
return armor.clone();
}
}

Some files were not shown because too many files have changed in this diff Show More