Added toggle to party as well and made it so it can be added to other channels if needed
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Toggleable {
|
||||
|
||||
private static final List<Toggleable> togglableClasses = new ArrayList<>();
|
||||
|
||||
public Toggleable() {
|
||||
togglableClasses.add(this);
|
||||
}
|
||||
|
||||
public static Toggleable getToggleable(UUID uuid) {
|
||||
for (Toggleable toggleableClass : togglableClasses) {
|
||||
if (toggleableClass.isToggled(uuid))
|
||||
return toggleableClass;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean isToggled(UUID uuid);
|
||||
|
||||
public abstract void setOff(UUID uuid);
|
||||
|
||||
public boolean toggle(UUID uuid) {
|
||||
if (isToggled(uuid)) {
|
||||
setOff(uuid);
|
||||
return (false);
|
||||
}
|
||||
for (Toggleable toggleable : togglableClasses) {
|
||||
if (toggleable.isToggled(uuid)) {
|
||||
setOff(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
setOn(uuid);
|
||||
return (true);
|
||||
}
|
||||
|
||||
public abstract void setOn(UUID uuid);
|
||||
|
||||
public void disableToggles(UUID uuid) {
|
||||
for (Toggleable toggleable : togglableClasses) {
|
||||
if (toggleable.isToggled(uuid)) {
|
||||
setOff(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Player player, Component message) {
|
||||
sendMessage(player, PlainTextComponentSerializer.plainText().serialize(message));
|
||||
}
|
||||
|
||||
public abstract void sendMessage(Player player, String message);
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.alttd.chat.objects.channels;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class Channel {
|
||||
public class Channel {
|
||||
|
||||
public static HashMap<String, Channel> channels = new HashMap<>();
|
||||
protected String permission;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alttd.chat.objects.channels;
|
||||
|
||||
public class DefaultChannel extends Channel{
|
||||
public abstract class DefaultChannel extends Channel{
|
||||
public DefaultChannel(String channelName, String format, boolean proxy) {
|
||||
super(channelName, format, proxy);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user