Skip to content

Commit

Permalink
Updating to Minecraft 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
alkanife committed Jan 30, 2023
1 parent eecb313 commit 732d2fc
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# old-combat
> Minecraft Plugin (1.19.2)
> Minecraft Plugin (1.19.3)
A very light version of [BukkitOldCombatMechanics](https://github.com/kernitus/BukkitOldCombatMechanics).

This plugin was made to be used with other plugins, but you can still enable/disable modules with the `/old-combat` command (requires to be a server operator).
This plugin was made to be used with other plugins, but you can still enable/disable modules with the `/oldcombat` command (requires to be a server operator).

## Requirements
This plugins requires the latest versions of [ProtocolLib](https://github.com/dmulloy2/ProtocolLib) and [CommandAPI](https://github.com/JorelAli/CommandAPI).
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.alkanife</groupId>
<artifactId>old-combat</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -66,7 +66,7 @@
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-core</artifactId>
<version>8.5.1</version>
<version>8.7.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
136 changes: 108 additions & 28 deletions src/main/java/fr/alkanife/oldcombat/commands/OldCombatCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,125 @@
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.BooleanArgument;
import fr.alkanife.oldcombat.modules.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class OldCombatCommand {

public static void register() {
BooleanArgument booleanArgument = new BooleanArgument("enable-disable");

CommandAPICommand attackSpeedCommand = new CommandAPICommand("attackspeed")
.withArguments(new BooleanArgument("enable-disable"))
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
AttackSpeedModule.ENABLED = (boolean) objects[0];
AttackSpeedModule.resetAll();
OldCombatCommand.broadcastOperators(commandSender.getName(), "AttackSpeed", "" + AttackSpeedModule.ENABLED);

toggleAttackSpeed(commandSender, objects[0]);
});

CommandAPICommand criticalHitCommand = new CommandAPICommand("criticalHit")
.withArguments(new BooleanArgument("enable-disable"))
CommandAPICommand criticalHitCommand = new CommandAPICommand("criticalhit")
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
CriticalHitModule.ENABLED = (boolean) objects[0];
OldCombatCommand.broadcastOperators(commandSender.getName(), "CriticalHit", "" + CriticalHitModule.ENABLED);

toggleCriticalHit(commandSender, objects[0]);
});

CommandAPICommand knockbackCommand = new CommandAPICommand("knockback")
.withArguments(new BooleanArgument("enable-disable"))
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
KnockbackModule.ENABLED = (boolean) objects[0];
OldCombatCommand.broadcastOperators(commandSender.getName(), "Knockback", "" + KnockbackModule.ENABLED);

toggleKnockback(commandSender, objects[0]);
});

CommandAPICommand playerRegenCommand = new CommandAPICommand("playerregen")
.withArguments(new BooleanArgument("enable-disable"))
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
PlayerRegenModule.ENABLED = (boolean) objects[0];
OldCombatCommand.broadcastOperators(commandSender.getName(), "PlayerRegen", "" + PlayerRegenModule.ENABLED);

togglePlayerRegen(commandSender, objects[0]);
});

CommandAPICommand soundCommand = new CommandAPICommand("sound")
.withArguments(new BooleanArgument("enable-disable"))
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
SoundModule.ENABLED = (boolean) objects[0];
OldCombatCommand.broadcastOperators(commandSender.getName(), "Sound", "" + SoundModule.ENABLED);

toggleSound(commandSender, objects[0]);
});

CommandAPICommand sweepCommand = new CommandAPICommand("sweep")
.withArguments(new BooleanArgument("enable-disable"))
.withArguments(booleanArgument)
.executes((commandSender, objects) -> {
if (!commandSender.isOp())
return;
SweepModule.ENABLED = (boolean) objects[0];
OldCombatCommand.broadcastOperators(commandSender.getName(), "Sweep", "" + SweepModule.ENABLED);

toggleSweep(commandSender, objects[0]);
});

CommandAPICommand allEnable = new CommandAPICommand("enable").executes((commandSender, objects) -> {
toggleAttackSpeed(commandSender, true);
toggleCriticalHit(commandSender, true);
toggleKnockback(commandSender, true);
togglePlayerRegen(commandSender, true);
toggleSound(commandSender, true);
toggleSweep(commandSender, true);
});

CommandAPICommand allDisable = new CommandAPICommand("disable").executes((commandSender, objects) -> {
toggleAttackSpeed(commandSender, false);
toggleCriticalHit(commandSender, false);
toggleKnockback(commandSender, false);
togglePlayerRegen(commandSender, false);
toggleSound(commandSender, false);
toggleSweep(commandSender, false);
});

new CommandAPICommand("oldcombat")
.withSubcommand(attackSpeedCommand)
.withSubcommand(criticalHitCommand)
.withSubcommand(knockbackCommand)
.withSubcommand(playerRegenCommand)
.withSubcommand(soundCommand)
.withSubcommand(sweepCommand)
.withSubcommand(allEnable)
.withSubcommand(allDisable)
.executes((commandSender, objects) -> {
commandSender.sendMessage("§7-----");
commandSender.sendMessage("§7AttackSpeed module: " + AttackSpeedModule.ENABLED);
commandSender.sendMessage("§7CriticalHit module: " + CriticalHitModule.ENABLED);
commandSender.sendMessage("§7Knockback module: " + KnockbackModule.ENABLED);
commandSender.sendMessage("§7PlayerRegen module: " + PlayerRegenModule.ENABLED);
commandSender.sendMessage("§7Sound module: " + SweepModule.ENABLED);
commandSender.sendMessage("§7Sweep module: " + SweepModule.ENABLED);
commandSender.sendMessage("§7-----");
if (!commandSender.isOp())
return;

String enable = "/oldcombat enable";
String disable = "/oldcombat disable";

commandSender.sendMessage("§f");
showToggle(commandSender, "AttackSpeed", AttackSpeedModule.ENABLED);
showToggle(commandSender, "CriticalHit", CriticalHitModule.ENABLED);
showToggle(commandSender, "Knockback", KnockbackModule.ENABLED);
showToggle(commandSender, "PlayerRegen", PlayerRegenModule.ENABLED);
showToggle(commandSender, "Sound", SweepModule.ENABLED);
showToggle(commandSender, "Sweep", SweepModule.ENABLED);
commandSender.sendMessage("§f");
commandSender.sendMessage(
Component.text("§7[Enable everything]")
.hoverEvent(HoverEvent.showText(Component.text(enable)))
.clickEvent(ClickEvent.runCommand(enable)).append(Component.text(" "))
.append(
Component.text("§7[Disable everything]")
.hoverEvent(HoverEvent.showText(Component.text(disable)))
.clickEvent(ClickEvent.runCommand(disable))));
commandSender.sendMessage("§f");
}).register();
}

Expand All @@ -88,4 +130,42 @@ private static void broadcastOperators(String operator, String module, String st
if (player.isOp())
player.sendMessage("§7§o[" + operator + ": Set " + module + " module to " + state + "]");
}

private static void showToggle(CommandSender commandSender, String name, boolean current) {
commandSender.sendMessage(Component.text("§7 - " + name + " module: " + current)
.hoverEvent(HoverEvent.showText(Component.text("Click to " + (current ? "disable" : "enable") + " the " + name + " module")))
.clickEvent(ClickEvent.runCommand("/oldcombat " + name.toLowerCase() + " " + !current)));
}

private static void toggleAttackSpeed(CommandSender commandSender, Object object) {
AttackSpeedModule.ENABLED = (boolean) object;
AttackSpeedModule.resetAll();
OldCombatCommand.broadcastOperators(commandSender.getName(), "AttackSpeed", "" + AttackSpeedModule.ENABLED);
commandSender.sendMessage("§6All connected players need to reconnect for the change to be effective.");
}

private static void toggleCriticalHit(CommandSender commandSender, Object object) {
CriticalHitModule.ENABLED = (boolean) object;
OldCombatCommand.broadcastOperators(commandSender.getName(), "CriticalHit", "" + CriticalHitModule.ENABLED);
}

private static void toggleKnockback(CommandSender commandSender, Object object) {
KnockbackModule.ENABLED = (boolean) object;
OldCombatCommand.broadcastOperators(commandSender.getName(), "Knockback", "" + KnockbackModule.ENABLED);
}

private static void togglePlayerRegen(CommandSender commandSender, Object object) {
PlayerRegenModule.ENABLED = (boolean) object;
OldCombatCommand.broadcastOperators(commandSender.getName(), "PlayerRegen", "" + PlayerRegenModule.ENABLED);
}

private static void toggleSound(CommandSender commandSender, Object object) {
SoundModule.ENABLED = (boolean) object;
OldCombatCommand.broadcastOperators(commandSender.getName(), "Sound", "" + SoundModule.ENABLED);
}

private static void toggleSweep(CommandSender commandSender, Object object) {
SweepModule.ENABLED = (boolean) object;
OldCombatCommand.broadcastOperators(commandSender.getName(), "Sweep", "" + SweepModule.ENABLED);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: fr.alkanife.oldcombat.OldCombat
name: Old-combat
version: 1.0.0
version: 1.0.1
author: Alkanife
api-version: 1.19
website: https://github.com/alkanife/old-combat
Expand Down

0 comments on commit 732d2fc

Please sign in to comment.