Skip to content

Commit 37a1f33

Browse files
committed
Tool flag hider
Custom knockback
1 parent 507155c commit 37a1f33

19 files changed

Lines changed: 580 additions & 283 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.2</version>
9+
<version>1.6.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>CombatPlus</name>

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

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import me.nik.combatplus.modules.impl.CombatLog;
1616
import me.nik.combatplus.modules.impl.CustomAttackSpeed;
1717
import me.nik.combatplus.modules.impl.CustomHealth;
18+
import me.nik.combatplus.modules.impl.CustomPlayerKnockback;
1819
import me.nik.combatplus.modules.impl.CustomPlayerRegeneration;
1920
import me.nik.combatplus.modules.impl.DamageModifiers;
2021
import me.nik.combatplus.modules.impl.DisableBowBoost;
@@ -24,6 +25,7 @@
2425
import me.nik.combatplus.modules.impl.FishingRodKnockback;
2526
import me.nik.combatplus.modules.impl.GoldenAppleCooldown;
2627
import me.nik.combatplus.modules.impl.HealthBar;
28+
import me.nik.combatplus.modules.impl.HideToolFlags;
2729
import me.nik.combatplus.utils.Messenger;
2830
import org.bukkit.Bukkit;
2931
import org.bukkit.ChatColor;
@@ -40,9 +42,9 @@ public final class CombatPlus extends JavaPlugin {
4042

4143
private static CombatPlus instance;
4244

43-
private Config config;
45+
private final Config config = new Config(this);
4446

45-
private Lang lang;
47+
private final Lang lang = new Lang();
4648

4749
private final List<Module> modules = new ArrayList<>();
4850

@@ -85,26 +87,53 @@ public void onEnable() {
8587

8688
instance = this;
8789

88-
this.lang = new Lang();
89-
90-
this.config = new Config(this);
91-
9290
//Load Files
93-
loadFiles();
91+
this.config.setup();
92+
this.lang.setup(this);
93+
this.lang.addDefaults();
94+
this.lang.get().options().copyDefaults(true);
95+
this.lang.save();
9496

9597
this.getServer().getConsoleSender().sendMessage(STARTUP_MESSAGE);
9698

9799
//Load Commands
98100
getCommand("combatplus").setExecutor(new CommandManager(this));
99101

100102
//Load Modules
101-
initModules();
103+
this.modules.clear();
104+
105+
this.modules.addAll(Arrays.asList(
106+
new CustomPlayerRegeneration(),
107+
new CustomAttackSpeed(),
108+
new DisableOffhand(),
109+
new HealthBar(),
110+
new GoldenAppleCooldown(),
111+
new EnchantedGoldenAppleCooldown(),
112+
new FishingRodKnockback(),
113+
new EnderpearlCooldown(),
114+
new DamageModifiers(),
115+
new CustomHealth(),
116+
new CombatLog(),
117+
new DisableBowBoost(),
118+
new Blocking(),
119+
new HideToolFlags(),
120+
new CustomPlayerKnockback()
121+
));
122+
123+
this.modules.forEach(Module::load);
102124

103125
//Load Listeners
104-
initListeners();
126+
PluginManager pm = this.getServer().getPluginManager();
127+
128+
//GUI Listener (Do not remove this, idiot nik)
129+
pm.registerEvents(new GuiListener(), this);
105130

106131
//Check for Updates
107-
checkForUpdates();
132+
if (Config.Setting.CHECK_FOR_UPDATES.getBoolean()) {
133+
new UpdateChecker(this).runTaskAsynchronously(this);
134+
} else {
135+
Messenger.consoleMessage(MsgType.CONSOLE_UPDATE_DISABLED.getMessage());
136+
}
108137

109138
//Load bStats
110139
new MetricsLite(this, 6982);
@@ -134,58 +163,4 @@ public CommentedFileConfiguration getConfiguration() {
134163
public Lang getLang() {
135164
return lang;
136165
}
137-
138-
/**
139-
* Load all the built-in files
140-
*/
141-
private void loadFiles() {
142-
config.setup();
143-
lang.setup(this);
144-
lang.addDefaults();
145-
lang.get().options().copyDefaults(true);
146-
lang.save();
147-
}
148-
149-
private void checkForUpdates() {
150-
if (Config.Setting.CHECK_FOR_UPDATES.getBoolean()) {
151-
new UpdateChecker(this).runTaskAsynchronously(this);
152-
} else {
153-
Messenger.consoleMessage(MsgType.CONSOLE_UPDATE_DISABLED.getMessage());
154-
}
155-
}
156-
157-
private void initModules() {
158-
159-
this.modules.clear();
160-
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);
179-
}
180-
181-
/**
182-
* Initialize enabled Listeners
183-
*/
184-
private void initListeners() {
185-
186-
final PluginManager pm = this.getServer().getPluginManager();
187-
188-
//GUI Listener (Do not remove this, idiot nik)
189-
pm.registerEvents(new GuiListener(), this);
190-
}
191166
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,28 @@ public enum Setting {
125125
DAMAGE_MODIFIERS_CUSTOM_TOOL_DAMAGES_TOOLS_DIAMOND_HOE("damage_modifiers.custom_tool_damages.tools.DIAMOND_HOE", 0),
126126
DAMAGE_MODIFIERS_CUSTOM_TOOL_DAMAGES_TOOLS_NETHERITE_HOE("damage_modifiers.custom_tool_damages.tools.NETHERITE_HOE", 0),
127127

128-
DISABLE_ARROW_BOOST("disable_arrow_boost", true, "Would you like to prevent players from boosting themselves by using Arrows?"),
128+
HIDE_TOOL_FLAGS("hide_tool_flags", true, "Would you like to hide the item flags shown on tools indicating their damage and attack speed?"),
129+
130+
DISABLE_ARROW_BOOST("disable_arrow_boost", false, "Would you like to prevent players from boosting themselves by using Arrows?"),
131+
132+
CUSTOM_PLAYER_KNOCKBACK("custom_player_knockback", "", "Custom player knockback properties"),
133+
CUSTOM_PLAYER_KNOCKBACK_ENABLED("custom_player_knockback.enabled", false, "Should we modify the player's knockback?"),
134+
CUSTOM_PLAYER_KNOCKBACK_FRICTION("custom_player_knockback.friction", 2.0, "The velocity friction to apply"),
135+
CUSTOM_PLAYER_KNOCKBACK_HORIZONTAL("custom_player_knockback.horizontal", 0.35, "The horizontal knockback to apply"),
136+
CUSTOM_PLAYER_KNOCKBACK_EXTRA_HORIZONTAL("custom_player_knockback.extra_horizontal", 0.425, "The extra horizontal knockback to apply"),
137+
CUSTOM_PLAYER_KNOCKBACK_VERTICAL("custom_player_knockback.vertical", 0.35, "The vertical knockback to apply"),
138+
CUSTOM_PLAYER_KNOCKBACK_EXTRA_VERTICAL("custom_player_knockback.extra_vertical", 0.085, "The extra vertical knockback to apply"),
139+
CUSTOM_PLAYER_KNOCKBACK_VERTICAL_LIMIT("custom_player_knockback.vertical_limit", 0.4, "The vertical velocity limit to apply"),
129140

130141
CUSTOM_PLAYER_REGENERATION("custom_player_regeneration", "", "Custom player regeneration properties"),
131-
CUSTOM_PLAYER_REGENERATION_ENABLED("custom_player_regeneration.enabled", true, "Should we modify the player's regeneration?"),
132-
CUSTOM_PLAYER_REGENERATION_FREQUENCY("custom_player_regeneration.frequency", 3, "The regeneration rate", "The default value replicates 1.8 regeneration"),
142+
CUSTOM_PLAYER_REGENERATION_ENABLED("custom_player_regeneration.enabled", false, "Should we modify the player's regeneration?"),
143+
CUSTOM_PLAYER_REGENERATION_FREQUENCY("custom_player_regeneration.frequency", 3, "The regeneration rate (In seconds)", "The default value replicates 1.8 regeneration"),
133144
CUSTOM_PLAYER_REGENERATION_AMOUNT("custom_player_regeneration.amount", 1, "The regeneration amount", "The default value replicates 1.8 regeneration"),
134145
CUSTOM_PLAYER_REGENERATION_EXCHAUSTION("custom_player_regeneration.exchaustion", 3, "The exchaustion amount", "The default value replicates 1.8 regeneration"),
135146

136147
SWORD_BLOCKING("sword_blocking", "", "Sword blocking properties"),
137-
SWORD_BLOCKING_ENABLED("sword_blocking.enabled", false, "Would you like players to get a Resistance and a Slowness Effect if they hold Right Click?"),
148+
SWORD_BLOCKING_ENABLED("sword_blocking.enabled", true, "Would you like players to get a Resistance and a Slowness Effect if they hold Right Click?"),
138149
SWORD_BLOCKING_IGNORE_SHIELDS("sword_blocking.ignore_shields", true, "Should we ignore it if the player is holding a shield on his offhand?"),
139-
SWORD_BLOCKING_CANCEL_SPRINTING("sword_blocking.cancel_sprinting", false, "Should we cancel the player's sprinting?"),
140150
SWORD_BLOCKING_EFFECT("sword_blocking.effect", "DAMAGE_RESISTANCE", "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html"),
141151
SWORD_BLOCKING_DURATION_TICKS("sword_blocking.duration_ticks", 8, "The duration in ticks (20 ticks = 1 second)"),
142152
SWORD_BLOCKING_AMPLIFIER("sword_blocking.amplifier", 0, "The effect amplifier"),

src/main/java/me/nik/combatplus/gui/menus/CombatGui.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public void handleMenu(InventoryClickEvent e) {
6868
getInventory().clear();
6969
setMenuItems();
7070
break;
71+
case 34:
72+
changeConfigBoolean(Config.Setting.CUSTOM_PLAYER_KNOCKBACK_ENABLED.getKey());
73+
getInventory().clear();
74+
setMenuItems();
75+
break;
7176
case 49:
7277
p.closeInventory();
7378
new MainGui(playerMenu, plugin).open();
@@ -138,12 +143,21 @@ protected void setMenuItems() {
138143
blockLore.add("&fRight Clicking With a Sword");
139144
ItemStack block = makeItem(Material.PAPER, 1, "&6Sword Blocking", blockLore);
140145

146+
List<String> kbLore = new ArrayList<>();
147+
kbLore.add("");
148+
kbLore.add("&7Currently set to: &a" + getConfigValue(Config.Setting.CUSTOM_PLAYER_KNOCKBACK_ENABLED.getKey()));
149+
kbLore.add("");
150+
kbLore.add("&fWould you like to use");
151+
kbLore.add("&fCustom player knockback?");
152+
ItemStack kb = makeItem(Material.PAPER, 1, "&6Custom Player Knockback", kbLore);
153+
141154
inventory.setItem(10, customAttackSpeed);
142155
inventory.setItem(12, oldSharpness);
143156
inventory.setItem(14, disableSweep);
144157
inventory.setItem(16, customToolDamages);
145158
inventory.setItem(28, disableBoost);
146159
inventory.setItem(30, customRegen);
147160
inventory.setItem(32, block);
161+
inventory.setItem(34, kb);
148162
}
149163
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
import org.bukkit.event.Listener;
77
import org.bukkit.event.inventory.InventoryClickEvent;
88
import org.bukkit.inventory.InventoryHolder;
9+
import org.bukkit.inventory.ItemStack;
910

1011
public class GuiListener implements Listener {
1112

1213
@EventHandler
13-
public void onClick(final InventoryClickEvent e) {
14+
public void onClick(InventoryClickEvent e) {
1415

1516
InventoryHolder holder = e.getInventory().getHolder();
1617

17-
if (!(holder instanceof Menu)) return;
18+
ItemStack item = e.getCurrentItem();
1819

19-
if (e.getCurrentItem() == null) return;
20-
if (e.getCurrentItem().getType() == Material.AIR) return;
20+
if (!(holder instanceof Menu) || item == null || item.getType() == Material.AIR) return;
2121

2222
e.setCancelled(true);
2323

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919

2020
public class Blocking extends Module {
2121

22-
private final ExpiringMap<UUID, Long> blocking = new ExpiringMap<>(10000L);
22+
private final ExpiringMap<UUID, Long> blocking = new ExpiringMap<>(5000L);
2323

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

28-
@EventHandler(priority = EventPriority.HIGHEST)
28+
@EventHandler(priority = EventPriority.MONITOR)
2929
public void onBlock(PlayerInteractEvent e) {
30-
if (e.getItem() == null || !e.getItem().getType().name().endsWith("_SWORD") || !e.getAction().name().contains("RIGHT_CLICK"))
31-
return;
30+
if (e.getItem() == null
31+
|| !e.getItem().getType().name().endsWith("_SWORD")
32+
|| (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)) return;
3233

3334
Action action = e.getAction();
3435

@@ -43,10 +44,6 @@ public void onBlock(PlayerInteractEvent e) {
4344
if (Config.Setting.SWORD_BLOCKING_IGNORE_SHIELDS.getBoolean() && player.getInventory().getItemInOffHand().getType().name().contains("SHIELD"))
4445
return;
4546

46-
if (Config.Setting.SWORD_BLOCKING_CANCEL_SPRINTING.getBoolean() && player.isSprinting()) {
47-
player.setSprinting(false);
48-
}
49-
5047
player.addPotionEffects(Arrays.asList(
5148
new PotionEffect(PotionEffectType.getByName(Config.Setting.SWORD_BLOCKING_EFFECT.getString()), Config.Setting.SWORD_BLOCKING_DURATION_TICKS.getInt(), Config.Setting.SWORD_BLOCKING_AMPLIFIER.getInt()),
5249
new PotionEffect(PotionEffectType.SLOW, Config.Setting.SWORD_BLOCKING_SLOW_DURATION_TICKS.getInt(), Config.Setting.SWORD_BLOCKING_SLOW_AMPLIFIER.getInt())
@@ -56,13 +53,14 @@ public void onBlock(PlayerInteractEvent e) {
5653

5754
if (!blocking.containsKey(uuid)) blocking.put(uuid, System.currentTimeMillis());
5855

59-
debug(player, "&6Action: &a" + e.getAction());
56+
debug(player, "&6Action: &a" + action.name());
6057
}
6158

6259
@EventHandler
6360
public void onInteractWhileBlocking(EntityDamageByEntityEvent e) {
64-
if (!(e.getDamager() instanceof Player) || e.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK || !this.blocking.containsKey(e.getDamager().getUniqueId()))
65-
return;
61+
if (!(e.getDamager() instanceof Player)
62+
|| e.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK
63+
|| !this.blocking.containsKey(e.getDamager().getUniqueId())) return;
6664

6765
UUID uuid = e.getDamager().getUniqueId();
6866

0 commit comments

Comments
 (0)