Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
needkg committed Jul 14, 2024
1 parent 60f057e commit b0bcf16
Show file tree
Hide file tree
Showing 64 changed files with 1,364 additions and 2,887 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
.DS_Store

# intellij
dependency-reduced-pom.xml
*.iml
*.ipr
*.iws
Expand Down
13 changes: 0 additions & 13 deletions DayNightPvP.iml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ day.

# Support

Need assistance or have a suggestion? Join our Discord community: [click here](https://discord.needkg.online)
Need assistance or have a suggestion? Join our Discord community: [click here](https://discord.needkg.com)

# Features

Expand Down Expand Up @@ -55,7 +55,7 @@ Need assistance or have a suggestion? Join our Discord community: [click here](h

# Commands

/dnp → Open the GUI
/dnp → Show all commands
/dnp reload → Reload the plugin

# WorldGuard Flags
Expand Down
64 changes: 35 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.needkg</groupId>
<groupId>org.callv2</groupId>
<artifactId>DayNightPvP</artifactId>
<name>DayNightPvP</name>
<version>1.2.5.4</version>
<version>1.2.6.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<java.version>1.8</java.version>
<shade.base>org.callv2.daynightpvp</shade.base>
<spigot.prefix>${project.name}</spigot.prefix>
<spigot.main>${project.groupId}.daynightpvp.DayNightPvP</spigot.main>
</properties>
Expand All @@ -38,11 +39,33 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>${shade.base}.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
<repositories>
Expand All @@ -52,11 +75,6 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>

<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>

<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
Expand All @@ -67,11 +85,6 @@
<url>https://jitpack.io</url>
</repository>

<repository>
<id>destroystokyo-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public//</url>
</repository>

<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
Expand All @@ -87,6 +100,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
Expand All @@ -101,13 +121,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
Expand All @@ -122,12 +135,5 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>7.2.14</version>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
93 changes: 93 additions & 0 deletions src/main/java/org/callv2/daynightpvp/DayNightPvP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.callv2.daynightpvp;

import org.bukkit.plugin.java.JavaPlugin;
import org.callv2.daynightpvp.bstats.BStatsHandler;
import org.callv2.daynightpvp.commands.CommandHandler;
import org.callv2.daynightpvp.files.ConfigFile;
import org.callv2.daynightpvp.files.LangFile;
import org.callv2.daynightpvp.listeners.ListenersHandler;
import org.callv2.daynightpvp.placeholder.PlaceholderHandler;
import org.callv2.daynightpvp.runnables.RunnableHandler;
import org.callv2.daynightpvp.utils.ConsoleUtils;
import org.callv2.daynightpvp.utils.PluginUtils;
import org.callv2.daynightpvp.vault.LoseMoneyOnDeath;
import org.callv2.daynightpvp.worldguard.FlagHandler;

public class DayNightPvP extends JavaPlugin {

public static boolean vaultIsPresent;
public static boolean griefIsPresent;
public static boolean worldGuardIsPresent;
public static boolean placeHolderIsPresent;

private static DayNightPvP instance;

private final ConfigFile configFile;
private final LangFile langFile;
private final CommandHandler commandHandler;
private final ListenersHandler listenersHandler;
private final PlaceholderHandler placeholderHandler;
private final RunnableHandler runnableHandler;
private final BStatsHandler bStatsHandler;

public DayNightPvP() {
instance = this;

configFile = new ConfigFile();
langFile = new LangFile(configFile);

runnableHandler = new RunnableHandler(configFile, langFile);

LoseMoneyOnDeath loseMoneyOnDeath = new LoseMoneyOnDeath(configFile, langFile);

commandHandler = new CommandHandler(langFile, loseMoneyOnDeath, runnableHandler);
listenersHandler = new ListenersHandler(configFile, langFile, loseMoneyOnDeath);
placeholderHandler = new PlaceholderHandler(langFile, configFile);
bStatsHandler = new BStatsHandler();

}

@Override
public void onLoad() {
verifyCompatibilityPlugins();

if (worldGuardIsPresent) {
FlagHandler.register();
}
}

@Override
public void onEnable() {
ConsoleUtils.sendStartupMessage();

configFile.createFile();
langFile.createFile();

bStatsHandler.start();

commandHandler.register();

listenersHandler.register();

placeholderHandler.register();

runnableHandler.startAllRunnables();
}

@Override
public void onDisable() {
runnableHandler.stopAllRunnables();
}

public static DayNightPvP getInstance() {
return instance;
}

private void verifyCompatibilityPlugins() {
vaultIsPresent = PluginUtils.isPluginInstalled("Vault");
worldGuardIsPresent = PluginUtils.isPluginInstalled("WorldGuard");
griefIsPresent = PluginUtils.isPluginInstalled("GriefPrevention");
placeHolderIsPresent = PluginUtils.isPluginInstalled("PlaceholderAPI");
}

}
13 changes: 13 additions & 0 deletions src/main/java/org/callv2/daynightpvp/bstats/BStatsHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.callv2.daynightpvp.bstats;

import org.bstats.bukkit.Metrics;
import org.callv2.daynightpvp.DayNightPvP;

public class BStatsHandler {

public void start() {
int bStatsID = 19067;
new Metrics(DayNightPvP.getInstance(), bStatsID);
}

}
27 changes: 27 additions & 0 deletions src/main/java/org/callv2/daynightpvp/commands/CommandHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.callv2.daynightpvp.commands;

import org.callv2.daynightpvp.DayNightPvP;
import org.callv2.daynightpvp.files.LangFile;
import org.callv2.daynightpvp.runnables.RunnableHandler;
import org.callv2.daynightpvp.vault.LoseMoneyOnDeath;

public class CommandHandler {

private final LangFile langFile;
private final LoseMoneyOnDeath loseMoneyOnDeath;
private final RunnableHandler runnableHandler;

public CommandHandler(LangFile langFile, LoseMoneyOnDeath loseMoneyOnDeath, RunnableHandler runnableHandler) {
this.langFile = langFile;
this.loseMoneyOnDeath = loseMoneyOnDeath;
this.runnableHandler = runnableHandler;
}

public void register() {

DnpCommand dnpCommand = new DnpCommand(langFile, loseMoneyOnDeath, runnableHandler);

DayNightPvP.getInstance().getCommand("daynightpvp").setExecutor(dnpCommand);
DayNightPvP.getInstance().getCommand("daynightpvp").setTabCompleter(dnpCommand);
}
}
88 changes: 88 additions & 0 deletions src/main/java/org/callv2/daynightpvp/commands/DnpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.callv2.daynightpvp.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.callv2.daynightpvp.commands.subcommands.ReloadSubCommand;
import org.callv2.daynightpvp.files.LangFile;
import org.callv2.daynightpvp.runnables.RunnableHandler;
import org.callv2.daynightpvp.services.PluginServices;
import org.callv2.daynightpvp.utils.PlayerUtils;
import org.callv2.daynightpvp.vault.LoseMoneyOnDeath;
import org.jetbrains.annotations.NotNull;

import java.util.*;

import static java.util.stream.Collectors.toList;

public class DnpCommand implements CommandExecutor, TabCompleter {

private final LangFile langFile;
private final LoseMoneyOnDeath loseMoneyOnDeath;
private final RunnableHandler runnableHandler;

private final Map<String, ISubCommand> subCommands = new HashMap<>();

public DnpCommand(LangFile langFile, LoseMoneyOnDeath loseMoneyOnDeath, RunnableHandler runnableHandler) {
this.langFile = langFile;
this.loseMoneyOnDeath = loseMoneyOnDeath;
this.runnableHandler = runnableHandler;

registerSubCommands();
}

private void registerSubCommands() {
subCommands.put("reload", new ReloadSubCommand(langFile, new PluginServices(loseMoneyOnDeath, runnableHandler)));
}

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

if (args.length == 0) {

PlayerUtils.sendMessage(sender, "");
PlayerUtils.sendMessage(sender,"§7§l* §a§lCommands§7:");
PlayerUtils.sendMessage(sender,"");
PlayerUtils.sendMessage(sender,"§7§l* §7/§9dnp §8-> §7Show all available commands.");
PlayerUtils.sendMessage(sender,"§7§l* §7/§9dnp reload §8-> §7Reload the plugin.");
return true;
}

ISubCommand dnpSubCommand = subCommands.get(args[0]);

if (dnpSubCommand == null) {
PlayerUtils.sendMessage(sender, langFile.getFeedbackNonExistentCommand());
return true;
}

dnpSubCommand.executeCommand(sender, command, commandLabel, args);
return true;
}

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length < 1) return null;

if (args.length == 1) {
return this.subCommands.keySet().stream()
.filter(subCmd -> sender.hasPermission("dnp.admin"))
.filter(subCmd -> subCmd.contains(args[0]) || subCmd.equalsIgnoreCase(args[0]))
.sorted()
.collect(toList());
}

String cmdName = this.subCommands.keySet().stream()
.filter(subCmd -> subCmd.equalsIgnoreCase(args[0]))
.findFirst().orElse(null);

if (cmdName == null) return new ArrayList<>();

if (this.subCommands.containsKey(cmdName)) {
return this.subCommands.get(cmdName).tabComplete(sender, command, alias, Arrays.asList(args).subList(1, args.length));
}

return new ArrayList<>();
}

}
Loading

0 comments on commit b0bcf16

Please sign in to comment.