Skip to content

Commit

Permalink
Merge pull request #133 from Nookure/feat/separate-paper-player-wrapp…
Browse files Browse the repository at this point in the history
…er-logic-into-childrens

Feat/separate paper player wrapper logic into childrens
  • Loading branch information
Angelillo15 authored Dec 2, 2024
2 parents 0016479 + aab6c98 commit 15e34cb
Show file tree
Hide file tree
Showing 17 changed files with 558 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ default void toggleStaffMode() {
* Set the player's staff chat mode.
*
* @param staffChatAsDefault if true, the player will be in staff chat mode
* by default
* @param saveInDB if true, the player's staff chat mode will be saved
*/
void setStaffChatAsDefault(boolean staffChatAsDefault);
void setStaffChatAsDefault(boolean staffChatAsDefault, boolean saveInDB);

/**
* Set the player's staff chat mode.
*
* @param staffChatAsDefault if true, the player will be in staff chat mode
*/
default void setStaffChatAsDefault(boolean staffChatAsDefault) {
setStaffChatAsDefault(staffChatAsDefault, true);
}

/**
* Reload/load the player's items.
Expand Down Expand Up @@ -138,4 +149,6 @@ default void disableVanish() {
* @return the player's items
*/
@NotNull Map<Integer, StaffItem> getItems();

@NotNull Map<Class<? extends StaffPlayerExtension>, StaffPlayerExtension> getExtensions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nookure.staff.api.annotation.staff;

import com.google.inject.BindingAnnotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@BindingAnnotation
public @interface StaffChatAsDefaultBool {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nookure.staff.api.annotation.staff;

import com.google.inject.BindingAnnotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@BindingAnnotation
public @interface StaffModeBool {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.nookure.staff.api.extension;

import com.google.inject.Inject;
import com.nookure.staff.api.StaffPlayerWrapper;
import org.jetbrains.annotations.NotNull;

public abstract class StaffPlayerExtension {
public StaffPlayerExtension(StaffPlayerWrapper player) {
@Inject
public StaffPlayerExtension(@NotNull final StaffPlayerWrapper player) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.nookure.staff.api.extension;

import com.google.inject.Inject;
import com.nookure.staff.api.StaffPlayerWrapper;
import org.jetbrains.annotations.NotNull;

/**
* This class represents an extension for the vanish feature
Expand All @@ -12,7 +14,8 @@ public abstract class VanishExtension extends StaffPlayerExtension {
*
* @param player the player
*/
public VanishExtension(StaffPlayerWrapper player) {
@Inject
public VanishExtension(@NotNull final StaffPlayerWrapper player) {
super(player);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nookure.staff.api.extension.staff;

import com.nookure.staff.api.StaffPlayerWrapper;
import com.nookure.staff.api.extension.StaffPlayerExtension;
import com.nookure.staff.api.item.StaffItem;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public abstract class StaffModeExtension extends StaffPlayerExtension {
public StaffModeExtension(StaffPlayerWrapper player) {
super(player);
}

public abstract void enableStaffMode(final boolean silentJoin);

public abstract void disableStaffMode();

public abstract void checkStaffMode();

public abstract void writeStaffModeState(final boolean state);

public abstract void toggleStaffMode(boolean silentJoin);

public abstract boolean isStaffMode();

public abstract void setItems();

@NotNull
public abstract Map<Integer, StaffItem> getItems();

public abstract void saveInventory();

public abstract void clearInventory();

public abstract void restoreInventory();

public abstract void saveLocation();

public abstract void restoreLocation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.nookure.staff.api.util.ServerUtils;
import com.nookure.staff.api.util.TextUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -33,7 +34,10 @@ public StaffItem(ItemPartial itemConfig) {
ItemMeta meta = itemStack.getItemMeta();

if (ServerUtils.isPaper) {
meta.displayName(TextUtils.toComponent(itemConfig.getName()));
Component displayName = TextUtils.toComponent(itemConfig.getName());
displayName = displayName.decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE);
meta.displayName(displayName);

meta.lore(itemConfig.lore());
} else {
meta.setDisplayName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.nookure.staff.api.messaging.EventMessenger;
import org.jetbrains.annotations.NotNull;

public abstract class DecoderPluginMessenger extends EventMessenger {
public final class DecoderPluginMessenger extends EventMessenger {
@Override
public void prepare() {
// Nothing to do here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
`vanished` TINYINT(1) NOT NULL DEFAULT 0,
`staff_chat_enabled` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLTE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.nookure.staff.api.event.EventManager;
import com.nookure.staff.api.extension.StaffPlayerExtensionManager;
import com.nookure.staff.api.extension.VanishExtension;
import com.nookure.staff.api.extension.staff.StaffModeExtension;
import com.nookure.staff.api.manager.PlayerWrapperManager;
import com.nookure.staff.api.messaging.Channels;
import com.nookure.staff.api.messaging.EventMessenger;
Expand All @@ -27,6 +28,7 @@
import com.nookure.staff.paper.command.main.NookureStaffCommand;
import com.nookure.staff.paper.command.staff.StaffCommandParent;
import com.nookure.staff.paper.extension.FreezePlayerExtension;
import com.nookure.staff.paper.extension.staff.PaperStaffModeExtension;
import com.nookure.staff.paper.extension.vanish.InternalVanishExtension;
import com.nookure.staff.paper.extension.vanish.SuperVanishExtension;
import com.nookure.staff.paper.listener.OnPlayerJoin;
Expand Down Expand Up @@ -316,6 +318,10 @@ private void loadExtensions() {
extensionManager.registerExtension(SuperVanishExtension.class, VanishExtension.class);
}
}

if (config.get().modules.isStaffMode()) {
extensionManager.registerExtension(PaperStaffModeExtension.class, StaffModeExtension.class);
}
}

public void onDisable() {
Expand Down
Loading

0 comments on commit 15e34cb

Please sign in to comment.