Moved chat-only stuff, F top, append text start

#85
This commit is contained in:
Norbi Peti 2019-02-20 16:48:08 +01:00
parent 26b44fbfe1
commit c5e33a93ba
9 changed files with 143 additions and 77 deletions

View file

@ -1,5 +1,6 @@
package buttondevteam.chat;
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
import buttondevteam.chat.components.fun.FunComponent;
import buttondevteam.chat.components.fun.UnlolCommand;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
@ -212,10 +213,7 @@ public class ChatProcessing {
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
String origin) {
TellrawPart json = new TellrawPart("");
if (mp != null && mp.ChatOnly) {
json.addExtra(new TellrawPart("[C]")
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
}
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
json.addExtra(
new TellrawPart(channelidentifier)
.setHoverEvent(

View file

@ -1,32 +0,0 @@
package buttondevteam.chat.commands;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.PlayerCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
public final class ChatonlyCommand extends PlayerCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Chat-only mode ----", //
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
"It was designed for chat clients", //
"Once enabled, the only way of disabling it is by relogging to the server" //
};
}
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
p.ChatOnly = true;
player.setGameMode(GameMode.SPECTATOR);
player.sendMessage("§bChat-only mode enabled. You are now invincible.");
return true;
}
}

View file

@ -0,0 +1,27 @@
package buttondevteam.chat.components.appendext;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.IHaveConfig;
import lombok.val;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.function.Supplier;
public class AppendTextComponent extends Component {
private HashMap<String, IHaveConfig> appendTexts=new HashMap<>();
private ConfigData<String[]> helpText(IHaveConfig config) {
return config.getData("helpText", ()->new String[0]);
}
@Override
protected void enable() {
val cs=getConfig().getConfig(); //TODO
}
@Override
protected void disable() {
}
}

View file

@ -0,0 +1,62 @@
package buttondevteam.chat.components.chatonly;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.formatting.TellrawEvent;
import buttondevteam.chat.formatting.TellrawPart;
import buttondevteam.core.ComponentManager;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class ChatOnlyComponent extends Component implements Listener {
@Override
protected void enable() {
registerListener(this);
registerCommand(new ChatonlyCommand());
}
@Override
protected void disable() {
}
public static void playerJoin(ChatPlayer cp, Player p) {
if(!ComponentManager.isEnabled(ChatOnlyComponent.class))
return;
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
cp.ChatOnly = false;
p.setGameMode(GameMode.SURVIVAL);
}
}
public static void tellrawCreate(ChatPlayer mp, TellrawPart json) {
if(!ComponentManager.isEnabled(ChatOnlyComponent.class))
return;
if (mp != null && mp.ChatOnly) {
json.addExtra(new TellrawPart("[C]")
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class);
if (mp.ChatOnly)
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent e) {
if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) {
e.setCancelled(true);
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
}
}
}

View file

@ -0,0 +1,28 @@
package buttondevteam.chat.components.chatonly;
import buttondevteam.lib.chat.ICommand2MC;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.PlayerCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false, helpText = {
"§6---- Chat-only mode ----", //
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
"It was designed for chat clients", //
"Once enabled, the only way of disabling it is by relogging to the server" //
})
public final class ChatonlyCommand extends ICommand2MC {
public boolean def(Player player) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
p.ChatOnly = true;
player.setGameMode(GameMode.SPECTATOR);
player.sendMessage("§bChat-only mode enabled. You are now invincible.");
return true;
}
}

View file

@ -1,8 +1,10 @@
package buttondevteam.chat.commands;
package buttondevteam.chat.components.fun;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.player.TBMCPlayerBase;
import lombok.val;
@ -16,23 +18,17 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@CommandClass
public class FTopCommand extends TBMCCommandBase {
@Override
public String[] GetHelpText(String arg0) {
return new String[]{ //
"§6---- F Top ----", //
"Shows the respect leaderboard" //
};
}
@CommandClass(helpText = {
"§6---- F Top ----", //
"Shows the respect leaderboard" //
})
public class FTopCommand extends ICommand2MC {
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
private ChatPlayer[] cached;
private long lastcache = 0;
@Override
public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) {
public boolean def(CommandSender sender, @Command2.OptionalArg int page) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
@ -52,15 +48,13 @@ public class FTopCommand extends TBMCCommandBase {
}
int i;
try {
i = arg2.length > 0 ? Integer.parseInt(arg2[0]) : 1;
if (i < 1)
i = 1; //i=1
} catch (Exception e) {
i = 1;
}
i = page<1?1:page;
} catch (Exception e) {
i = 1;
}
val ai = new AtomicInteger();
arg0.sendMessage("§6---- Top Fs ----");
arg0.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
sender.sendMessage("§6---- Top Fs ----");
sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF()))
.collect(Collectors.joining("\n")));
});

View file

@ -2,6 +2,7 @@ package buttondevteam.chat.components.fun;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.player.TBMCPlayer;
@ -11,6 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
@ -30,6 +32,7 @@ public class FunComponent extends Component implements Listener {
registerListener(pc);
registerCommand(command=new UnlolCommand());
registerListener(this);
registerCommand(new FTopCommand());
}
@Override
@ -84,4 +87,8 @@ public class FunComponent extends Component implements Listener {
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
}
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
}
}

View file

@ -3,6 +3,7 @@ package buttondevteam.chat.listener;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PlayerJoinTimerTask;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
import buttondevteam.chat.components.fun.UnlolCommand;
import buttondevteam.chat.commands.ucmds.HistoryCommand;
import buttondevteam.chat.components.flair.FlairComponent;
@ -62,10 +63,7 @@ public class PlayerJoinLeaveListener implements Listener {
TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
cp.ChatOnly = false;
p.setGameMode(GameMode.SURVIVAL);
}
ChatOnlyComponent.playerJoin(cp, p);
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
}
@ -77,7 +75,6 @@ public class PlayerJoinLeaveListener implements Listener {
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
PlayerListener.nicknames.inverse().remove(event.getPlayer().getUniqueId());
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
}
}

View file

@ -176,21 +176,6 @@ public class PlayerListener implements Listener {
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class);
if (mp.ChatOnly)
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent e) {
if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) {
e.setCancelled(true);
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsoleCommand(ServerCommandEvent event) {
if (onCommandPreprocess(event.getSender(), event.getCommand()))