9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-31 21:06:38 +00:00

Add more hidden reasons & show, hide, and toggle actions

This commit is contained in:
LoJoSho
2023-02-01 15:51:06 -06:00
parent 645fd25b82
commit 57d5e02275
8 changed files with 74 additions and 7 deletions

View File

@@ -327,7 +327,7 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
MessagesUtil.sendMessage(sender, "hide-cosmetic");
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
user.hideCosmetics(CosmeticUser.HiddenReason.COMMAND);
return true;
}
case ("show") -> {

View File

@@ -22,6 +22,9 @@ public class Actions {
private static ActionEquip ACTION_EQUIP = new ActionEquip();
private static ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
private static ActionParticle ACTION_PARTICLE = new ActionParticle();
private static ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
private static ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
private static ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
public static Action getAction(String id) {
@@ -40,7 +43,7 @@ public class Actions {
for (String a : raw) {
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
String message = StringUtils.substringAfter(a, "] ");
MessagesUtil.sendDebugMessages("ID is " + id + " // Message is " + message);
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
if (isAction(id)) {
getAction(id).run(user, message);
} else {

View File

@@ -0,0 +1,19 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
public class ActionCosmeticHide extends Action {
public ActionCosmeticHide() {
super("hide");
}
@Override
public void run(CosmeticUser user, String raw) {
if (!user.getHidden()) {
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
return;
}
}
}

View File

@@ -0,0 +1,19 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
public class ActionCosmeticShow extends Action {
public ActionCosmeticShow() {
super("show");
}
@Override
public void run(CosmeticUser user, String raw) {
if (user.getHidden()) {
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return; // Do not hide if its already off for WG
user.showCosmetics();
}
}
}

View File

@@ -0,0 +1,22 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
public class ActionCosmeticToggle extends Action {
public ActionCosmeticToggle() {
super("toggle");
}
@Override
public void run(CosmeticUser user, String raw) {
if (user.getHidden()) {
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
return;
}
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
return;
}
}

View File

@@ -24,9 +24,10 @@ public class WGListener implements Listener {
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = region.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(loc);
// TODO: Add more cosmetics
if (set.getRegions().size() == 0) {
user.showCosmetics();
if (user.getHidden()) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
user.showCosmetics();
}
}
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {

View File

@@ -207,7 +207,7 @@ public class PlayerGameListener implements Listener {
Player player = (Player) event.getEntity();
CosmeticUser user = CosmeticUsers.getUser(player);
if (event.getAction().equals(EntityPotionEffectEvent.Action.ADDED)) {
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
user.hideCosmetics(CosmeticUser.HiddenReason.POTION);
return;
}
if (event.getAction().equals(EntityPotionEffectEvent.Action.CLEARED) || event.getAction().equals(EntityPotionEffectEvent.Action.REMOVED)) {

View File

@@ -460,6 +460,9 @@ public class CosmeticUser {
public enum HiddenReason {
NONE,
WORLDGUARD,
PLUGIN
PLUGIN,
POTION,
ACTION,
COMMAND
}
}