Skip to content

Commit 6697c53

Browse files
committed
Code changes, removed useless stuff
1 parent bbf25fa commit 6697c53

23 files changed

Lines changed: 52 additions & 66 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
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.3</version>
9+
<version>1.6.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CombatPlus</name>

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import me.nik.combatplus.files.Lang;
77
import me.nik.combatplus.files.commentedfiles.CommentedFileConfiguration;
88
import me.nik.combatplus.listeners.GuiListener;
9-
import me.nik.combatplus.managers.MsgType;
109
import me.nik.combatplus.managers.PapiHook;
1110
import me.nik.combatplus.managers.UpdateChecker;
1211
import me.nik.combatplus.metrics.MetricsLite;
@@ -26,12 +25,10 @@
2625
import me.nik.combatplus.modules.impl.GoldenAppleCooldown;
2726
import me.nik.combatplus.modules.impl.HealthBar;
2827
import me.nik.combatplus.modules.impl.HideToolFlags;
29-
import me.nik.combatplus.utils.ChatUtils;
3028
import org.bukkit.Bukkit;
3129
import org.bukkit.ChatColor;
3230
import org.bukkit.attribute.Attribute;
3331
import org.bukkit.event.HandlerList;
34-
import org.bukkit.plugin.PluginManager;
3532
import org.bukkit.plugin.java.JavaPlugin;
3633

3734
import java.util.ArrayList;
@@ -122,17 +119,12 @@ public void onEnable() {
122119

123120
this.modules.forEach(Module::load);
124121

125-
//Load Listeners
126-
PluginManager pm = this.getServer().getPluginManager();
127-
128122
//GUI Listener (Do not remove this, idiot nik)
129-
pm.registerEvents(new GuiListener(), this);
123+
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
130124

131125
//Check for Updates
132126
if (Config.Setting.CHECK_FOR_UPDATES.getBoolean()) {
133127
new UpdateChecker(this).runTaskAsynchronously(this);
134-
} else {
135-
ChatUtils.consoleMessage(MsgType.CONSOLE_UPDATE_DISABLED.getMessage());
136128
}
137129

138130
//Load bStats
@@ -146,14 +138,8 @@ public void onEnable() {
146138
Bukkit.getPluginManager().callEvent(new CombatPlusLoadEvent());
147139
}
148140

149-
public Module getModule(String name) {
150-
for (Module module : this.modules) {
151-
if (module.getName().equals(name)) {
152-
return module;
153-
}
154-
}
155-
156-
return null;
141+
public Module getModule(Class<? extends Module> clazz) {
142+
return this.modules.stream().filter(module -> module.getClass().equals(clazz)).findFirst().orElse(null);
157143
}
158144

159145
public CommentedFileConfiguration getConfiguration() {

src/main/java/me/nik/combatplus/files/Lang.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public void addDefaults() {
6161
get().addDefault("gui_combat", "&c&lCombat Settings");
6262
get().addDefault("gui_general", "&c&lGeneral Settings");
6363
get().addDefault("console_update_not_found", "&6&lNo updates are found, You're running the Latest Version <3");
64-
get().addDefault("console_update_disabled", "&f&lUpdate Checker is Disabled, Skipping.");
6564
get().addDefault("console_commands", "&c&lYou cannot run this command through the console :(");
6665
}
6766
}

src/main/java/me/nik/combatplus/managers/MsgType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public enum MsgType {
2525
GUI_COMBAT(ChatUtils.format(CombatPlus.getInstance().getLang().get().getString("gui_combat"))),
2626
GUI_GENERAL(ChatUtils.format(CombatPlus.getInstance().getLang().get().getString("gui_general"))),
2727
CONSOLE_UPDATE_NOT_FOUND(PREFIX.getMessage() + ChatUtils.format(CombatPlus.getInstance().getLang().get().getString("console_update_not_found"))),
28-
CONSOLE_UPDATE_DISABLED(PREFIX.getMessage() + ChatUtils.format(CombatPlus.getInstance().getLang().get().getString("console_update_disabled"))),
2928
CONSOLE_COMMANDS(PREFIX.getMessage() + ChatUtils.format(CombatPlus.getInstance().getLang().get().getString("console_commands")));
3029

3130
private final String message;

src/main/java/me/nik/combatplus/managers/PapiHook.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
44
import me.nik.combatplus.CombatPlus;
5+
import me.nik.combatplus.modules.impl.CombatLog;
56
import me.nik.combatplus.modules.impl.EnchantedGoldenAppleCooldown;
67
import me.nik.combatplus.modules.impl.EnderpearlCooldown;
78
import me.nik.combatplus.modules.impl.GoldenAppleCooldown;
@@ -45,22 +46,26 @@ public String onRequest(OfflinePlayer player, String identifier) {
4546

4647
switch (identifier) {
4748
case "goldenapple":
48-
GoldenAppleCooldown goldenApple = (GoldenAppleCooldown) this.plugin.getModule("Golden Apple Cooldown");
49+
GoldenAppleCooldown goldenApple = (GoldenAppleCooldown) this.plugin.getModule(GoldenAppleCooldown.class);
4950
if (goldenApple == null) return "";
5051
return goldenApple.getCooldown(player.getUniqueId());
52+
5153
case "enchantedgoldenapple":
52-
EnchantedGoldenAppleCooldown enchantedGoldenApple = (EnchantedGoldenAppleCooldown) this.plugin.getModule("Enchanted Golden Apple Cooldown");
54+
EnchantedGoldenAppleCooldown enchantedGoldenApple = (EnchantedGoldenAppleCooldown) this.plugin.getModule(EnchantedGoldenAppleCooldown.class);
5355
if (enchantedGoldenApple == null) return "";
5456
return enchantedGoldenApple.getCooldown(player.getUniqueId());
57+
5558
case "enderpearl":
56-
EnderpearlCooldown enderpearl = (EnderpearlCooldown) this.plugin.getModule("Enderpearl Cooldown");
59+
EnderpearlCooldown enderpearl = (EnderpearlCooldown) this.plugin.getModule(EnderpearlCooldown.class);
5760
if (enderpearl == null) return "";
5861
return enderpearl.getCooldown(player.getUniqueId());
62+
5963
case "combatlog":
60-
me.nik.combatplus.modules.impl.CombatLog combatLog = (me.nik.combatplus.modules.impl.CombatLog) this.plugin.getModule("CombatLog");
64+
CombatLog combatLog = (CombatLog) this.plugin.getModule(CombatLog.class);
6165
if (combatLog == null) return "";
6266
return combatLog.getCooldown(player.getUniqueId());
6367
}
68+
6469
return null;
6570
}
6671
}

src/main/java/me/nik/combatplus/managers/UpdateChecker.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.nik.combatplus.CombatPlus;
44
import me.nik.combatplus.utils.ChatUtils;
5+
import org.bukkit.Bukkit;
56
import org.bukkit.event.EventHandler;
67
import org.bukkit.event.Listener;
78
import org.bukkit.event.player.PlayerJoinEvent;
@@ -25,37 +26,39 @@ public UpdateChecker(CombatPlus plugin) {
2526

2627
@Override
2728
public void run() {
29+
2830
try {
29-
newVersion = readLines();
31+
32+
URLConnection connection = new URL("https://raw.githubusercontent.com/NikV2/CombatPlus/master/version.txt").openConnection();
33+
34+
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
35+
36+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
37+
38+
final String line = reader.readLine();
39+
40+
reader.close();
41+
42+
this.newVersion = line;
43+
3044
} catch (IOException e) {
3145
plugin.getLogger().warning("Couldn't check for updates, Is the server connected to the internet?");
3246
return;
3347
}
3448

3549
if (!plugin.getDescription().getVersion().equals(newVersion)) {
36-
ChatUtils.consoleMessage(MsgType.UPDATE_REMINDER.getMessage().replaceAll("%current%", plugin.getDescription().getVersion()).replaceAll("%new%", newVersion));
37-
plugin.getServer().getPluginManager().registerEvents(this, plugin);
38-
} else {
39-
ChatUtils.consoleMessage(MsgType.CONSOLE_UPDATE_NOT_FOUND.getMessage());
40-
}
41-
}
42-
43-
private String readLines() throws IOException {
44-
URLConnection connection = new URL("https://raw.githubusercontent.com/NikV2/CombatPlus/master/version.txt").openConnection();
45-
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
46-
47-
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
50+
ChatUtils.consoleMessage(MsgType.UPDATE_REMINDER.getMessage()
51+
.replace("%current%", plugin.getDescription().getVersion())
52+
.replace("%new%", newVersion));
4853

49-
final String line = reader.readLine();
50-
51-
reader.close();
52-
53-
return line;
54+
Bukkit.getPluginManager().registerEvents(this, plugin);
55+
} else ChatUtils.consoleMessage(MsgType.CONSOLE_UPDATE_NOT_FOUND.getMessage());
5456
}
5557

5658
@EventHandler
5759
public void onJoin(final PlayerJoinEvent e) {
5860
if (!e.getPlayer().hasPermission(Permissions.ADMIN.getPermission())) return;
61+
5962
e.getPlayer().sendMessage(MsgType.UPDATE_REMINDER.getMessage()
6063
.replace("%current%", plugin.getDescription().getVersion())
6164
.replace("%new%", newVersion));

src/main/java/me/nik/combatplus/modules/Module.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@
1313
public class Module implements Listener {
1414

1515
private final boolean enabled;
16-
private final String name;
1716

18-
public Module(String name, boolean enabled) {
19-
this.name = name;
17+
public Module(boolean enabled) {
2018
this.enabled = enabled;
2119
}
2220

23-
public String getName() {
24-
return name;
25-
}
26-
2721
public void load() {
2822
if (!this.enabled) return;
2923
Bukkit.getPluginManager().registerEvents(this, CombatPlus.getInstance());
@@ -36,7 +30,7 @@ public void shutdown() {
3630

3731
protected void debug(Player player, String information) {
3832
if (Config.Setting.DEVELOPER_MODE.getBoolean() && player.hasPermission(Permissions.DEBUG.getPermission())) {
39-
player.sendMessage(MsgType.PREFIX.getMessage() + this.name + ChatUtils.format(" &f&l>> &r" + information));
33+
player.sendMessage(MsgType.PREFIX.getMessage() + this.getClass().getSimpleName() + ChatUtils.format(" &f&l>> &r" + information));
4034
}
4135
}
4236
}

src/main/java/me/nik/combatplus/modules/impl/Blocking.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Blocking extends Module {
2222
private final ExpiringMap<UUID, Long> blocking = new ExpiringMap<>(5000L);
2323

2424
public Blocking() {
25-
super("Sword Blocking", Config.Setting.SWORD_BLOCKING_ENABLED.getBoolean());
25+
super(Config.Setting.SWORD_BLOCKING_ENABLED.getBoolean());
2626
}
2727

2828
@EventHandler(priority = EventPriority.MONITOR)

src/main/java/me/nik/combatplus/modules/impl/CombatLog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class CombatLog extends Module {
3131
private final Map<UUID, Long> taggedPlayers = new ConcurrentHashMap<>();
3232

3333
public CombatLog() {
34-
super("CombatLog", Config.Setting.COMBATLOG_ENABLED.getBoolean());
34+
super(Config.Setting.COMBATLOG_ENABLED.getBoolean());
3535

3636
TaskUtils.taskTimerAsync(() -> this.taggedPlayers.keySet().forEach(uuid -> {
3737

src/main/java/me/nik/combatplus/modules/impl/CustomAttackSpeed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class CustomAttackSpeed extends Module {
1616

1717
public CustomAttackSpeed() {
18-
super("Custom Attack Speed", Config.Setting.CUSTOM_ATTACK_SPEED_ENABLED.getBoolean());
18+
super(Config.Setting.CUSTOM_ATTACK_SPEED_ENABLED.getBoolean());
1919
}
2020

2121
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

0 commit comments

Comments
 (0)