Skip to content

Commit d5c64c7

Browse files
committed
Finalized (Literally) some stuff.
Some things are now readable. God damn my free plugins need a big re-code. I'm embarassed:|
1 parent 0958980 commit d5c64c7

17 files changed

Lines changed: 183 additions & 59 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.0</version>
9+
<version>1.6.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CombatPlus</name>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void onDisable() {
7474

7575
/**
7676
* This needs a re-code, i might do it once im not so lazy
77+
* Right now it's the definition of spaghetti code.
7778
*/
7879

7980
@Override

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,44 @@ private boolean holdsShield(Player p) {
3232
}
3333

3434
@EventHandler(priority = EventPriority.HIGHEST)
35-
public void onBlock(PlayerInteractEvent e) {
36-
if (e.getItem() == null) return;
35+
public void onBlock(final PlayerInteractEvent e) {
36+
if (e.getItem() == null || !e.getAction().name().contains("RIGHT_CLICK")) return;
37+
3738
Action action = e.getAction();
38-
if (!action.name().contains("RIGHT_CLICK")) return;
3939

4040
final Block block = e.getClickedBlock();
41+
4142
if (action == Action.RIGHT_CLICK_BLOCK && block != null) return;
43+
4244
if (!e.getItem().getType().name().contains("SWORD")) return;
4345

4446
if (block != null && block.getType().isInteractable()) return;
4547

4648
Player p = e.getPlayer();
49+
4750
if (WorldUtils.combatDisabledWorlds(p)) return;
51+
4852
boolean hasShield = holdsShield(p);
53+
4954
if (Config.Setting.SWORD_BLOCKING_IGNORE_SHIELDS.getBoolean() && hasShield) return;
5055

5156
if (Config.Setting.SWORD_BLOCKING_CANCEL_SPRINTING.getBoolean() && p.isSprinting()) {
5257
p.setSprinting(false);
5358
}
59+
5460
p.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Config.Setting.SWORD_BLOCKING_EFFECT.getString()), Config.Setting.SWORD_BLOCKING_DURATION_TICKS.getInt(), Config.Setting.SWORD_BLOCKING_AMPLIFIER.getInt()));
61+
5562
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Config.Setting.SWORD_BLOCKING_SLOW_DURATION_TICKS.getInt(), Config.Setting.SWORD_BLOCKING_SLOW_AMPLIFIER.getInt()));
5663

5764
final UUID uuid = p.getUniqueId();
58-
if (!blocking.containsKey(uuid)) {
59-
blocking.put(uuid, System.currentTimeMillis());
60-
}
65+
66+
if (!blocking.containsKey(uuid)) blocking.put(uuid, System.currentTimeMillis());
67+
6168
debug(p, "&6Action: &a" + action.toString() + " &6Holds Shield: &a" + holdsShield(p));
6269
}
6370

6471
@EventHandler
65-
public void onInteractWhileBlocking(EntityDamageByEntityEvent e) {
72+
public void onInteractWhileBlocking(final EntityDamageByEntityEvent e) {
6673
if (!(e.getDamager() instanceof Player)) return;
6774
UUID uuid = e.getDamager().getUniqueId();
6875
if (blocking.containsKey(uuid)) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,24 @@ public BowBoost() {
1717
}
1818

1919
@EventHandler
20-
public void onArrowDamage(EntityDamageByEntityEvent e) {
20+
public void onArrowDamage(final EntityDamageByEntityEvent e) {
2121
if (!(e.getEntity() instanceof Player)) return;
2222
if (!(e.getDamager() instanceof Arrow)) return;
23+
2324
Player p = (Player) e.getEntity();
25+
2426
if (WorldUtils.combatDisabledWorlds(p)) return;
27+
2528
if (p.hasPermission(Permissions.BYPASS_BOWBOOST.getPermission())) return;
29+
2630
Arrow arrow = (Arrow) e.getDamager();
31+
2732
ProjectileSource holder = arrow.getShooter();
33+
2834
if (holder instanceof Player) {
35+
2936
Player holderPlayer = (Player) holder;
37+
3038
if (p.getUniqueId().equals(holderPlayer.getUniqueId())) {
3139
e.setCancelled(true);
3240
debug(p, "&6Cancelled: &a" + e.isCancelled());

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private void unTagPlayer(Player player) {
116116
//Stuff
117117

118118
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
119-
public void onCombat(EntityDamageByEntityEvent e) {
119+
public void onCombat(final EntityDamageByEntityEvent e) {
120120

121121
final Entity target = e.getEntity();
122122

@@ -158,7 +158,7 @@ public void onCombat(EntityDamageByEntityEvent e) {
158158
}
159159

160160
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
161-
public void onCommand(PlayerCommandPreprocessEvent e) {
161+
public void onCommand(final PlayerCommandPreprocessEvent e) {
162162
if (!Config.Setting.COMBATLOG_COMMANDS_ENABLED.getBoolean()) return;
163163

164164
final Player p = e.getPlayer();
@@ -176,7 +176,7 @@ public void onCommand(PlayerCommandPreprocessEvent e) {
176176
}
177177

178178
@EventHandler(priority = EventPriority.LOWEST)
179-
public void onQuit(PlayerQuitEvent e) {
179+
public void onQuit(final PlayerQuitEvent e) {
180180

181181
final Player p = e.getPlayer();
182182

@@ -191,7 +191,7 @@ public void onQuit(PlayerQuitEvent e) {
191191
}
192192

193193
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
194-
public void onItemDrop(PlayerDropItemEvent e) {
194+
public void onItemDrop(final PlayerDropItemEvent e) {
195195
if (!Config.Setting.COMBATLOG_PREVENT_DROPPING_ITEMS.getBoolean()) return;
196196

197197
final Player p = e.getPlayer();
@@ -203,14 +203,14 @@ public void onItemDrop(PlayerDropItemEvent e) {
203203
}
204204

205205
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
206-
public void onDeath(PlayerDeathEvent e) {
206+
public void onDeath(final PlayerDeathEvent e) {
207207
if (!isTagged(e.getEntity())) return;
208208

209209
unTagPlayer(e.getEntity());
210210
}
211211

212212
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
213-
public void onItemPick(EntityPickupItemEvent e) {
213+
public void onItemPick(final EntityPickupItemEvent e) {
214214
if (!Config.Setting.COMBATLOG_PREVENT_PICKING_ITEMS.getBoolean()) return;
215215
if (!(e.getEntity() instanceof Player)) return;
216216
final Player p = (Player) e.getEntity();
@@ -221,7 +221,7 @@ public void onItemPick(EntityPickupItemEvent e) {
221221
}
222222

223223
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
224-
public void onTeleport(PlayerTeleportEvent e) {
224+
public void onTeleport(final PlayerTeleportEvent e) {
225225
if (!Config.Setting.COMBATLOG_PREVENT_TELEPORTATIONS.getBoolean()) return;
226226
final Player p = e.getPlayer();
227227

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.Bukkit;
88
import org.bukkit.entity.Player;
99
import org.bukkit.event.EventHandler;
10+
import org.bukkit.event.EventPriority;
1011
import org.bukkit.event.player.PlayerJoinEvent;
1112
import org.bukkit.event.player.PlayerQuitEvent;
1213

@@ -15,18 +16,18 @@ public CustomHealth() {
1516
super("Custom Player Health", Config.Setting.CUSTOM_PLAYER_HEALTH_ENABLED.getBoolean());
1617
}
1718

18-
@EventHandler(ignoreCancelled = true)
19-
public void onJoin(PlayerJoinEvent e) {
19+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
20+
public void onJoin(final PlayerJoinEvent e) {
2021
StatUtils.setMaxHealth(e.getPlayer());
2122
}
2223

23-
@EventHandler
24-
public void onLeave(PlayerQuitEvent e) {
24+
@EventHandler(priority = EventPriority.LOWEST)
25+
public void onLeave(final PlayerQuitEvent e) {
2526
StatUtils.resetMaxHealth(e.getPlayer());
2627
}
2728

2829
@EventHandler
29-
public void onStartup(CombatPlusLoadEvent e) {
30+
public void onStartup(final CombatPlusLoadEvent e) {
3031
for (Player p : Bukkit.getOnlinePlayers()) {
3132
if (p == null) continue; //Just in case
3233
StatUtils.setMaxHealth(p);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DamageModifiers() {
2424
}
2525

2626
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
27-
public void onEntityDamage(EntityDamageByEntityEvent e) {
27+
public void onEntityDamage(final EntityDamageByEntityEvent e) {
2828
if (!(e.getDamager() instanceof Player)) return;
2929
final Player player = (Player) e.getDamager();
3030
if (WorldUtils.combatDisabledWorlds(player)) return;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@ public DisabledItems() {
1717
}
1818

1919
@EventHandler
20-
public void onCraft(PrepareItemCraftEvent e) {
20+
public void onCraft(final PrepareItemCraftEvent e) {
2121
if (e.getViewers().size() < 1) return;
22+
2223
Player p = (Player) e.getViewers().get(0);
24+
2325
if (p.hasPermission(Permissions.BYPASS_ITEMS.getPermission())) return;
26+
2427
CraftingInventory inv = e.getInventory();
28+
2529
ItemStack result = inv.getResult();
30+
2631
if (result != null && Config.Setting.DISABLED_ITEMS_LIST.getStringList().contains(result.getType().name().toLowerCase())) {
32+
2733
inv.setResult(null);
34+
2835
p.sendMessage(MsgType.CANNOT_CRAFT_THIS.getMessage());
36+
2937
debug(p, "&6Cancelled: &a" + (inv.getResult() == null));
3038
}
3139
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,33 @@ public String getCooldown(UUID uuid) {
4040
}
4141

4242
@EventHandler(ignoreCancelled = true)
43-
public void onEatEnchantedGoldenApple(PlayerItemConsumeEvent e) {
43+
public void onEatEnchantedGoldenApple(final PlayerItemConsumeEvent e) {
44+
4445
if (WorldUtils.goldenAppleDisabledWorlds(e.getPlayer())) return;
46+
4547
if (e.getPlayer().hasPermission(Permissions.BYPASS_GAPPLE.getPermission())) return;
48+
4649
if (e.getItem().getType() == Material.ENCHANTED_GOLDEN_APPLE) {
50+
4751
final UUID p = e.getPlayer().getUniqueId();
52+
4853
final Player player = e.getPlayer();
54+
4955
if (cooldown.containsKey(p)) {
5056
long secondsleft = ((cooldown.get(p) / 1000) + Config.Setting.ENCHANTED_APPLE_COOLDOWN.getInt()) - (System.currentTimeMillis() / 1000);
5157
if (secondsleft < 1) {
5258
cooldown.remove(p);
5359
return;
5460
}
61+
5562
e.setCancelled(true);
63+
5664
player.sendMessage(MsgType.ENCHANTED_GOLDEN_APPLE_COOLDOWN.getMessage().replaceAll("%seconds%", String.valueOf(secondsleft)));
5765
} else {
5866
cooldown.put(p, System.currentTimeMillis());
67+
5968
debug(player, "&6Added to cooldown");
69+
6070
if (Config.Setting.ENCHANTED_APPLE_ACTIONBAR.getBoolean()) {
6171
new BukkitRunnable() {
6272

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,38 @@ public String getCooldown(UUID uuid) {
4040
}
4141

4242
@EventHandler(ignoreCancelled = true)
43-
public void onLaunch(ProjectileLaunchEvent e) {
43+
public void onLaunch(final ProjectileLaunchEvent e) {
44+
4445
if (!(e.getEntity().getShooter() instanceof Player)) return;
46+
4547
if (!(e.getEntity().getType() == EntityType.ENDER_PEARL)) return;
48+
4649
Player player = (Player) e.getEntity().getShooter();
50+
4751
if (WorldUtils.enderpearlDisabledWorlds(player)) return;
52+
4853
if (player.hasPermission(Permissions.BYPASS_EPEARL.getPermission())) return;
54+
4955
final UUID p = player.getUniqueId();
56+
5057
if (cooldown.containsKey(p)) {
58+
5159
e.setCancelled(true);
60+
5261
long secondsLeft = ((cooldown.get(p) / 1000) + Config.Setting.ENDERPEARL_COOLDOWN.getInt()) - (System.currentTimeMillis() / 1000);
62+
5363
if (secondsLeft < 1) {
5464
cooldown.remove(p);
5565
return;
5666
}
67+
5768
player.sendMessage(MsgType.ENDERPEARL_COOLDOWN.getMessage().replaceAll("%seconds%", String.valueOf(secondsLeft)));
5869
} else {
70+
5971
cooldown.put(p, System.currentTimeMillis());
72+
6073
debug(player, "&6Added to cooldown");
74+
6175
if (Config.Setting.ENDERPEARL_ACTIONBAR.getBoolean()) {
6276
new BukkitRunnable() {
6377
@Override

0 commit comments

Comments
 (0)