Skip to content

Commit b5ab583

Browse files
committed
Many many changes
1 parent d5c64c7 commit b5ab583

55 files changed

Lines changed: 1555 additions & 1535 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CombatPlus.iml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
</content>
2222
<orderEntry type="inheritedJdk" />
2323
<orderEntry type="sourceFolder" forTests="false" />
24-
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT" level="project" />
24+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT" level="project" />
2525
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
26-
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
27-
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
28-
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
29-
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
30-
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.10.9" level="project" />
26+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:31.0.1-jre" level="project" />
27+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
28+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
29+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
30+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.checkerframework:checker-qual:3.12.0" level="project" />
31+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.errorprone:error_prone_annotations:2.7.1" level="project" />
32+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
33+
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.9" level="project" />
34+
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.4" level="project" />
35+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.30" level="project" />
36+
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.11.1" level="project" />
3137
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
3238
</component>
3339
</module>

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.nik</groupId>
88
<artifactId>CombatPlus</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CombatPlus</name>
@@ -79,14 +79,14 @@
7979
<dependency>
8080
<groupId>org.spigotmc</groupId>
8181
<artifactId>spigot-api</artifactId>
82-
<version>1.16.4-R0.1-SNAPSHOT</version>
82+
<version>1.18.2-R0.1-SNAPSHOT</version>
8383
<scope>provided</scope>
8484
</dependency>
8585

8686
<dependency>
8787
<groupId>me.clip</groupId>
8888
<artifactId>placeholderapi</artifactId>
89-
<version>2.10.9</version>
89+
<version>2.11.1</version>
9090
<scope>provided</scope>
9191
</dependency>
9292

src/main/java/me/nik/combatplus/CombatPlus.java

Lines changed: 45 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
import me.nik.combatplus.files.Config;
66
import me.nik.combatplus.files.Lang;
77
import me.nik.combatplus.files.commentedfiles.CommentedFileConfiguration;
8-
import me.nik.combatplus.handlers.PapiHook;
9-
import me.nik.combatplus.handlers.UpdateChecker;
108
import me.nik.combatplus.listeners.GuiListener;
11-
import me.nik.combatplus.managers.CustomRecipes;
129
import me.nik.combatplus.managers.MsgType;
10+
import me.nik.combatplus.managers.PapiHook;
11+
import me.nik.combatplus.managers.UpdateChecker;
1312
import me.nik.combatplus.metrics.MetricsLite;
1413
import me.nik.combatplus.modules.Module;
1514
import me.nik.combatplus.modules.impl.Blocking;
16-
import me.nik.combatplus.modules.impl.BowBoost;
1715
import me.nik.combatplus.modules.impl.CombatLog;
16+
import me.nik.combatplus.modules.impl.CustomAttackSpeed;
1817
import me.nik.combatplus.modules.impl.CustomHealth;
18+
import me.nik.combatplus.modules.impl.CustomPlayerRegeneration;
1919
import me.nik.combatplus.modules.impl.DamageModifiers;
20-
import me.nik.combatplus.modules.impl.DisabledItems;
21-
import me.nik.combatplus.modules.impl.EnchantedGoldenApple;
22-
import me.nik.combatplus.modules.impl.Enderpearl;
20+
import me.nik.combatplus.modules.impl.DisableBowBoost;
21+
import me.nik.combatplus.modules.impl.DisableOffhand;
22+
import me.nik.combatplus.modules.impl.EnchantedGoldenAppleCooldown;
23+
import me.nik.combatplus.modules.impl.EnderpearlCooldown;
2324
import me.nik.combatplus.modules.impl.FishingRodKnockback;
24-
import me.nik.combatplus.modules.impl.GoldenApple;
25+
import me.nik.combatplus.modules.impl.GoldenAppleCooldown;
2526
import me.nik.combatplus.modules.impl.HealthBar;
26-
import me.nik.combatplus.modules.impl.Offhand;
27-
import me.nik.combatplus.modules.impl.OldPvP;
28-
import me.nik.combatplus.modules.impl.PlayerRegen;
27+
import me.nik.combatplus.utils.Messenger;
2928
import org.bukkit.Bukkit;
3029
import org.bukkit.ChatColor;
3130
import org.bukkit.attribute.Attribute;
32-
import org.bukkit.attribute.AttributeInstance;
31+
import org.bukkit.event.HandlerList;
3332
import org.bukkit.plugin.PluginManager;
3433
import org.bukkit.plugin.java.JavaPlugin;
3534

3635
import java.util.ArrayList;
36+
import java.util.Arrays;
3737
import java.util.List;
3838

3939
public final class CombatPlus extends JavaPlugin {
@@ -60,34 +60,39 @@ public static CombatPlus getInstance() {
6060

6161
@Override
6262
public void onDisable() {
63+
6364
//Load Default Stats to avoid server damage
64-
setDefaultStats();
65+
Bukkit.getOnlinePlayers().forEach(player -> {
66+
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(Config.Setting.CUSTOM_PLAYER_HEALTH_DEFAULT_MAX_HEALTH.getDouble());
67+
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(Config.Setting.CUSTOM_ATTACK_SPEED_DEFAULT_ATTACK_SPEED.getDouble());
68+
player.saveData();
69+
});
6570

66-
this.modules.forEach(Module::disInit);
71+
this.modules.forEach(Module::shutdown);
6772

6873
config.reset();
6974
lang.reload();
7075
lang.save();
7176

77+
HandlerList.unregisterAll(this);
78+
this.getServer().getScheduler().cancelTasks(this);
79+
7280
instance = null;
7381
}
7482

75-
/**
76-
* This needs a re-code, i might do it once im not so lazy
77-
* Right now it's the definition of spaghetti code.
78-
*/
79-
8083
@Override
8184
public void onEnable() {
85+
8286
instance = this;
87+
8388
this.lang = new Lang();
8489

8590
this.config = new Config(this);
8691

8792
//Load Files
8893
loadFiles();
8994

90-
this.getServer().getConsoleSender().sendMessage(this.STARTUP_MESSAGE);
95+
this.getServer().getConsoleSender().sendMessage(STARTUP_MESSAGE);
9196

9297
//Load Commands
9398
getCommand("combatplus").setExecutor(new CommandManager(this));
@@ -105,7 +110,6 @@ public void onEnable() {
105110
new MetricsLite(this, 6982);
106111

107112
//Hook PlaceholderAPI
108-
109113
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
110114
new PapiHook(this).register();
111115
}
@@ -146,52 +150,32 @@ private void checkForUpdates() {
146150
if (Config.Setting.CHECK_FOR_UPDATES.getBoolean()) {
147151
new UpdateChecker(this).runTaskAsynchronously(this);
148152
} else {
149-
consoleMessage(MsgType.CONSOLE_UPDATE_DISABLED.getMessage());
153+
Messenger.consoleMessage(MsgType.CONSOLE_UPDATE_DISABLED.getMessage());
150154
}
151155
}
152156

153-
/**
154-
* Default Stats to avoid Server Damage
155-
*/
156-
private void setDefaultStats() {
157-
Bukkit.getOnlinePlayers().forEach(player -> {
158-
final double defaultHealth = Config.Setting.ADV_BASE_HEALTH.getDouble();
159-
final AttributeInstance playerMaxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
160-
playerMaxHealth.setBaseValue(defaultHealth);
161-
final double defaultAttSpd = Config.Setting.ADV_NEW_ATTACK_SPEED.getDouble();
162-
final AttributeInstance playerAttSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
163-
playerAttSpeed.setBaseValue(defaultAttSpd);
164-
player.saveData();
165-
});
166-
}
167-
168157
private void initModules() {
158+
169159
this.modules.clear();
170160

171-
//add modules
172-
this.modules.add(new PlayerRegen());
173-
this.modules.add(new OldPvP());
174-
this.modules.add(new Offhand());
175-
this.modules.add(new HealthBar());
176-
this.modules.add(new GoldenApple());
177-
this.modules.add(new FishingRodKnockback());
178-
this.modules.add(new Enderpearl());
179-
this.modules.add(new EnchantedGoldenApple());
180-
this.modules.add(new DisabledItems());
181-
this.modules.add(new DamageModifiers());
182-
this.modules.add(new CustomHealth());
183-
this.modules.add(new CombatLog());
184-
this.modules.add(new BowBoost());
185-
this.modules.add(new Blocking());
186-
187-
this.modules.forEach(Module::init);
188-
189-
if (Config.Setting.ENCHANTED_APPLE_CRAFTING.getBoolean()) {
190-
try {
191-
this.getServer().addRecipe(new CustomRecipes(this).enchantedGoldenAppleRecipe());
192-
} catch (Exception ignored) {
193-
}
194-
}
161+
//Add modules
162+
this.modules.addAll(Arrays.asList(
163+
new CustomPlayerRegeneration(),
164+
new CustomAttackSpeed(),
165+
new DisableOffhand(),
166+
new HealthBar(),
167+
new GoldenAppleCooldown(),
168+
new EnchantedGoldenAppleCooldown(),
169+
new FishingRodKnockback(),
170+
new EnderpearlCooldown(),
171+
new DamageModifiers(),
172+
new CustomHealth(),
173+
new CombatLog(),
174+
new DisableBowBoost(),
175+
new Blocking()
176+
));
177+
178+
this.modules.forEach(Module::load);
195179
}
196180

197181
/**
@@ -204,11 +188,4 @@ private void initListeners() {
204188
//GUI Listener (Do not remove this, idiot nik)
205189
pm.registerEvents(new GuiListener(), this);
206190
}
207-
208-
/**
209-
* @param message The console message to send to the Server (ChatColor Friendly)
210-
*/
211-
public void consoleMessage(String message) {
212-
this.getServer().getConsoleSender().sendMessage(message);
213-
}
214191
}

src/main/java/me/nik/combatplus/commands/CommandManager.java

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,65 +25,92 @@ public CommandManager(CombatPlus plugin) {
2525
subCommands.add(new Reload(plugin));
2626
}
2727

28+
private static final String INFO_MESSAGE = MsgType.PREFIX.getMessage()
29+
+ ChatColor.GRAY + "You're running "
30+
+ ChatColor.WHITE + CombatPlus.getInstance().getDescription().getName()
31+
+ ChatColor.GRAY + " version "
32+
+ ChatColor.RED + "v" + CombatPlus.getInstance().getDescription().getVersion()
33+
+ ChatColor.GRAY + " by"
34+
+ ChatColor.WHITE + " Nik";
35+
36+
public ArrayList<SubCommand> getSubcommands() {
37+
return subCommands;
38+
}
39+
2840
@Override
2941
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
3042
if (args.length > 0) {
43+
3144
for (int i = 0; i < getSubcommands().size(); i++) {
45+
3246
final SubCommand subCommand = getSubcommands().get(i);
3347

3448
if (args[0].equalsIgnoreCase(subCommand.getName())) {
49+
3550
if (!subCommand.canConsoleExecute() && sender instanceof ConsoleCommandSender) {
51+
3652
sender.sendMessage(MsgType.CONSOLE_COMMANDS.getMessage());
53+
3754
return true;
3855
}
56+
3957
if (!sender.hasPermission(subCommand.getPermission())) {
58+
4059
sender.sendMessage(MsgType.NO_PERMISSION.getMessage());
60+
4161
return true;
4262
}
63+
4364
subCommand.perform(sender, args);
65+
4466
return true;
4567
}
68+
4669
if (args[0].equalsIgnoreCase("help")) {
70+
4771
helpMessage(sender);
72+
4873
return true;
4974
}
5075
}
76+
5177
} else {
52-
pluginInfo(sender);
78+
79+
sender.sendMessage(INFO_MESSAGE);
80+
5381
return true;
5482
}
83+
5584
helpMessage(sender);
56-
return true;
57-
}
5885

59-
public ArrayList<SubCommand> getSubcommands() {
60-
return subCommands;
86+
return true;
6187
}
6288

6389
@Override
6490
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
6591
if (args.length == 1) {
66-
ArrayList<String> subcommandsArgs = new ArrayList<>();
92+
93+
List<String> subcommandsArgs = new ArrayList<>();
94+
6795
for (int i = 0; i < getSubcommands().size(); i++) {
6896
subcommandsArgs.add(getSubcommands().get(i).getName());
6997
}
98+
7099
return subcommandsArgs;
71100
}
101+
72102
return null;
73103
}
74104

75105
private void helpMessage(CommandSender sender) {
76106
sender.sendMessage("");
77107
sender.sendMessage(MsgType.PREFIX.getMessage() + ChatColor.GRAY + "Available Commands");
78108
sender.sendMessage("");
79-
for (int i = 0; i < getSubcommands().size(); i++) {
80-
if (!sender.hasPermission(getSubcommands().get(i).getPermission())) continue;
81-
sender.sendMessage(ChatColor.RED + getSubcommands().get(i).getSyntax() + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + getSubcommands().get(i).getDescription());
82-
}
109+
this.subCommands.stream().filter(subCommand -> sender.hasPermission(subCommand.getPermission()))
110+
.forEach(subCommand -> sender.sendMessage(ChatColor.RED
111+
+ subCommand.getSyntax() + ChatColor.DARK_GRAY
112+
+ " - " + ChatColor.GRAY
113+
+ subCommand.getDescription()));
83114
sender.sendMessage("");
84115
}
85-
86-
private void pluginInfo(CommandSender sender) {
87-
sender.sendMessage(MsgType.PREFIX.getMessage() + ChatColor.GRAY + "You're running " + ChatColor.WHITE + plugin.getDescription().getName() + ChatColor.GRAY + " version " + ChatColor.RED + "v" + plugin.getDescription().getVersion() + ChatColor.GRAY + " by" + ChatColor.WHITE + " Nik");
88-
}
89116
}

src/main/java/me/nik/combatplus/commands/SubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public abstract class SubCommand {
1414

1515
protected abstract String getPermission();
1616

17+
protected abstract int maxArguments();
18+
1719
protected abstract boolean canConsoleExecute();
1820

1921
protected abstract void perform(CommandSender sender, String[] args);

src/main/java/me/nik/combatplus/commands/subcommands/Menu.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package me.nik.combatplus.commands.subcommands;
22

33
import me.nik.combatplus.CombatPlus;
4-
import me.nik.combatplus.Permissions;
54
import me.nik.combatplus.commands.SubCommand;
6-
import me.nik.combatplus.gui.PlayerMenuUtility;
5+
import me.nik.combatplus.gui.PlayerMenu;
76
import me.nik.combatplus.gui.menus.MainGui;
7+
import me.nik.combatplus.managers.Permissions;
88
import org.bukkit.command.CommandSender;
99
import org.bukkit.entity.Player;
1010

@@ -38,17 +38,19 @@ public String getPermission() {
3838
return Permissions.ADMIN.getPermission();
3939
}
4040

41+
@Override
42+
protected int maxArguments() {
43+
return 1;
44+
}
45+
4146
@Override
4247
public boolean canConsoleExecute() {
4348
return false;
4449
}
4550

4651
@Override
4752
public void perform(CommandSender sender, String[] args) {
48-
if (args.length == 1) {
49-
Player player = (Player) sender;
50-
new MainGui(new PlayerMenuUtility(player), plugin).open();
51-
}
53+
new MainGui(new PlayerMenu((Player) sender), plugin).open();
5254
}
5355

5456
@Override

0 commit comments

Comments
 (0)