Skip to content

Commit

Permalink
add warmup for unstuck command
Browse files Browse the repository at this point in the history
improve code
update bStats
optimize pom.xml
  • Loading branch information
xGinko committed Mar 17, 2023
1 parent 3336774 commit f53b8e6
Show file tree
Hide file tree
Showing 43 changed files with 831 additions and 372 deletions.
20 changes: 11 additions & 9 deletions NetherCeiling-1.12.2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.xGinko</groupId>
<artifactId>NetherCeiling</artifactId>
<version>1.2.2--1.12.2</version>
<version>1.2.3--1.12.2</version>
<packaging>jar</packaging>

<name>NetherCeiling</name>
Expand Down Expand Up @@ -48,6 +48,14 @@
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -89,23 +97,17 @@
<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-BETA-3</version>
</dependency>
<!-- reflections used for auto-lang feature -->
<!-- reflections for auto-lang feature -->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<!-- Jetbrains Annotations for stuff like @NotNull -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.1.0</version>
</dependency>
<!-- bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.xginko.netherceiling;

import me.xginko.netherceiling.commands.NetherCeilingCmd;
import me.xginko.netherceiling.commands.UnstuckCmd;
import me.xginko.netherceiling.commands.NetherCeilingCommand;
import me.xginko.netherceiling.config.Config;
import me.xginko.netherceiling.config.LanguageCache;
import me.xginko.netherceiling.modules.NetherCeilingModule;
Expand All @@ -18,7 +17,6 @@
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand All @@ -45,27 +43,22 @@ public void onEnable() {
logger.info(" ");
logger.info(" ");

// Load lang and config
logger.info("Loading Translations");
reloadLang();

logger.info("Loading Config");
reloadNetherCeilingConfig();
reloadConfiguration();

// Register commands
logger.info("Registering Commands");
getCommand("netherceiling").setExecutor(new NetherCeilingCmd());
getCommand("unstuck").setExecutor(new UnstuckCmd());
NetherCeilingCommand.reloadCommands();

// Metrics
logger.info("Loading Metrics");
new Metrics(this, 17203);

// Resource-friendly TPS checker
ScheduledExecutorService schedulerTPS = Executors.newScheduledThreadPool(1);
schedulerTPS.scheduleAtFixedRate(() -> {
Thread thread = new Thread(() -> tps = getServer().getTPS()[0]);
thread.start();
}, 2, 1, TimeUnit.SECONDS);
// Scheduled TPS checker
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
new Thread(() -> tps = getServer().getTPS()[0]).start();
}, 1, 1, TimeUnit.SECONDS);

logger.info("Done.");
}
Expand Down Expand Up @@ -101,7 +94,13 @@ public static LanguageCache getLang(CommandSender commandSender) {
}
}

public void reloadNetherCeilingConfig() {
public void reloadPlugin() {
reloadLang();
reloadConfiguration();
NetherCeilingCommand.reloadCommands();
}

public void reloadConfiguration() {
config = new Config();
NetherCeilingModule.reloadModules();
config.saveConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.xginko.netherceiling.commands;

import me.xginko.netherceiling.NetherCeiling;
import me.xginko.netherceiling.commands.netherceiling.NetherCeilingCmd;
import me.xginko.netherceiling.commands.unstuck.UnstuckCmd;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;

import java.util.HashSet;

public interface NetherCeilingCommand extends CommandExecutor {

String label();

HashSet<NetherCeilingCommand> commands = new HashSet<>();
static void reloadCommands() {
commands.clear();

commands.add(new NetherCeilingCmd());
commands.add(new UnstuckCmd());

NetherCeiling plugin = NetherCeiling.getInstance();
CommandMap commandMap = plugin.getServer().getCommandMap();
for (NetherCeilingCommand command : commands) {
plugin.getCommand(command.label()).unregister(commandMap);
plugin.getCommand(command.label()).setExecutor(command);
}
}

@Override
boolean onCommand(CommandSender sender, Command command, String label, String[] args);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package me.xginko.netherceiling.commands.netherceiling;

import me.xginko.netherceiling.commands.NetherCeilingCommand;
import me.xginko.netherceiling.commands.SubCommand;
import me.xginko.netherceiling.commands.netherceiling.subcommands.ReloadSubCmd;
import me.xginko.netherceiling.commands.netherceiling.subcommands.VersionSubCmd;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

import java.util.ArrayList;
import java.util.List;

public class NetherCeilingCmd implements NetherCeilingCommand, TabCompleter {

private final List<SubCommand> subcommands = new ArrayList<>();
private final List<String> tabcompleters = new ArrayList<>();

public NetherCeilingCmd() {
subcommands.add(new ReloadSubCmd());
subcommands.add(new VersionSubCmd());
for (SubCommand subcommand : subcommands) {
tabcompleters.add(subcommand.getName());
}
}

@Override
public String label() {
return "netherceiling";
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase(label()) && args.length > 0 && args.length <=2) {
return tabcompleters;
}
return null;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase(label()) && args.length > 0) {
boolean cmdExists = false;
for (SubCommand subcommand : subcommands) {
if (args[0].equalsIgnoreCase(subcommand.getName())) {
subcommand.perform(sender, args);
cmdExists = true;
}
}
if (!cmdExists) showCommandOverviewTo(sender);
} else {
showCommandOverviewTo(sender);
}
return true;
}

private void showCommandOverviewTo(CommandSender sender) {
if (!sender.hasPermission("netherceiling.cmd.*")) return;
sender.sendMessage(ChatColor.GRAY+"-----------------------------------------------------");
sender.sendMessage(ChatColor.WHITE+"NetherCeiling Commands ");
sender.sendMessage(ChatColor.GRAY+"-----------------------------------------------------");
sender.sendMessage(ChatColor.WHITE+"/unstuck"+ChatColor.DARK_GRAY+" - "+ChatColor.GRAY+"Teleport yourself down from the nether ceiling.");
for (SubCommand subcommand : subcommands) {
sender.sendMessage(
ChatColor.WHITE + subcommand.getSyntax()
+ ChatColor.DARK_GRAY + " - "
+ ChatColor.GRAY + subcommand.getDescription()
);
}
sender.sendMessage(ChatColor.GRAY+"-----------------------------------------------------");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.xginko.netherceiling.commands.subcommands;
package me.xginko.netherceiling.commands.netherceiling.subcommands;

import org.jetbrains.annotations.NotNull;
import me.xginko.netherceiling.NetherCeiling;
import me.xginko.netherceiling.commands.SubCommand;
import org.bukkit.ChatColor;
Expand All @@ -22,12 +21,10 @@ public String getSyntax() {
}

@Override
public void perform(@NotNull CommandSender sender, String[] args) {
public void perform(CommandSender sender, String[] args) {
if (sender.hasPermission("netherceiling.cmd.reload")) {
sender.sendMessage(ChatColor.RED + "Reloading NetherCeiling config...");
NetherCeiling plugin = NetherCeiling.getInstance();
plugin.reloadLang();
plugin.reloadNetherCeilingConfig();
NetherCeiling.getInstance().reloadPlugin();
sender.sendMessage(ChatColor.GREEN + "Reload complete.");
} else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', NetherCeiling.getLang(sender).noPermission));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.xginko.netherceiling.commands.subcommands;
package me.xginko.netherceiling.commands.netherceiling.subcommands;

import org.jetbrains.annotations.NotNull;
import me.xginko.netherceiling.NetherCeiling;
import me.xginko.netherceiling.commands.SubCommand;
import org.bukkit.ChatColor;
Expand All @@ -22,7 +21,7 @@ public String getSyntax() {
}

@Override
public void perform(@NotNull CommandSender sender, String[] args) {
public void perform(CommandSender sender, String[] args) {
if (sender.hasPermission("netherceiling.cmd.version")) {
sender.sendMessage("\n");
sender.sendMessage(
Expand Down
Loading

0 comments on commit f53b8e6

Please sign in to comment.