Skip to content

Commit abc1430

Browse files
committed
🚧 Add features
1 parent 051d677 commit abc1430

13 files changed

Lines changed: 438 additions & 1 deletion

File tree

API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ public enum Permission {
305305
ESSENTIALS_SIGN_RESET("Allows you to use the <reset> mini message format"),
306306
ESSENTIALS_SIGN_FONT("Allows you to use the <font> mini message format"),
307307
ESSENTIALS_SIGN_KEYBIND("Allows you to use the <key> mini message format"),
308-
ESSENTIALS_STEP_START, ESSENTIALS_STEP_FINISH;
308+
ESSENTIALS_STEP_START,
309+
ESSENTIALS_STEP_FINISH,
310+
ESSENTIALS_ITEMFRAME,
311+
ESSENTIALS_SILENT_DEATH("Allows you to die silently without a death message");
309312

310313
private final String description;
311314
private final String[] args;

API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,18 @@ public enum Message {
960960
STEP_DOESNT_EXIST("<error>Step &f%step% <error>does not exist."),
961961
STEP_ALREADY_EXIST("<error>Step &f%step% <error>already started."),
962962
STEP_DOESNT_STARTED("<error>Step &f%step% <error>doesn't started."),
963+
964+
// ItemFrame
965+
DESCRIPTION_ITEMFRAME("Toggle item frame visibility"),
966+
COMMAND_ITEMFRAME_INVISIBLE("<success>Item frame is now <white>invisible<success>."),
967+
COMMAND_ITEMFRAME_VISIBLE("<success>Item frame is now <white>visible<success>."),
968+
COMMAND_ITEMFRAME_NOT_FOUND("<error>No item frame found. Look at an item frame and try again."),
969+
970+
// Death Messages
971+
DEATH_MESSAGE_GENERIC("#99E0FF%player% &7died."),
972+
DEATH_MESSAGE_PLAYER("#99E0FF%player% &7was slain by #34cfe0%killer%&7."),
973+
DEATH_MESSAGE_MOB("#99E0FF%player% &7was killed by &c%mob%&7."),
974+
DEATH_MESSAGE_MYTHIC_MOB("#99E0FF%player% &7was slain by <gradient:#ff6600:#ff0000>%mob%</gradient>&7!"),
963975
;
964976

965977
private EssentialsPlugin plugin;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package fr.maxlego08.essentials.api.modules.death;
2+
3+
public enum DeathMessageType {
4+
5+
DISABLE,
6+
DEFAULT,
7+
CUSTOM
8+
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fr.maxlego08.essentials.api.modules.death;
2+
3+
import org.bukkit.entity.Entity;
4+
5+
import java.util.Optional;
6+
7+
public interface MythicMobsHook {
8+
9+
/**
10+
* Checks if the given entity is a MythicMob.
11+
*
12+
* @param entity the entity to check
13+
* @return true if the entity is a MythicMob, false otherwise
14+
*/
15+
boolean isMythicMob(Entity entity);
16+
17+
/**
18+
* Gets the display name of a MythicMob entity.
19+
*
20+
* @param entity the entity to get the name of
21+
* @return an Optional containing the MythicMob's display name, or empty if not a MythicMob
22+
*/
23+
Optional<String> getMythicMobName(Entity entity);
24+
25+
}

Hooks/MythicMobs/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
group = "Hooks:MythicMobs"
2+
3+
repositories {
4+
maven(url = "https://mvn.lumine.io/repository/maven-public/")
5+
}
6+
7+
dependencies {
8+
compileOnly(project(":API"))
9+
compileOnly("io.papermc.paper:paper-api:1.21.5-R0.1-SNAPSHOT")
10+
compileOnly("io.lumine:Mythic-Dist:5.7.2")
11+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fr.maxlego08.essentials.hooks;
2+
3+
import fr.maxlego08.essentials.api.EssentialsPlugin;
4+
import fr.maxlego08.essentials.api.modules.death.MythicMobsHook;
5+
import io.lumine.mythic.bukkit.MythicBukkit;
6+
import io.lumine.mythic.core.mobs.ActiveMob;
7+
import org.bukkit.entity.Entity;
8+
9+
import java.util.Optional;
10+
11+
public class MythicMobsHookImpl implements MythicMobsHook {
12+
13+
private final EssentialsPlugin plugin;
14+
15+
public MythicMobsHookImpl(EssentialsPlugin plugin) {
16+
this.plugin = plugin;
17+
}
18+
19+
@Override
20+
public boolean isMythicMob(Entity entity) {
21+
return MythicBukkit.inst().getMobManager().isMythicMob(entity);
22+
}
23+
24+
@Override
25+
public Optional<String> getMythicMobName(Entity entity) {
26+
if (!isMythicMob(entity)) {
27+
return Optional.empty();
28+
}
29+
30+
ActiveMob activeMob = MythicBukkit.inst().getMobManager().getMythicMobInstance(entity);
31+
if (activeMob == null) {
32+
return Optional.empty();
33+
}
34+
35+
String displayName = activeMob.getDisplayName();
36+
if (displayName != null && !displayName.isEmpty()) {
37+
return Optional.of(displayName);
38+
}
39+
40+
return Optional.of(activeMob.getMobType());
41+
}
42+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include("Hooks:AxVault")
2525
include("Hooks:NuVotifier")
2626
include("Hooks:NChat")
2727
include("Hooks:WorldGuard")
28+
include("Hooks:MythicMobs")
2829

2930
include("NMS:V1_20_4")
3031
include("NMS:V1_20_6")

src/main/java/fr/maxlego08/essentials/ZEssentialsPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,5 +834,15 @@ private void loadHooks() {
834834
if (getServer().getPluginManager().isPluginEnabled("NChat")) {
835835
createInstance("NChatHook").ifPresent(object -> this.getLogger().info("Register NChatHook."));
836836
}
837+
838+
if (getServer().getPluginManager().isPluginEnabled("MythicMobs")) {
839+
createInstance("MythicMobsHookImpl").ifPresent(object -> {
840+
var deathModule = this.moduleManager.getModule(fr.maxlego08.essentials.module.modules.DeathMessageModule.class);
841+
if (deathModule != null) {
842+
deathModule.setMythicMobsHook((fr.maxlego08.essentials.api.modules.death.MythicMobsHook) object);
843+
}
844+
this.getLogger().info("Register MythicMobsHook.");
845+
});
846+
}
837847
}
838848
}

src/main/java/fr/maxlego08/essentials/commands/CommandLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import fr.maxlego08.essentials.commands.commands.teleport.CommandTeleportToHere;
8080
import fr.maxlego08.essentials.commands.commands.teleport.CommandTeleportWorld;
8181
import fr.maxlego08.essentials.commands.commands.teleport.CommandTop;
82+
import fr.maxlego08.essentials.commands.commands.utils.CommandItemFrame;
8283
import fr.maxlego08.essentials.commands.commands.utils.*;
8384
import fr.maxlego08.essentials.commands.commands.utils.lag.CommandLag;
8485
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandEnchant;
@@ -283,6 +284,7 @@ public void loadCommands(CommandManager commandManager) {
283284

284285
register("pub", CommandPub.class);
285286
register("step", CommandStep.class);
287+
register("itemframe", CommandItemFrame.class, "iframe");
286288

287289
for (RegisterCommand registerCommand : this.commands) {
288290
try {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package fr.maxlego08.essentials.commands.commands.utils;
2+
3+
import fr.maxlego08.essentials.api.EssentialsPlugin;
4+
import fr.maxlego08.essentials.api.commands.CommandResultType;
5+
import fr.maxlego08.essentials.api.commands.Permission;
6+
import fr.maxlego08.essentials.api.messages.Message;
7+
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
8+
import org.bukkit.FluidCollisionMode;
9+
import org.bukkit.Location;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.entity.ItemFrame;
12+
import org.bukkit.util.RayTraceResult;
13+
import org.bukkit.util.Vector;
14+
15+
public class CommandItemFrame extends VCommand {
16+
17+
public CommandItemFrame(EssentialsPlugin plugin) {
18+
super(plugin);
19+
this.setPermission(Permission.ESSENTIALS_ITEMFRAME);
20+
this.setDescription(Message.DESCRIPTION_ITEMFRAME);
21+
this.onlyPlayers();
22+
}
23+
24+
@Override
25+
protected CommandResultType perform(EssentialsPlugin plugin) {
26+
Location eyeLocation = player.getEyeLocation();
27+
Vector direction = eyeLocation.getDirection();
28+
29+
RayTraceResult result = player.getWorld().rayTraceEntities(
30+
eyeLocation,
31+
direction,
32+
5.0,
33+
entity -> entity instanceof ItemFrame
34+
);
35+
36+
if (result == null || result.getHitEntity() == null) {
37+
message(sender, Message.COMMAND_ITEMFRAME_NOT_FOUND);
38+
return CommandResultType.DEFAULT;
39+
}
40+
41+
Entity entity = result.getHitEntity();
42+
if (entity instanceof ItemFrame itemFrame) {
43+
boolean newVisibility = !itemFrame.isVisible();
44+
itemFrame.setVisible(newVisibility);
45+
46+
if (newVisibility) {
47+
message(sender, Message.COMMAND_ITEMFRAME_VISIBLE);
48+
} else {
49+
message(sender, Message.COMMAND_ITEMFRAME_INVISIBLE);
50+
}
51+
return CommandResultType.SUCCESS;
52+
}
53+
54+
message(sender, Message.COMMAND_ITEMFRAME_NOT_FOUND);
55+
return CommandResultType.DEFAULT;
56+
}
57+
}

0 commit comments

Comments
 (0)