mirror of
https://github.com/darverdevs/Uranium.git
synced 2024-11-21 23:06:04 -08:00
feat: add User class
This commit is contained in:
parent
5a28ececd2
commit
a62fca9405
|
@ -1,4 +1,4 @@
|
|||
package darverdevs;
|
||||
package uranium;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -9,8 +9,10 @@ public class Main extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void setupConfig() {
|
||||
getLogger().info("Initializing config...");
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
getLogger().info("Done!");
|
||||
}
|
||||
|
||||
}
|
127
src/main/java/uranium/user/User.java
Normal file
127
src/main/java/uranium/user/User.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package uranium.user;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import uranium.Main;
|
||||
import uranium.util.StringUtil;
|
||||
|
||||
// To my knowledge, there's no other way around the warnings in `sendBungeeMessage`.
|
||||
@SuppressWarnings({"UnstableApiUsage"})
|
||||
public class User {
|
||||
|
||||
private final Player player;
|
||||
private final String name;
|
||||
private String lastMessage;
|
||||
private Long lastMessageMS;
|
||||
private String ip;
|
||||
private String domain;
|
||||
private boolean vanished;
|
||||
private boolean staffChat;
|
||||
private boolean commandSpy;
|
||||
|
||||
public User(Player player) {
|
||||
this.player = player;
|
||||
this.name = player.getName();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public String getLastMessage() {
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
public void setLastMessage(String lastMessage) {
|
||||
this.lastMessage = lastMessage;
|
||||
}
|
||||
|
||||
public Long getLastMessageMS() {
|
||||
return lastMessageMS;
|
||||
}
|
||||
|
||||
public void setLastMessageMS(Long lastMessageMS) {
|
||||
this.lastMessageMS = lastMessageMS;
|
||||
}
|
||||
|
||||
public String getIP() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIP(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public boolean isVanished() {
|
||||
return vanished;
|
||||
}
|
||||
|
||||
public void setVanished(boolean vanished) {
|
||||
this.vanished = vanished;
|
||||
if (vanished)
|
||||
UserManager.getUsers().forEach((user) -> {
|
||||
if (!user.hasPermission("uranium.vanish"))
|
||||
user.getPlayer().hidePlayer(player);
|
||||
});
|
||||
else UserManager.getUsers().forEach((user) -> user.getPlayer().showPlayer(player));
|
||||
}
|
||||
|
||||
public boolean isStaffChat() {
|
||||
return staffChat;
|
||||
}
|
||||
|
||||
public void setStaffChat(boolean staffChat) {
|
||||
this.staffChat = staffChat;
|
||||
}
|
||||
|
||||
public boolean isCommandSpy() {
|
||||
return commandSpy;
|
||||
}
|
||||
|
||||
public void setCommandSpy(boolean commandSpy) {
|
||||
this.commandSpy = commandSpy;
|
||||
}
|
||||
|
||||
public void sendBungeeMessage(Player player, String channel, String message) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(channel);
|
||||
out.writeUTF(message);
|
||||
|
||||
player.sendPluginMessage(JavaPlugin.getPlugin(Main.class), "BungeeCord", out.toByteArray());
|
||||
}
|
||||
|
||||
public void sendBungeeMessage(Player player, String channel) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(channel);
|
||||
|
||||
player.sendPluginMessage(JavaPlugin.getPlugin(Main.class), "BungeeCord", out.toByteArray());
|
||||
}
|
||||
|
||||
public void onJoin() {
|
||||
sendBungeeMessage(player, "IP");
|
||||
sendBungeeMessage(player, "EAG|GetDomain");
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
player.sendMessage(StringUtil.cc(message));
|
||||
}
|
||||
}
|
33
src/main/java/uranium/user/UserManager.java
Normal file
33
src/main/java/uranium/user/UserManager.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package uranium.user;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class UserManager {
|
||||
|
||||
private static final HashMap<String, User> users;
|
||||
|
||||
static {
|
||||
users = new HashMap<>();
|
||||
}
|
||||
|
||||
public static User addUser(Player player) {
|
||||
users.put(player.getName().toLowerCase(), new User(player));
|
||||
return users.get(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static User getUser(Player player) {
|
||||
return users.get(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static void removeUser(Player player) {
|
||||
users.remove(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static Collection<User> getUsers() {
|
||||
return users.values();
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/uranium/util/StringUtil.java
Normal file
11
src/main/java/uranium/util/StringUtil.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package uranium.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
public static String cc(String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
name: Uranium
|
||||
version: 1.0.0-LITE
|
||||
main: darverdevs.Main
|
||||
main: uranium.Main
|
||||
description: A moderation utility for Eaglercraft 1.8 servers.
|
||||
author: Cold
|
||||
softdepend: [PlaceholderAPI]
|
Loading…
Reference in New Issue
Block a user