Skip to content

Commit

Permalink
Merge pull request #61 from Nookure/feature/freeze-chat-timer
Browse files Browse the repository at this point in the history
Feature/freeze chat timer
  • Loading branch information
Angelillo15 authored Nov 10, 2023
2 parents af2b2bf + 6abd0fb commit 08600cc
Show file tree
Hide file tree
Showing 34 changed files with 599 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nookure.mast.api.event;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public interface BukkitListener<T> extends Listener {
@EventHandler
void handle(T event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.nookure.mast.api.manager;

import com.google.inject.Singleton;
import es.angelillo15.mast.api.IStaffPlayer;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashMap;

@Singleton
public class FreezeManager {
public HashMap<String, FreezeVector> frozenPlayers = new HashMap<>();

/**
* Freeze the player
* @param staff IStaffPlayer who freeze the player
* @param target Player to freeze
*/
public void freezePlayer(IStaffPlayer staff, Player target) {
freezePlayer(staff, target, -1);
}

/**
* Freeze the player
* @param staff IStaffPlayer who freeze the player
* @param target Player to freeze
* @param time Time to freeze expire
*/
public void freezePlayer(IStaffPlayer staff, Player target, long time) {
frozenPlayers.put(target.getName(), new FreezeVector(staff, target, time));
}

/**
* Unfreeze the player
* @param target Player
*/
public void unfreezePlayer(Player target) {
frozenPlayers.remove(target.getName());
}

/**
* Unfreeze the player
* @param target Player
*/
public void unfreezePlayer(String target) {
frozenPlayers.remove(target);
}

/**
* Check if the player is frozen
* @param target Player
* @return boolean
*/
public boolean isFrozen(Player target) {
return frozenPlayers.containsKey(target.getName());
}

/**
* Check if the player is frozen
* @param target Player
* @return boolean
*/
public boolean isFrozen(String target) {
return frozenPlayers.containsKey(target);
}

/**
* Gets the frozen players list
* @return ArrayList of OfflinePlayer
*/
public ArrayList<OfflinePlayer> getFrozenPlayers() {
ArrayList<OfflinePlayer> frozen = new ArrayList<>();
frozenPlayers.forEach((name, vector) -> frozen.add(vector.getTarget()));
return frozen;
}

/**
* Gets the frozen players list
* @return ArrayList of FreezeVector with the frozen players
*/
public ArrayList<FreezeVector> getFreezeVectors() {
ArrayList<FreezeVector> frozen = new ArrayList<>();
frozenPlayers.forEach((name, vector) -> frozen.add(vector));
return frozen;
}

public FreezeVector getFreezeVector(Player target) {
return frozenPlayers.get(target.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.nookure.mast.api.manager;

import es.angelillo15.mast.api.IStaffPlayer;
import org.bukkit.OfflinePlayer;


public class FreezeVector {
private final IStaffPlayer staffPlayer;
private final OfflinePlayer target;
private long timeLeft;
private boolean hasTalked = false;

public FreezeVector(IStaffPlayer staffPlayer, OfflinePlayer target, long timeLeft) {
this.staffPlayer = staffPlayer;
this.target = target;
this.timeLeft = timeLeft;
}

public IStaffPlayer getStaffPlayer() {
return staffPlayer;
}

public OfflinePlayer getTarget() {
return target;
}

/**
* Get the time left to unfreeze the player
* -1 disabled
* -2 expired
* @return long time left
*/
public long getTimeLeft() {
return timeLeft;
}

public void setTimeLeft(int timeLeft) {
this.timeLeft = timeLeft;
}

public boolean hasTalked() {
return hasTalked;
}

public void setHasTalked(boolean hasTalked) {
this.hasTalked = hasTalked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,12 @@ public interface IStaffPlayer {
default String getName() {
return getPlayer().getName();
}

/**
* Send a message to the player
* @param message - message to send
*/
default void sendMessage(String message) {
TextUtils.sendMessage(getPlayer(), TextUtils.toMM(message));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package es.angelillo15.mast.api.config.bukkit;


import es.angelillo15.mast.api.utils.NumberUtils;

import java.util.List;

public class Config {
Expand Down Expand Up @@ -108,6 +110,18 @@ public static boolean askToExecuteCommands() {
public static List<String> commands() {
return ConfigLoader.getConfig().getConfig().getStringList("Freeze.commands");
}

public static boolean freezeChat() {
return ConfigLoader.getConfig().getConfig().getBoolean("Freeze.freezeChat");
}

public static long freezeTimer() {
String value = ConfigLoader.getConfig().getConfig().getString("Freeze.freezeTimer");
if (value == null) return -1;
if (value.equals("false")) return -1;

return NumberUtils.parseToMilis(value);
}
}

public static class Addons {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ public static String GET_FREEZE_CANNOT_FREEZE_THAT_PLAYER_MESSAGE() {
return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeBypassMessage"));
}

public static String FREEZE_CHAT_FORMAT() {
return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatFormat"));
}

public static String FREEZE_STAFF_CHAT_FORMAT() {
return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeStaffChatFormat"));
}

public static String FREEZE_CHAT_USAGE() {
return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatUsage"));
}

public static String FREEZE_CHAT_NOT_FROZEN() {
return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatNotFrozen"));
}

public static class StaffVault {
public static String itemSaved() {
return TextUtils.parseBukkitMessage(messages.getString("StaffVault.itemSaved"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
package es.angelillo15.mast.api.managers.freeze;

import com.google.inject.Inject;
import com.nookure.mast.api.manager.FreezeVector;
import es.angelillo15.mast.api.IStaffPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

/**
* This class is deprecated, use {@link com.nookure.mast.api.manager.FreezeManager} instead
* @since 3.0.0
*/
@Deprecated
public class FreezeManager {
public static HashMap<String, FreezeVector> frozenPlayers = new HashMap<>();
@Inject
private static com.nookure.mast.api.manager.FreezeManager freezeManager;

/**
* Freeze the player
* @param staff IStaffPlayer who freeze the player
* @param target Player to freeze
*/
public static void freezePlayer(IStaffPlayer staff, Player target) {
frozenPlayers.put(target.getName(), new FreezeVector(staff, target));
freezeManager.freezePlayer(staff, target, -1);
}

/**
* Freeze the player
* @param staff IStaffPlayer who freeze the player
* @param target Player to freeze
* @param time Time to freeze the player (in ms)
*/
public static void freezePlayer(IStaffPlayer staff, Player target, long time) {
freezeManager.freezePlayer(staff, target, time);
}

/**
* Unfreeze the player
* @param target Player
*/
public static void unfreezePlayer(Player target) {
frozenPlayers.remove(target.getName());
freezeManager.unfreezePlayer(target);
}

/**
* Unfreeze the player
* @param target Player
*/
public static void unfreezePlayer(String target) {
frozenPlayers.remove(target);
freezeManager.unfreezePlayer(target);
}

/**
Expand All @@ -40,7 +57,7 @@ public static void unfreezePlayer(String target) {
* @return boolean
*/
public static boolean isFrozen(Player target) {
return frozenPlayers.containsKey(target.getName());
return freezeManager.isFrozen(target);
}

/**
Expand All @@ -49,20 +66,18 @@ public static boolean isFrozen(Player target) {
* @return boolean
*/
public static boolean isFrozen(String target) {
return frozenPlayers.containsKey(target);
return freezeManager.isFrozen(target);
}

/**
* Gets the frozen players list
* @return ArrayList of OfflinePlayer
*/
public static ArrayList<OfflinePlayer> getFrozenPlayers() {
ArrayList<OfflinePlayer> frozen = new ArrayList<>();
frozenPlayers.forEach((name, vector) -> frozen.add(vector.getTarget()));
return frozen;
return freezeManager.getFrozenPlayers();
}

public static FreezeVector getFreezeVector(Player target) {
return frozenPlayers.get(target.getName());
return freezeManager.getFreezeVector(target);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package es.angelillo15.mast.api.nms

import net.kyori.adventure.text.Component
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack

Expand Down Expand Up @@ -32,4 +33,11 @@ abstract class VersionSupport {
* @param key The key to remove.
*/
abstract fun removeTag(item: ItemStack, key: String): ItemStack

/**
* Send an action bar message to a player.
* @param player The player to send the action bar message to.
* @param message The message to send.
*/
abstract fun sendActionBar(player: Player, message: Component)
}
Loading

0 comments on commit 08600cc

Please sign in to comment.