Skip to content

Commit 3fa4f58

Browse files
committed
My free plugins need a re-code -_-
1 parent ab064f7 commit 3fa4f58

25 files changed

Lines changed: 197 additions & 270 deletions

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@
2727
import me.nik.combatplus.listeners.combatlog.TeleportListener;
2828
import me.nik.combatplus.listeners.fixes.Projectiles;
2929
import me.nik.combatplus.managers.CombatLog;
30+
import me.nik.combatplus.managers.CustomRecipes;
3031
import me.nik.combatplus.managers.MsgType;
3132
import me.nik.combatplus.metrics.MetricsLite;
32-
import me.nik.combatplus.utils.CustomRecipes;
33-
import me.nik.combatplus.utils.ResetStats;
34-
import me.nik.combatplus.utils.SetAttackSpeed;
35-
import me.nik.combatplus.utils.SetCustomHealth;
33+
import me.nik.combatplus.utils.StatUtils;
3634
import org.bukkit.Bukkit;
3735
import org.bukkit.ChatColor;
3836
import org.bukkit.attribute.Attribute;
3937
import org.bukkit.attribute.AttributeInstance;
38+
import org.bukkit.entity.Player;
4039
import org.bukkit.plugin.PluginManager;
4140
import org.bukkit.plugin.java.JavaPlugin;
4241

42+
import java.util.Collection;
43+
4344
public final class CombatPlus extends JavaPlugin {
4445

4546
private static CombatPlus instance;
@@ -52,6 +53,14 @@ public static CombatPlus getInstance() {
5253
return instance;
5354
}
5455

56+
private final String[] STARTUP_MESSAGE = {
57+
" ",
58+
ChatColor.RED + "Combat Plus v" + this.getDescription().getVersion(),
59+
" ",
60+
ChatColor.WHITE + " Author: Nik",
61+
" "
62+
};
63+
5564
@Override
5665
public void onDisable() {
5766
//Load Default Stats to avoid server damage
@@ -66,6 +75,10 @@ public void onDisable() {
6675
consoleMessage(MsgType.CONSOLE_DISABLED.getMessage());
6776
}
6877

78+
/**
79+
* This needs a re-code, i might do it once im not so lazy
80+
*/
81+
6982
@Override
7083
public void onEnable() {
7184
instance = this;
@@ -76,12 +89,7 @@ public void onEnable() {
7689
//Load Files
7790
loadFiles();
7891

79-
//Startup Message
80-
consoleMessage("");
81-
consoleMessage(" " + ChatColor.RED + "Combat Plus v" + this.getDescription().getVersion());
82-
consoleMessage("");
83-
consoleMessage(" " + ChatColor.WHITE + "Author: Nik");
84-
consoleMessage("");
92+
this.getServer().getConsoleSender().sendMessage(this.STARTUP_MESSAGE);
8593

8694
//Unsupported Version Checker
8795
checkSupported();
@@ -140,7 +148,7 @@ private void checkForUpdates() {
140148
*/
141149
private void setDefaultStats() {
142150
if (serverVersion("1.8")) return;
143-
this.getServer().getOnlinePlayers().forEach(player -> {
151+
Bukkit.getOnlinePlayers().forEach(player -> {
144152
final double defaultHealth = Config.Setting.ADV_BASE_HEALTH.getDouble();
145153
final AttributeInstance playerMaxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
146154
playerMaxHealth.setBaseValue(defaultHealth);
@@ -157,20 +165,20 @@ private void setDefaultStats() {
157165
*/
158166
private void loadStats() {
159167
if (serverVersion("1.8")) return;
160-
SetAttackSpeed setAttackSpeed = new SetAttackSpeed();
161-
ResetStats resetStats = new ResetStats();
162-
SetCustomHealth setCustomHealth = new SetCustomHealth();
163168

169+
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
170+
171+
//Yes i'm using forEach instead of for loop, For this case it doesn't really matter if its faster or heavier so shhh
164172
if (Config.Setting.OLD_PVP.getBoolean()) {
165-
this.getServer().getOnlinePlayers().forEach(setAttackSpeed::setAttackSpd);
173+
players.forEach(StatUtils::setAttackSpeed);
166174
} else {
167-
this.getServer().getOnlinePlayers().forEach(resetStats::resetAttackSpeed);
175+
players.forEach(StatUtils::resetAttackSpeed);
168176
}
169177

170178
if (Config.Setting.CUSTOM_PLAYER_HEALTH_ENABLED.getBoolean()) {
171-
this.getServer().getOnlinePlayers().forEach(setCustomHealth::setHealth);
179+
players.forEach(StatUtils::setMaxHealth);
172180
} else {
173-
this.getServer().getOnlinePlayers().forEach(resetStats::resetMaxHealth);
181+
players.forEach(StatUtils::resetMaxHealth);
174182
}
175183
}
176184

@@ -192,7 +200,7 @@ private void initialize() {
192200
pm.registerEvents(new BowBoost(), this);
193201
}
194202
if (Config.Setting.OLD_REGEN.getBoolean()) {
195-
pm.registerEvents(new PlayerRegen(this), this);
203+
pm.registerEvents(new PlayerRegen(), this);
196204
}
197205
if (Config.Setting.DISABLED_ITEMS_ENABLED.getBoolean()) {
198206
pm.registerEvents(new DisabledItems(), this);
Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package me.nik.combatplus.listeners;
22

33
import me.nik.combatplus.files.Config;
4-
import me.nik.combatplus.utils.ResetStats;
5-
import me.nik.combatplus.utils.SetAttackSpeed;
6-
import me.nik.combatplus.utils.SetCustomHealth;
4+
import me.nik.combatplus.utils.StatUtils;
75
import org.bukkit.event.EventHandler;
86
import org.bukkit.event.Listener;
97
import org.bukkit.event.player.PlayerChangedWorldEvent;
@@ -12,51 +10,35 @@
1210

1311
public class AttributesSet implements Listener {
1412

15-
private final SetAttackSpeed setAttackSpeed = new SetAttackSpeed();
16-
private final ResetStats resetStats = new ResetStats();
17-
private final SetCustomHealth setCustomHealth = new SetCustomHealth();
18-
19-
/*
20-
Changes the attribute of the player to the Old Attack Speed (On Join)
21-
*/
22-
2313
@EventHandler(ignoreCancelled = true)
2414
public void onJoin(PlayerJoinEvent e) {
2515
if (Config.Setting.OLD_PVP.getBoolean()) {
26-
setAttackSpeed.setAttackSpd(e.getPlayer());
16+
StatUtils.setAttackSpeed(e.getPlayer());
2717
} else {
28-
resetStats.resetAttackSpeed(e.getPlayer());
18+
StatUtils.resetAttackSpeed(e.getPlayer());
2919
}
3020

3121
if (Config.Setting.CUSTOM_PLAYER_HEALTH_ENABLED.getBoolean()) {
32-
setCustomHealth.setHealth(e.getPlayer());
22+
StatUtils.setMaxHealth(e.getPlayer());
3323
} else {
34-
resetStats.resetMaxHealth(e.getPlayer());
24+
StatUtils.resetMaxHealth(e.getPlayer());
3525
}
3626

3727
}
3828

39-
/*
40-
Resets the attribute of the player to the New Attack Speed (On Leave)
41-
*/
42-
4329
@EventHandler
4430
public void onLeave(PlayerQuitEvent e) {
4531
if (Config.Setting.OLD_PVP.getBoolean()) {
46-
resetStats.resetAttackSpeed(e.getPlayer());
32+
StatUtils.resetAttackSpeed(e.getPlayer());
4733
}
4834
if (Config.Setting.CUSTOM_PLAYER_HEALTH_ENABLED.getBoolean()) {
49-
resetStats.resetMaxHealth(e.getPlayer());
35+
StatUtils.resetMaxHealth(e.getPlayer());
5036
}
5137
}
5238

53-
/*
54-
Changes the attribute of the player to the Old Attack Speed (On World Change)
55-
*/
56-
5739
@EventHandler(ignoreCancelled = true)
5840
public void onWorldChange(PlayerChangedWorldEvent e) {
5941
if (!Config.Setting.OLD_PVP.getBoolean()) return;
60-
setAttackSpeed.setAttackSpd(e.getPlayer());
42+
StatUtils.setAttackSpeed(e.getPlayer());
6143
}
6244
}

src/main/java/me/nik/combatplus/listeners/Blocking.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.bukkit.event.block.Action;
1212
import org.bukkit.event.entity.EntityDamageByEntityEvent;
1313
import org.bukkit.event.player.PlayerInteractEvent;
14+
import org.bukkit.event.player.PlayerQuitEvent;
1415
import org.bukkit.potion.PotionEffect;
1516
import org.bukkit.potion.PotionEffectType;
1617

@@ -19,9 +20,7 @@
1920

2021
public class Blocking implements Listener {
2122

22-
private static final String[] interactiveBlocks = {"DOOR", "TABLE", "STAND", "CHEST", "GATE", "DISPENSER", "DROPPER", "NOTE", "REDSTONE", "DIODE", "FRAME", "LEVER", "SHULKER", "FURNACE", "BARREL"};
23-
24-
private final WorldUtils worldUtils = new WorldUtils();
23+
private final String[] interactiveBlocks = {"DOOR", "TABLE", "STAND", "CHEST", "GATE", "DISPENSER", "DROPPER", "NOTE", "REDSTONE", "DIODE", "FRAME", "LEVER", "SHULKER", "FURNACE", "BARREL"};
2524

2625
private final HashMap<UUID, Long> blocking = new HashMap<>();
2726

@@ -44,7 +43,7 @@ public void onBlock(PlayerInteractEvent e) {
4443
}
4544

4645
Player p = e.getPlayer();
47-
if (worldUtils.combatDisabledWorlds(p)) return;
46+
if (WorldUtils.combatDisabledWorlds(p)) return;
4847
if (Config.Setting.SWORD_BLOCKING_IGNORE_SHIELDS.getBoolean() && holdsShield(e.getPlayer())) return;
4948

5049
if (Config.Setting.SWORD_BLOCKING_CANCEL_SPRINTING.getBoolean() && p.isSprinting()) {
@@ -74,4 +73,11 @@ public void onInteractWhileBlocking(EntityDamageByEntityEvent e) {
7473
blocking.remove(uuid);
7574
}
7675
}
76+
77+
@EventHandler
78+
public void cleanCache(final PlayerQuitEvent e) {
79+
UUID uuid = e.getPlayer().getUniqueId();
80+
if (!this.blocking.containsKey(uuid)) return;
81+
this.blocking.remove(uuid);
82+
}
7783
}

src/main/java/me/nik/combatplus/listeners/BowBoost.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@
1212

1313
public class BowBoost implements Listener {
1414

15-
private final WorldUtils worldUtils = new WorldUtils();
16-
17-
/*
18-
Disables the ability to Boost yourself up using a Bow, By shooting yourself
19-
This Listener prevents players hitting themselves with a bow
20-
*/
21-
2215
@EventHandler
2316
public void onArrowDamage(EntityDamageByEntityEvent e) {
2417
if (!(e.getEntity() instanceof Player)) return;
2518
if (!(e.getDamager() instanceof Arrow)) return;
2619
Player p = (Player) e.getEntity();
27-
if (worldUtils.combatDisabledWorlds(p)) return;
20+
if (WorldUtils.combatDisabledWorlds(p)) return;
2821
if (p.hasPermission(Permissions.BYPASS_BOWBOOST.getPermission())) return;
2922
Arrow arrow = (Arrow) e.getDamager();
3023
ProjectileSource holder = arrow.getShooter();

src/main/java/me/nik/combatplus/listeners/DamageModifiers.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@
1616

1717
public class DamageModifiers implements Listener {
1818

19-
private final WorldUtils worldUtils = new WorldUtils();
20-
21-
/*
22-
This Listener Changes the Damage Dealt to All Entities to the Old Values
23-
*/
24-
2519
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
2620
public void onEntityDamage(EntityDamageByEntityEvent e) {
2721
if (!(e.getDamager() instanceof Player)) return;
2822
final Player player = (Player) e.getDamager();
29-
if (worldUtils.combatDisabledWorlds(player)) return;
23+
if (WorldUtils.combatDisabledWorlds(player)) return;
3024
final ItemStack handItem = player.getInventory().getItemInMainHand();
3125
final String weapon = handItem.getType().name();
3226
if (Config.Setting.DISABLE_SWEEP_ENABLED.getBoolean() && e.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK)) {

src/main/java/me/nik/combatplus/listeners/DisabledItems.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
public class DisabledItems implements Listener {
1515

16-
/*
17-
This Listener Disables the crafting of the items defined in the Config
18-
*/
19-
2016
@EventHandler
2117
public void onCraft(PrepareItemCraftEvent e) {
2218
if (e.getViewers().size() < 1) return;

src/main/java/me/nik/combatplus/listeners/EnchantedGoldenApple.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@
2323
public class EnchantedGoldenApple implements Listener {
2424

2525
private final CombatPlus plugin;
26-
private final WorldUtils worldUtils = new WorldUtils();
2726

2827
private static final HashMap<UUID, Long> cooldown = new HashMap<>();
2928

3029
public EnchantedGoldenApple(CombatPlus plugin) {
3130
this.plugin = plugin;
3231
}
3332

34-
/*
35-
This Listener adds a cooldown between eating Enchanted Golden Apples
36-
*/
37-
3833
public static String getCooldown(UUID uuid) {
3934
if (cooldown.containsKey(uuid)) {
4035
long secondsleft = ((cooldown.get(uuid) / 1000) + Config.Setting.COOLDOWN_ENCHANTED_APPLE_COOLDOWN.getInt()) - (System.currentTimeMillis() / 1000);
@@ -49,7 +44,7 @@ public static String getCooldown(UUID uuid) {
4944

5045
@EventHandler(ignoreCancelled = true)
5146
public void onEatEnchantedGoldenApple(PlayerItemConsumeEvent e) {
52-
if (worldUtils.gappleDisabledWorlds(e.getPlayer())) return;
47+
if (WorldUtils.gappleDisabledWorlds(e.getPlayer())) return;
5348
if (e.getPlayer().hasPermission(Permissions.BYPASS_GAPPLE.getPermission())) return;
5449
if (isEnchantedGoldenApple(e)) {
5550
final UUID p = e.getPlayer().getUniqueId();

src/main/java/me/nik/combatplus/listeners/Enderpearl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
public class Enderpearl implements Listener {
2525

2626
private final CombatPlus plugin;
27-
private final WorldUtils worldUtils = new WorldUtils();
2827

2928
private static final HashMap<UUID, Long> cooldown = new HashMap<>();
3029

3130
public Enderpearl(CombatPlus plugin) {
3231
this.plugin = plugin;
3332
}
3433

35-
/*
36-
This Listener Adds a cooldown between using Ender Pearls
37-
*/
38-
3934
public static String getCooldown(UUID uuid) {
4035
if (cooldown.containsKey(uuid)) {
4136
long secondsleft = ((cooldown.get(uuid) / 1000) + Config.Setting.ENDERPEARL_COOLDOWN.getInt()) - (System.currentTimeMillis() / 1000);
@@ -53,7 +48,7 @@ public void onLaunch(ProjectileLaunchEvent e) {
5348
if (!(e.getEntity().getShooter() instanceof Player)) return;
5449
if (!(e.getEntity().getType() == EntityType.ENDER_PEARL)) return;
5550
Player player = (Player) e.getEntity().getShooter();
56-
if (worldUtils.enderpearlDisabledWorlds(player)) return;
51+
if (WorldUtils.enderpearlDisabledWorlds(player)) return;
5752
if (player.hasPermission(Permissions.BYPASS_EPEARL.getPermission())) return;
5853
final UUID p = player.getUniqueId();
5954
if (cooldown.containsKey(p)) {

src/main/java/me/nik/combatplus/listeners/FishingRodKnockback.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import me.nik.combatplus.files.Config;
44
import me.nik.combatplus.utils.Messenger;
5-
import me.nik.combatplus.utils.MiscUtils;
65
import org.bukkit.Bukkit;
76
import org.bukkit.GameMode;
7+
import org.bukkit.Location;
88
import org.bukkit.entity.Entity;
99
import org.bukkit.entity.EntityType;
1010
import org.bukkit.entity.FishHook;
@@ -17,12 +17,10 @@
1717
import org.bukkit.event.entity.EntityDamageEvent;
1818
import org.bukkit.event.entity.ProjectileHitEvent;
1919
import org.bukkit.event.player.PlayerFishEvent;
20+
import org.bukkit.util.Vector;
2021

2122
public class FishingRodKnockback implements Listener {
2223

23-
/*
24-
Bring back old fishing rod behavior
25-
*/
2624

2725
@EventHandler(priority = EventPriority.HIGHEST)
2826
public void onRodLand(ProjectileHitEvent e) {
@@ -56,7 +54,7 @@ public void onRodLand(ProjectileHitEvent e) {
5654
Bukkit.getPluginManager().callEvent(event);
5755
if (event.isCancelled()) return;
5856

59-
livingEntity.setVelocity(MiscUtils.calculateVelocity(livingEntity.getVelocity(), livingEntity.getLocation(), hook.getLocation()));
57+
livingEntity.setVelocity(calculateVelocity(livingEntity.getVelocity(), livingEntity.getLocation(), hook.getLocation()));
6058
livingEntity.damage(Config.Setting.ADV_FISHING_ROD_DAMAGE.getDouble());
6159
Messenger.debug(holder, "&3Fishing Rod Knockback &f&l>> &6Velocity: &a" + livingEntity.getVelocity().toString());
6260
}
@@ -79,4 +77,32 @@ public void onHook(PlayerFishEvent e) {
7977
private EntityDamageEvent customEvent(Player rodder, Entity entity, double damage) {
8078
return new EntityDamageByEntityEvent(rodder, entity, EntityDamageEvent.DamageCause.PROJECTILE, damage);
8179
}
80+
81+
private Vector calculateVelocity(Vector vel, Location player, Location loc) {
82+
double xDist = loc.getX() - player.getX();
83+
double zDist = loc.getZ() - player.getZ();
84+
85+
while (xDist * xDist + zDist * zDist < 0.0001) {
86+
xDist = (Math.random() - Math.random()) * 0.01D;
87+
zDist = (Math.random() - Math.random()) * 0.01D;
88+
}
89+
90+
double distance = Math.sqrt(xDist * xDist + zDist * zDist);
91+
92+
double y = vel.getY() / 2;
93+
double x = vel.getX() / 2;
94+
double z = vel.getZ() / 2;
95+
96+
x -= xDist / distance * 0.4;
97+
98+
y += 0.4;
99+
100+
z -= zDist / distance * 0.4;
101+
102+
if (y >= 0.4) {
103+
y = 0.4;
104+
}
105+
106+
return new Vector(x, y, z);
107+
}
82108
}

0 commit comments

Comments
 (0)