Skip to content

Commit

Permalink
🐛[main/App] Merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymalc committed Aug 19, 2021
1 parent 3fd3752 commit 9292ec7
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.linyuanlin.minecraft.manager;

import com.linyuanlin.minecraft.App;
import org.bukkit.plugin.java.JavaPlugin;
import com.tjplaysnow.discord.object.Bot;
import com.tjplaysnow.discord.object.ThreadSpigot;
import net.dv8tion.jda.api.entities.TextChannel;
Expand All @@ -13,9 +14,13 @@ public class DiscordBotManager {
// Key: Bot Tag, Value: Bot
private final HashMap<String, Bot> bots = new HashMap<>();

public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

public void registerNewBot(String tag, String token) {
Bot b = new Bot(token, tag);
b.setBotThread(new ThreadSpigot(App.getPlugin()));
b.setBotThread(new ThreadSpigot(getPlugin()));
bots.put(tag, b);
}

Expand All @@ -32,20 +37,20 @@ public void shutDownAllBot() {
public void sendMessage(String botTag, String channelTag, String message) {
Bot bot = bots.get(botTag);
if (bot == null) {
App.getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
+ " because bot is not exist.");
return;
}
String cId = textChannels.get(channelTag);
if (cId == null) {
App.getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
+ " because channel is not exist.");
return;
}

TextChannel c = bot.getBot().getTextChannelById(cId);
if (c == null) {
App.getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
getPlugin().getLogger().warning("Cannot let bot " + botTag + " send message to channel " + channelTag
+ " because channel is not exist.");
return;
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/linyuanlin/minecraft/Manager/GuildManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.util.*;

public class GuildManager implements CommandExecutor {
public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

public GuildManager() {
Objects.requireNonNull(App.getPlugin().getCommand("guild")).setExecutor(this);
Objects.requireNonNull(getPlugin().getCommand("guild")).setExecutor(this);
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
try {
PlayerData p = App.getPlugin().allPlayers.get(((Player) sender).getUniqueId());
PlayerData p = getPlugin().allPlayers.get(((Player) sender).getUniqueId());
if (p == null) {
return false;
}
Expand All @@ -40,7 +45,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
App.getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mongodb.client.model.Filters;
import java.util.*;
import org.bukkit.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.bson.Document;

Expand All @@ -14,13 +15,17 @@ public class LocationManager {
public final static String lobby_spawn = "lobby_spawn";
public final static String house_spawn = "house_spawn";

public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

private HashMap<String, Location> tagLocationMap = new HashMap<>();;

public void loadLocations() {
List<Document> docList = App.getPlugin().dbClient.findMany("Location", Filters.empty());
List<Document> docList = getPlugin().dbClient.findMany("Location", Filters.empty());
for (Document doc : docList) {
tagLocationMap.put(doc.getString("tag"), this.getLocation(
App.getPlugin().worldManager.getWorldData(WorldManager.world_lobby).getWorld(),
getPlugin().worldManager.getWorldData(WorldManager.world_lobby).getWorld(),
doc));
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/linyuanlin/minecraft/Manager/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.*;
Expand All @@ -18,15 +19,19 @@ public class TeamManager implements CommandExecutor {
*/
public final static int INVITE_COOLING_MINS = 1;

public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

public TeamManager() {
Objects.requireNonNull(App.getPlugin().getCommand("team")).setExecutor(this);
Objects.requireNonNull(getPlugin().getCommand("team")).setExecutor(this);
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
try {
PlayerData p = App.getPlugin().allPlayers.get(((Player) sender).getUniqueId());
PlayerData p = getPlugin().allPlayers.get(((Player) sender).getUniqueId());
if (p == null) {
return false;
}
Expand All @@ -47,7 +52,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
App.getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
return false;
}
}
Expand Down Expand Up @@ -88,14 +93,14 @@ private boolean invite(PlayerData senderPlayer, String[] args) {
return false;
}

PlayerData receiverPlayer = App.getPlugin().allPlayers.get(p.getUniqueId());
PlayerData receiverPlayer = getPlugin().allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player().sendMessage("你邀請的玩家 " + ChatColor.GOLD + args[1] + ChatColor.WHITE
+ " 不存在於allPlayers中,請聯繫開發人員");
return false;
}

Optional<Team> team = App.getPlugin().allPlayers.get(receiverPlayer.player().getUniqueId()).team();
Optional<Team> team = getPlugin().allPlayers.get(receiverPlayer.player().getUniqueId()).team();

if (receiverPlayer == senderPlayer) {
senderPlayer.player().sendMessage(ChatColor.RED + "不能邀請自己");
Expand Down Expand Up @@ -163,7 +168,7 @@ private boolean join(PlayerData senderPlayer, String[] args) throws Exception {
"你要加入的隊伍的邀請人 " + ChatColor.GOLD + args[1] + ChatColor.WHITE + " 不存在或是不在線上!");
return false;
}
PlayerData receiverPlayer = App.getPlugin().allPlayers.get(p.getUniqueId());
PlayerData receiverPlayer = getPlugin().allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player().sendMessage("你要加入的隊伍的邀請人" + ChatColor.GOLD + args[1] + ChatColor.WHITE
+ "不存在於allPlayers中, 請聯繫開發人員");
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/linyuanlin/minecraft/Manager/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;

Expand All @@ -15,16 +16,20 @@ public class TradeManager implements CommandExecutor {
* constants
*/

public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

public TradeManager() {
Objects.requireNonNull(App.getPlugin().getCommand("trade")).setExecutor(this);
Objects.requireNonNull(getPlugin().getCommand("trade")).setExecutor(this);
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {

try {
PlayerData p = App.getPlugin().allPlayers.get(((Player) sender).getUniqueId());
PlayerData p = getPlugin().allPlayers.get(((Player) sender).getUniqueId());

if (p == null) {
return false;
Expand All @@ -42,7 +47,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
App.getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
getPlugin().discordBotManager.sendMessage("TEST", "Project-Minecraft", sw.toString());
return false;
}
}
Expand Down Expand Up @@ -80,7 +85,7 @@ private boolean pay(PlayerData senderPlayer, String[] args) {
return false;
}

PlayerData receiverPlayer = App.getPlugin().allPlayers.get(p.getUniqueId());
PlayerData receiverPlayer = getPlugin().allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player().sendMessage(
"玩家 " + ChatColor.GOLD + receiverName + ChatColor.WHITE + " 不存在或是不在線上");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class PluginMessageHandler implements PluginMessageListener {
public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

@Override
public void onPluginMessageReceived(String channel, @NotNull Player player, byte[] message) {
Bukkit.getConsoleSender().sendMessage("receive plugin message");
Expand Down Expand Up @@ -49,7 +54,7 @@ public void sendPluginMessage(String subChannel, String PluginMessage) {
out.writeUTF(subChannel);
out.writeUTF(PluginMessage);
Bukkit.getConsoleSender().sendMessage("send plugin message: " + subChannel + ' ' + PluginMessage);
Objects.requireNonNull(Iterables.getFirst(Bukkit.getOnlinePlayers(), null)).sendPluginMessage(App.getPlugin(),
Objects.requireNonNull(Iterables.getFirst(Bukkit.getOnlinePlayers(), null)).sendPluginMessage(getPlugin(),
"BungeeCord", out.toByteArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
import com.mongodb.client.*;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.*;

public class MongodbClient {
public static App getPlugin() {
return JavaPlugin.getPlugin(App.class);
}

public FindIterable<Document> cursor;
private MongoClient client;
private MongoDatabase database;

public MongodbClient(String databaseName) {
try {
this.client = MongoClients.create(App.getPlugin().mongodbConnectString);
this.client = MongoClients.create(getPlugin().mongodbConnectString);
this.database = this.client.getDatabase(databaseName);
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 9292ec7

Please sign in to comment.