Skip to content

Commit b9776b5

Browse files
committed
Added API
1 parent 68ff032 commit b9776b5

7 files changed

Lines changed: 96 additions & 13 deletions

File tree

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.6</version>
9+
<version>1.6.7</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CombatPlus</name>

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.nik.combatplus;
22

3+
import me.nik.combatplus.api.CombatPlusAPI;
4+
import me.nik.combatplus.api.CombatPlusAPIProvider;
5+
import me.nik.combatplus.api.events.CombatPlusAPIBackend;
36
import me.nik.combatplus.api.events.CombatPlusLoadEvent;
47
import me.nik.combatplus.commands.CommandManager;
58
import me.nik.combatplus.files.Config;
@@ -45,6 +48,8 @@ public final class CombatPlus extends JavaPlugin {
4548

4649
private final List<Module> modules = new ArrayList<>();
4750

51+
private static CombatPlusAPI api;
52+
4853
public static CombatPlus getInstance() {
4954
return instance;
5055
}
@@ -79,11 +84,21 @@ public void onDisable() {
7984
instance = null;
8085
}
8186

87+
public static CombatPlusAPI getApi() {
88+
return api;
89+
}
90+
91+
public Module getModule(Class<? extends Module> clazz) {
92+
return this.modules.stream().filter(module -> module.getClass().equals(clazz)).findFirst().orElse(null);
93+
}
94+
8295
@Override
8396
public void onEnable() {
8497

8598
instance = this;
8699

100+
CombatPlusAPIProvider.register(api = new CombatPlusAPIBackend(this));
101+
87102
//Load Files
88103
this.config.setup();
89104
this.lang.setup(this);
@@ -138,10 +153,6 @@ public void onEnable() {
138153
Bukkit.getPluginManager().callEvent(new CombatPlusLoadEvent());
139154
}
140155

141-
public Module getModule(Class<? extends Module> clazz) {
142-
return this.modules.stream().filter(module -> module.getClass().equals(clazz)).findFirst().orElse(null);
143-
}
144-
145156
public CommentedFileConfiguration getConfiguration() {
146157
return config.getConfig();
147158
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package me.nik.combatplus.api;
22

3-
public class CombatPlusAPI {
4-
//Empty for now
3+
import java.util.UUID;
4+
5+
public interface CombatPlusAPI {
6+
7+
/**
8+
* Tag a player from the combat log
9+
*
10+
* @param uuid the player's uuid
11+
*/
12+
void tagPlayer(UUID uuid);
13+
14+
/**
15+
* Untag a player from the combat log
16+
*
17+
* @param uuid the player's uuid
18+
*/
19+
void unTagPlayer(UUID uuid);
520
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package me.nik.combatplus.api;
2+
3+
public class CombatPlusAPIProvider {
4+
5+
private static CombatPlusAPI API = null;
6+
7+
public CombatPlusAPIProvider() {
8+
}
9+
10+
public static CombatPlusAPI getAPI() {
11+
return API;
12+
}
13+
14+
@Deprecated
15+
public static void register(CombatPlusAPI api) {
16+
API = api;
17+
}
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.nik.combatplus.api.events;
2+
3+
import me.nik.combatplus.CombatPlus;
4+
import me.nik.combatplus.api.CombatPlusAPI;
5+
import me.nik.combatplus.modules.impl.CombatLog;
6+
7+
import java.util.UUID;
8+
9+
public class CombatPlusAPIBackend implements CombatPlusAPI {
10+
11+
private final CombatPlus plugin;
12+
13+
public CombatPlusAPIBackend(CombatPlus plugin) {
14+
this.plugin = plugin;
15+
}
16+
17+
@Override
18+
public void tagPlayer(UUID uuid) {
19+
20+
CombatLog combatLog = (CombatLog) this.plugin.getModule(CombatLog.class);
21+
22+
if (combatLog != null) combatLog.tagPlayer(uuid);
23+
}
24+
25+
@Override
26+
public void unTagPlayer(UUID uuid) {
27+
28+
CombatLog combatLog = (CombatLog) this.plugin.getModule(CombatLog.class);
29+
30+
if (combatLog != null) combatLog.unTagPlayer(uuid);
31+
}
32+
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public CombatLog() {
4242

4343
if (player == null) {
4444

45-
this.taggedPlayers.remove(uuid);
45+
unTagPlayer(uuid);
4646

4747
return;
4848
}
@@ -64,7 +64,7 @@ private long getSecondsLeft(UUID uuid) {
6464

6565
if (secondsLeft < 1L) {
6666

67-
this.taggedPlayers.remove(uuid);
67+
unTagPlayer(uuid);
6868

6969
return 0L;
7070
}
@@ -84,7 +84,10 @@ public String getCooldown(UUID uuid) {
8484
return "Ready";
8585
}
8686

87-
private void tagPlayer(Player player) {
87+
public void tagPlayer(UUID uuid) {
88+
89+
Player player = Bukkit.getPlayer(uuid);
90+
8891
if (Config.Setting.COMBATLOG_DISABLED_WORLDS.getStringList().stream().anyMatch(world -> world.equals(player.getWorld().getName()))
8992
|| (!Config.Setting.DISABLE_BYPASS_PERMISSIONS.getBoolean()
9093
&& player.hasPermission(Permissions.BYPASS_COMBATLOG.getPermission()))) return;
@@ -107,6 +110,10 @@ private void tagPlayer(Player player) {
107110
debug(player, "&6Tagged");
108111
}
109112

113+
public void unTagPlayer(UUID uuid) {
114+
this.taggedPlayers.remove(uuid);
115+
}
116+
110117
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
111118
public void onCombat(EntityDamageByEntityEvent e) {
112119
if (!(e.getEntity() instanceof LivingEntity)) return;
@@ -142,9 +149,9 @@ public void onCombat(EntityDamageByEntityEvent e) {
142149

143150
if (player == null) return;
144151

145-
tagPlayer(player);
152+
tagPlayer(player.getUniqueId());
146153

147-
if (target instanceof Player) tagPlayer((Player) target);
154+
if (target instanceof Player) tagPlayer(target.getUniqueId());
148155
}
149156

150157
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.6
1+
1.6.7

0 commit comments

Comments
 (0)