Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi servers #18

Merged
merged 9 commits into from
Nov 16, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.azisaba.lgw.rankingdisplayer;

import jp.azisaba.lgw.rankingdisplayer.command.RankingDisplayerCommand;
import jp.azisaba.lgw.rankingdisplayer.command.RankingHoloCommand;
import jp.azisaba.lgw.rankingdisplayer.config.PluginConfig;
import jp.azisaba.lgw.rankingdisplayer.holo.DHListener;
Expand Down Expand Up @@ -27,6 +28,7 @@ public void onEnable() {
if (!Bukkit.getPluginManager().isPluginEnabled("KDStatusReloaded")) {
getLogger().severe("KDStatusReloaded is not loaded.");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

// Migrate
Expand Down Expand Up @@ -57,6 +59,9 @@ public void onEnable() {
Bukkit.getPluginCommand("rankingholo").setExecutor(new RankingHoloCommand());
Bukkit.getPluginCommand("rankingholo").setPermissionMessage(ChatColor.RED + "権限がありません!");

Bukkit.getPluginCommand("rankingdisplayer").setExecutor(new RankingDisplayerCommand(this));
Bukkit.getPluginCommand("rankingdisplayer").setPermissionMessage(ChatColor.RED + "権限がありません!");

if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
new KDSPlaceholderExpansion().register();
}
Expand All @@ -67,19 +72,16 @@ public void onEnable() {

@Override
public void onDisable() {
// if (listener != null) {
// listener.removeAllBoards();
// }

Bukkit.getLogger().info(getName() + " disabled.");
}

public void reloadPluginConfig() {

getLogger().info("Reloading plugin config...");
reloadConfig();

RankingDisplayer.config = new PluginConfig(this);
RankingDisplayer.config.loadConfig();
getLogger().info("Successfully to reload plugin config!");
}

public static PluginConfig getPluginConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package jp.azisaba.lgw.rankingdisplayer.command;

import jp.azisaba.lgw.rankingdisplayer.RankingDisplayer;
import lombok.RequiredArgsConstructor;
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;

@RequiredArgsConstructor
public class RankingDisplayerCommand implements CommandExecutor {
private final RankingDisplayer plugin;

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if (args.length < 1) {
return false;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (args[0].equals("reload")) {
if (args.length != 2) {
sender.sendMessage("/" + command.getName() + " reload <type>");
return true;
}
if (args[1].equals("config")) {
sender.sendMessage("Reloading config...");
plugin.reloadPluginConfig();
sender.sendMessage("Completed to reload config!");
return true;
}
sender.sendMessage("No type matched: " + args[1]);
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ public void loadConfig() {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ConfigOptions {
public String path();
String path();

public OptionType type() default OptionType.NONE;
OptionType type() default OptionType.NONE;
}

public enum OptionType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jp.azisaba.lgw.rankingdisplayer.holo;
package jp.azisaba.lgw.rankingdisplayer.old;

import com.google.common.base.Strings;
import jp.azisaba.lgw.kdstatus.KDStatusReloaded;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class DisplayListener implements Listener {

private final long cacheHoldMilliSec = 1000 * 10;

private static String HEADER = ChatColor.AQUA + Strings.repeat("=", 8) + " " + ChatColor.GOLD
private final static String HEADER = ChatColor.AQUA + Strings.repeat("=", 8) + " " + ChatColor.GOLD
+ "Kill Ranking " + ChatColor.AQUA + Strings.repeat("=", 8);

private final HashMap<Player, Long> updatedTime = new HashMap<>();
Expand Down Expand Up @@ -206,12 +206,10 @@ private void displayRanking(RankingType type, Hologram holo, Player p, boolean i

long end = System.currentTimeMillis();

plugin.getLogger().info("Displayed " + type.toString() + " Ranking for " + p.getName() + " async ("
plugin.getLogger().info("Displayed " + type + " Ranking for " + p.getName() + " async ("
+ (end - start - (endedSynchro - waitingSynchro) + rankingDataFetchTime) + "ms)");

Bukkit.getScheduler().runTaskLater(plugin, () -> {
processingPlayers.remove(p);
}, 0);
Bukkit.getScheduler().runTaskLater(plugin, () -> processingPlayers.remove(p), 0);
});
}

Expand Down Expand Up @@ -281,7 +279,7 @@ private void setRankingData(Hologram holo, Player p, List<KillRankingData> dataL

int kills = kdsPlugin.getKdDataContainer().getPlayerData(p, true).getKills(unit);

String line = ChatColor.BLUE + "YOU" + ChatColor.RED + " » " + ChatColor.YELLOW + "" + rankingStr + "位 " +
String line = ChatColor.BLUE + "YOU" + ChatColor.RED + " » " + ChatColor.YELLOW + rankingStr + "位 " +
ChatColor.GOLD + p.getName() + ChatColor.RED + ": " + ChatColor.AQUA + kills + " kill(s)";

if (RankingHideManager.isHiding(p.getUniqueId())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.azisaba.lgw.rankingdisplayer.holo;
package jp.azisaba.lgw.rankingdisplayer.old;

import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand All @@ -12,8 +13,8 @@
*/
public class Hologram {

private static String version;
private static int versionNumber;
private static final String version;
private static final int versionNumber;
private static Class<?> armorStand, spawnPacket, world, craftWorld, craftPlayer, iChatBaseComponent,
chatComponentText, entityLiving, entityPlayer, playerConnection, packetRaw, nbtTagCompound, packetDestroy,
packetTeleport;
Expand Down Expand Up @@ -79,14 +80,6 @@ public Location getLocation() {
return defaultLocation;
}

public void setSpace(double space) {
this.space = space;
}

public double getSpace() {
return space;
}

public List<String> getLines() {
return messages;
}
Expand All @@ -99,7 +92,8 @@ public String getLine(int line) {
return messages.get(line);
}

private double space = 0.3;
@Getter
private final double space = 0.3;
private final HashMap<Player, HoloComponent> holoMap = new HashMap<>();

public void display(Player... players) {
Expand Down Expand Up @@ -166,8 +160,8 @@ public void removeFrom(Player... players) {
int[] ids = new int[idList.size()];

int count = 0;
for (Integer i : idList) {
ids[count] = i.intValue();
for (int i : idList) {
ids[count] = i;
count++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class RankingCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
public boolean onCommand(CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
sender.sendMessage(ChatColor.RED + "/settings" + ChatColor.GRAY + "に移行しました!");
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ commands:
rankingholo:
usage: /rankingholo <place|remove|remove-all|list>
permission: rankingdisplayer.command.rankingholo
rankingdisplayer:
usage: /rankingdisplayer <reload>
permission: rankingdisplayer.command.rankingdisplayer
permissions:
rankingdisplayer.command.ranking:
default: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package jp.azisaba.lgw.rankingdisplay.ranking;

import jp.azisaba.lgw.kdstatus.utils.TimeUnit;
import jp.azisaba.lgw.rankingdisplay.TestSize;
import jp.azisaba.lgw.rankingdisplayer.ranking.RankingType;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.Locale;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

@Tag(TestSize.SMALL)
public class RankingTypeTest {
@Test
public void ConversionTest() {
assertEquals(RankingType.DAILY, RankingType.getType("daily"));
assertEquals(RankingType.MONTHLY, RankingType.getType("monthly"));
assertEquals(RankingType.TOTAL, RankingType.getType("total"));
assertNull(RankingType.getType("none"));
}

@Test
public void ReConversionTest() {
assertEquals(RankingType.DAILY, RankingType.getType(RankingType.DAILY.name().toLowerCase(Locale.ROOT)));
assertEquals(RankingType.MONTHLY, RankingType.getType(RankingType.MONTHLY.name().toLowerCase(Locale.ROOT)));
assertEquals(RankingType.TOTAL, RankingType.getType(RankingType.TOTAL.name().toLowerCase(Locale.ROOT)));
}

@Test
public void TimeUnitMatchTest() {
assertEquals(TimeUnit.DAILY, RankingType.DAILY.getKdStatusTimeUnit());
assertEquals(TimeUnit.MONTHLY, RankingType.MONTHLY.getKdStatusTimeUnit());
assertEquals(TimeUnit.LIFETIME, RankingType.TOTAL.getKdStatusTimeUnit());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

@Tag(TestSize.SMALL)
@Tag(TestSize.MEDIUM)
public class DateFormatUtilsTest {
@Test
public void FormatCalenderBySingle() {
Expand All @@ -26,7 +26,7 @@ public void FormatCalenderBySingle() {

// Execute
testcases.forEach((timeMill, expectation) -> {
Calendar calendar = Calendar.getInstance();
Calendar calendar = new Calendar.Builder().setInstant(0).build();
calendar.setTimeInMillis(timeMill);
assertEquals(expectation, DateFormatUtils.format(calendar));
});
Expand Down