Skip to content

Commit 854090f

Browse files
committed
Commit
1 parent 927a7cc commit 854090f

5 files changed

Lines changed: 138 additions & 33 deletions

File tree

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

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import me.nik.combatplus.handlers.PapiHook;
77
import me.nik.combatplus.handlers.UpdateChecker;
88
import me.nik.combatplus.listeners.AttributesSet;
9+
import me.nik.combatplus.listeners.Blocking;
910
import me.nik.combatplus.listeners.BowBoost;
1011
import me.nik.combatplus.listeners.DamageModifiers;
1112
import me.nik.combatplus.listeners.DisabledItems;
@@ -215,54 +216,58 @@ private void initialize() {
215216
if (isEnabled("knockback.fishing_rod.enabled")) {
216217
registerEvent(new FishingRodKnockback());
217218
}
219+
if (isEnabled("combat.settings.sword_blocking.enabled")) {
220+
registerEvent(new Blocking());
221+
}
218222
//GUI Listener (Do not remove this, idiot nik)
219223
registerEvent(new GUIListener(this));
220224
}
221225

222226
private void checkSupported() {
223227
if (serverVersion("1.8")) {
224-
Config.get().set("combat.settings.old_pvp", false);
225-
Config.get().set("combat.settings.old_weapon_damage", false);
226-
Config.get().set("combat.settings.old_tool_damage", false);
227-
Config.get().set("combat.settings.old_sharpness", false);
228-
Config.get().set("combat.settings.disable_sweep_attacks.enabled", false);
229-
Config.get().set("combat.settings.old_player_regen", false);
230-
Config.get().set("custom.player_health.enabled", false);
231-
Config.get().set("fixes.kill_aura", false);
232-
Config.get().set("disable_offhand.enabled", false);
233-
Config.get().set("recipes.enchanted_golden_apple", false);
234-
Config.get().set("knockback.fishing_rod.enabled", false);
235-
Config.get().set("golden_apple_cooldown.golden_apple.actionbar", false);
236-
Config.get().set("golden_apple_cooldown.enchanted_golden_apple.actionbar", false);
237-
Config.get().set("enderpearl_cooldown.actionbar", false);
228+
setBoolean("combat.settings.old_pvp", false);
229+
setBoolean("combat.settings.old_weapon_damage", false);
230+
setBoolean("combat.settings.old_tool_damage", false);
231+
setBoolean("combat.settings.old_sharpness", false);
232+
setBoolean("combat.settings.disable_sweep_attacks.enabled", false);
233+
setBoolean("combat.settings.old_player_regen", false);
234+
setBoolean("custom.player_health.enabled", false);
235+
setBoolean("fixes.kill_aura", false);
236+
setBoolean("disable_offhand.enabled", false);
237+
setBoolean("recipes.enchanted_golden_apple", false);
238+
setBoolean("knockback.fishing_rod.enabled", false);
239+
setBoolean("golden_apple_cooldown.golden_apple.actionbar", false);
240+
setBoolean("golden_apple_cooldown.enchanted_golden_apple.actionbar", false);
241+
setBoolean("enderpearl_cooldown.actionbar", false);
242+
setBoolean("combat.settings.sword_blocking.enabled", false);
238243
config.save();
239244
config.reload();
240245
consoleMessage(Messenger.message("console.unsupported_version"));
241246
} else if (serverVersion("1.9")) {
242-
Config.get().set("combat.settings.disable_sweep_attacks.enabled", false);
243-
Config.get().set("recipes.enchanted_golden_apple", false);
244-
Config.get().set("knockback.fishing_rod.enabled", false);
247+
setBoolean("combat.settings.disable_sweep_attacks.enabled", false);
248+
setBoolean("recipes.enchanted_golden_apple", false);
249+
setBoolean("knockback.fishing_rod.enabled", false);
245250
config.save();
246251
config.reload();
247252
consoleMessage(Messenger.message("console.unsupported_version"));
248253
consoleMessage(Messenger.message("console.unsupported_sweep_attack"));
249254
} else if (serverVersion("1.10")) {
250-
Config.get().set("combat.settings.disable_sweep_attacks.enabled", false);
251-
Config.get().set("recipes.enchanted_golden_apple", false);
252-
Config.get().set("knockback.fishing_rod.enabled", false);
255+
setBoolean("combat.settings.disable_sweep_attacks.enabled", false);
256+
setBoolean("recipes.enchanted_golden_apple", false);
257+
setBoolean("knockback.fishing_rod.enabled", false);
253258
config.save();
254259
config.reload();
255260
consoleMessage(Messenger.message("console.unsupported_version"));
256261
consoleMessage(Messenger.message("console.unsupported_sweep_attack"));
257262
} else if (serverVersion("1.11")) {
258-
Config.get().set("recipes.enchanted_golden_apple", false);
259-
Config.get().set("knockback.fishing_rod.enabled", false);
263+
setBoolean("recipes.enchanted_golden_apple", false);
264+
setBoolean("knockback.fishing_rod.enabled", false);
260265
config.save();
261266
config.reload();
262267
consoleMessage(Messenger.message("console.unsupported_version"));
263268
} else if (serverVersion("1.12")) {
264-
Config.get().set("recipes.enchanted_golden_apple", false);
265-
Config.get().set("knockback.fishing_rod.enabled", false);
269+
setBoolean("recipes.enchanted_golden_apple", false);
270+
setBoolean("knockback.fishing_rod.enabled", false);
266271
config.save();
267272
config.reload();
268273
consoleMessage(Messenger.message("console.unsupported_version"));
@@ -281,6 +286,10 @@ private boolean isEnabled(String path) {
281286
return Config.get().getBoolean(path);
282287
}
283288

289+
private void setBoolean(String path, boolean value) {
290+
Config.get().set(path, value);
291+
}
292+
284293
public void consoleMessage(String message) {
285294
this.getServer().getConsoleSender().sendMessage(message);
286295
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public void addDefaults() {
6565
Config.get().addDefault("combat.settings.disable_sweep_attacks.ignore_sweeping_edge", false);
6666
Config.get().addDefault("combat.settings.disable_arrow_boost", true);
6767
Config.get().addDefault("combat.settings.old_player_regen", true);
68+
Config.get().addDefault("combat.settings.sword_blocking.enabled", true);
69+
Config.get().addDefault("combat.settings.sword_blocking.ignore_shields", true);
70+
Config.get().addDefault("combat.settings.sword_blocking.cancel_sprinting", false);
71+
Config.get().addDefault("combat.settings.sword_blocking.effect", "DAMAGE_RESISTANCE");
72+
Config.get().addDefault("combat.settings.sword_blocking.duration_ticks", 8);
73+
Config.get().addDefault("combat.settings.sword_blocking.amplifier", 0);
74+
Config.get().addDefault("combat.settings.sword_blocking.slow_duration_ticks", 8);
75+
Config.get().addDefault("combat.settings.sword_blocking.slow_amplifier", 2);
6876
Config.get().addDefault("combat.settings.disabled_worlds", combatList);
6977
Config.get().addDefault("golden_apple_cooldown.golden_apple.enabled", true);
7078
Config.get().addDefault("golden_apple_cooldown.golden_apple.cooldown", 10);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package me.nik.combatplus.listeners;
2+
3+
import me.nik.combatplus.files.Config;
4+
import me.nik.combatplus.utils.Messenger;
5+
import me.nik.combatplus.utils.WorldUtils;
6+
import org.bukkit.block.Block;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.EventPriority;
10+
import org.bukkit.event.Listener;
11+
import org.bukkit.event.block.Action;
12+
import org.bukkit.event.player.PlayerInteractEvent;
13+
import org.bukkit.potion.PotionEffect;
14+
import org.bukkit.potion.PotionEffectType;
15+
16+
public class Blocking implements Listener {
17+
18+
private final WorldUtils worldUtils = new WorldUtils();
19+
20+
private final PotionEffect effect = new PotionEffect(PotionEffectType.getByName(Config.get().getString("combat.settings.sword_blocking.effect")), Config.get().getInt("combat.settings.sword_blocking.duration_ticks"), Config.get().getInt("combat.settings.sword_blocking.amplifier"));
21+
private final int slowAmplifier = Config.get().getInt("combat.settings.sword_blocking.slow_amplifier");
22+
private final int slowDuration = Config.get().getInt("combat.settings.sword_blocking.slow_duration_ticks");
23+
private final boolean ignoreShields = Config.get().getBoolean("combat.settings.sword_blocking.ignore_shields");
24+
private final PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, slowDuration, slowAmplifier);
25+
private final boolean cancelSprinting = Config.get().getBoolean("combat.settings.sword_blocking.cancel_sprinting");
26+
27+
private static boolean interactiveBlock(Block block) {
28+
String b = block.getType().name();
29+
return b.contains("DOOR")
30+
|| b.contains("TABLE")
31+
|| b.contains("STAND")
32+
|| b.contains("CHEST")
33+
|| b.contains("GATE")
34+
|| b.contains("DISPENSER")
35+
|| b.contains("DROPPER")
36+
|| b.contains("NOTE")
37+
|| b.contains("REDSTONE")
38+
|| b.contains("DIODE")
39+
|| b.contains("FRAME")
40+
|| b.contains("LEVER")
41+
|| b.contains("SHULKER")
42+
|| b.contains("FURNACE")
43+
|| b.contains("BARREL");
44+
}
45+
46+
@EventHandler(priority = EventPriority.HIGHEST)
47+
public void onBlock(PlayerInteractEvent e) {
48+
if (e.getItem() == null) return;
49+
Action action = e.getAction();
50+
if (!action.name().contains("RIGHT_CLICK")) return;
51+
final Block block = e.getClickedBlock();
52+
if (action == Action.RIGHT_CLICK_BLOCK && block != null && interactiveBlock(block)) return;
53+
if (!e.getItem().getType().name().contains("SWORD")) return;
54+
Player p = e.getPlayer();
55+
if (worldUtils.combatDisabledWorlds(p)) return;
56+
if (ignoreShields && holdsShield(e.getPlayer())) return;
57+
if (cancelSprinting && p.isSprinting()) {
58+
p.setSprinting(false);
59+
}
60+
p.addPotionEffect(effect);
61+
p.addPotionEffect(slowness);
62+
Messenger.debug(p, "&3Sword Blocking &f&l>> &6Action: &a" + action.toString() + " &6Holds Shield: &a" + holdsShield(p));
63+
}
64+
65+
private boolean holdsShield(Player p) {
66+
return p.getInventory().getItemInOffHand().getType().name().contains("SHIELD");
67+
}
68+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public void onClick(InventoryClickEvent e) {
9999
booleanSet("combat.settings.old_player_regen", !configBoolean("combat.settings.old_player_regen"));
100100
saveAndReload();
101101
break;
102+
case "§6Sword Blocking":
103+
booleanSet("combat.settings.sword_blocking.enabled", !configBoolean("combat.settings.sword_blocking.enabled"));
104+
saveAndReload();
105+
break;
102106
// General GUI Settings
103107
case "§6Golden Apple Cooldown":
104108
booleanSet("golden_apple_cooldown.golden_apple.enabled", !configBoolean("golden_apple_cooldown.golden_apple.enabled"));

src/main/java/me/nik/combatplus/utils/GUIManager.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void run() {
109109
}
110110

111111
public void openCombatGUI(Player p) {
112-
Inventory combatGUI = Bukkit.createInventory(new CombatPlusHolder(), 45, Messenger.format(Lang.get().getString("gui.combat")));
112+
Inventory combatGUI = Bukkit.createInventory(new CombatPlusHolder(), 54, Messenger.format(Lang.get().getString("gui.combat")));
113113
p.openInventory(combatGUI);
114114
final Player pNon = p;
115115
new BukkitRunnable() {
@@ -206,19 +206,35 @@ public void run() {
206206
oldRegenMeta.setLore(oldRegenLore);
207207
oldRegen.setItemMeta(oldRegenMeta);
208208

209+
//sword blocking
210+
ItemStack block = new ItemStack(Material.PAPER, 1);
211+
ItemMeta blockMeta = block.getItemMeta();
212+
blockMeta.setDisplayName("§6Sword Blocking");
213+
ArrayList<String> blockLore = new ArrayList<>();
214+
blockLore.add("");
215+
blockLore.add(ChatColor.GRAY + "Currently set to: " + ChatColor.GREEN + isEnabled("combat.settings.sword_blocking.enabled"));
216+
blockLore.add("");
217+
blockLore.add(ChatColor.WHITE + "Gives Resistance While");
218+
blockLore.add(ChatColor.WHITE + "Right Clicking With a Sword");
219+
blockLore.add("");
220+
blockLore.add(ChatColor.GRAY + "More options in the Config.yml");
221+
blockMeta.setLore(blockLore);
222+
block.setItemMeta(blockMeta);
223+
209224
ItemStack back = new ItemStack(Material.BARRIER, 1);
210225
ItemMeta backMeta = back.getItemMeta();
211226
backMeta.setDisplayName("§cBack");
212227
back.setItemMeta(backMeta);
213228

214-
combatGUI.setItem(10, oldPvp);
215-
combatGUI.setItem(12, oldWepDmg);
216-
combatGUI.setItem(14, oldToolDmg);
217-
combatGUI.setItem(16, oldSharp);
218-
combatGUI.setItem(20, disableSweep);
219-
combatGUI.setItem(22, disableBoost);
220-
combatGUI.setItem(24, oldRegen);
221-
combatGUI.setItem(40, back);
229+
combatGUI.setItem(10, block);
230+
combatGUI.setItem(12, oldPvp);
231+
combatGUI.setItem(14, oldWepDmg);
232+
combatGUI.setItem(16, oldToolDmg);
233+
combatGUI.setItem(28, oldSharp);
234+
combatGUI.setItem(30, disableSweep);
235+
combatGUI.setItem(32, disableBoost);
236+
combatGUI.setItem(34, oldRegen);
237+
combatGUI.setItem(49, back);
222238
}
223239
}.runTaskTimer(plugin, 1, 5);
224240
}

0 commit comments

Comments
 (0)