Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
needkg committed Jul 3, 2024
1 parent f5d9124 commit d4f61da
Show file tree
Hide file tree
Showing 45 changed files with 662 additions and 1,232 deletions.
13 changes: 0 additions & 13 deletions DayNightPvP.iml

This file was deleted.

6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<java.version>1.8</java.version>
<spigot.prefix>${project.name}</spigot.prefix>
<spigot.main>${project.groupId}.daynightpvp.DayNightPvP</spigot.main>
</properties>
Expand All @@ -38,8 +38,8 @@
<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>

Expand Down
90 changes: 45 additions & 45 deletions src/main/java/org/callvdois/daynightpvp/DayNightPvP.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.callvdois.daynightpvp.commands.CommandManager;
import org.callvdois.daynightpvp.config.FilesManager;
import org.callvdois.daynightpvp.events.EventsManager;
import org.callvdois.daynightpvp.metrics.MetricsManager;
import org.callvdois.daynightpvp.placeholder.PlaceholderManager;
import org.callvdois.daynightpvp.service.ServiceManager;
import org.callvdois.daynightpvp.Listeners.ListenersHandler;
import org.callvdois.daynightpvp.commands.CommandHandler;
import org.callvdois.daynightpvp.files.ConfigFile;
import org.callvdois.daynightpvp.files.LangFile;
import org.callvdois.daynightpvp.metrics.MetricsHandler;
import org.callvdois.daynightpvp.placeholder.PlaceholderHandler;
import org.callvdois.daynightpvp.runnables.RunnableHandler;
import org.callvdois.daynightpvp.utils.ConsoleUtils;
import org.callvdois.daynightpvp.utils.PluginUtils;
import org.callvdois.daynightpvp.worldguard.WorldGuardManager;
import org.callvdois.daynightpvp.worldguard.FlagHandler;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -23,24 +24,30 @@ public class DayNightPvP extends JavaPlugin {
public static boolean placeHolderIsPresent;
public static List<BukkitTask> serviceTasks = new ArrayList<>();
private static DayNightPvP instance;
private final FilesManager filesManager;
private final CommandManager commandManager;
private final EventsManager eventsManager;
private final PlaceholderManager placeholderManager;
private final WorldGuardManager worldGuardManager;
private final ServiceManager serviceManager;
private final MetricsManager metricsManager;
private final ConsoleUtils consoleUtils;
private final ConfigFile configFile;
private final LangFile langFile;
private final CommandHandler commandHandler;
private final ListenersHandler listenersHandler;
private final PlaceholderHandler placeholderHandler;
private final FlagHandler flagHandler;
private final RunnableHandler runnableHandler;
private final MetricsHandler metricsHandler;
private final PluginUtils pluginUtils;

public DayNightPvP() {
instance = this;

filesManager = new FilesManager();
commandManager = new CommandManager();
eventsManager = new EventsManager();
placeholderManager = new PlaceholderManager();
worldGuardManager = new WorldGuardManager();
serviceManager = new ServiceManager();
metricsManager = new MetricsManager();
consoleUtils = new ConsoleUtils();
configFile = new ConfigFile();
langFile = new LangFile();
commandHandler = new CommandHandler();
listenersHandler = new ListenersHandler();
placeholderHandler = new PlaceholderHandler();
flagHandler = new FlagHandler();
runnableHandler = new RunnableHandler();
metricsHandler = new MetricsHandler();
pluginUtils = new PluginUtils();

}

Expand All @@ -50,49 +57,42 @@ public static DayNightPvP getInstance() {

@Override
public void onLoad() {
load();
}

@Override
public void onEnable() {
enable();
}

private void load() {

verifyCompatibilityPlugins();

if (worldGuardIsPresent) {
worldGuardManager.register();
flagHandler.register();
}
}

private void enable() {
ConsoleUtils.startMessage();
@Override
public void onEnable() {
consoleUtils.sendStartupMessage();

filesManager.createFiles();
metricsHandler.start();

commandManager.register();
configFile.createFile();
langFile.createFile();

eventsManager.register();
commandHandler.register();

placeholderManager.register();
listenersHandler.register();

serviceManager.startServices();
placeholderHandler.register();

metricsManager.register();
runnableHandler.startAllRunnables();
}


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

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

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.callvdois.daynightpvp.events;
package org.callvdois.daynightpvp.Listeners;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand All @@ -10,22 +10,24 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.callvdois.daynightpvp.DayNightPvP;
import org.callvdois.daynightpvp.config.ConfigManager;
import org.callvdois.daynightpvp.config.LangManager;
import org.callvdois.daynightpvp.griefprevention.GriefManager;
import org.callvdois.daynightpvp.files.ConfigFile;
import org.callvdois.daynightpvp.files.LangFile;
import org.callvdois.daynightpvp.griefprevention.GriefPreventionHandler;
import org.callvdois.daynightpvp.utils.WorldUtils;
import org.callvdois.daynightpvp.worldguard.AllowPvpOnDayFlag;
import org.callvdois.daynightpvp.worldguard.AllowDaytimePvpFlag;

public class DamageEvent implements Listener {
public class DamageListener implements Listener {

private final GriefManager griefManager;
private final ConfigManager configManager;
private final LangManager langManager;
private final GriefPreventionHandler griefPreventionHandler;
private final ConfigFile configFile;
private final LangFile langFile;
private final WorldUtils worldUtils;

public DamageEvent() {
griefManager = new GriefManager();
configManager = new ConfigManager();
langManager = new LangManager();
public DamageListener() {
griefPreventionHandler = new GriefPreventionHandler();
configFile = new ConfigFile();
langFile = new LangFile();
worldUtils = new WorldUtils();
}

@EventHandler
Expand All @@ -36,8 +38,8 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

if (checkHooks(damagedPlayer, damager)) {
event.setCancelled(true);
if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langManager.getNotifyPvpDisabled());
if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langFile.getNotifyPvpDisabled());
}
}
}
Expand All @@ -50,8 +52,8 @@ public void onProjectileHitEvent(ProjectileHitEvent event) {

if (checkHooks(damagedPlayer, damager)) {
event.setCancelled(true);
if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langManager.getNotifyPvpDisabled());
if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langFile.getNotifyPvpDisabled());
}
}

Expand All @@ -68,8 +70,8 @@ public void onPotionSplash(PotionSplashEvent event) {
if (event.getAffectedEntities().contains(damagedPlayer) && damagedPlayer != damager) {
if (checkHooks(damagedPlayer, damager)) {
event.setIntensity(damagedPlayer, 0.0);
if (configManager.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langManager.getNotifyPvpDisabled());
if (configFile.getNotifyPlayersChatHitAnotherPlayerDuringTheDay()) {
damager.sendMessage(langFile.getNotifyPvpDisabled());
}
}
}
Expand All @@ -91,13 +93,13 @@ private boolean checkHooks(Player damagedPlayer, Player damager) {
if (damager.hasPermission("dnp.bypasspvp")) {
return false;
}
if (DayNightPvP.worldGuardIsPresent && AllowPvpOnDayFlag.checkState(damagedPlayer) && AllowPvpOnDayFlag.checkState(damager)) {
if (DayNightPvP.worldGuardIsPresent && AllowDaytimePvpFlag.checkStateOnPosition(damagedPlayer) && AllowDaytimePvpFlag.checkStateOnPosition(damager)) {
return false;
}
if (DayNightPvP.griefIsPresent && !configManager.getGriefPreventionPvpInLandEnabled() && griefManager.verify(damagedPlayer, damager)) {
if (DayNightPvP.griefIsPresent && !configFile.getGriefPreventionPvpInLandEnabled() && griefPreventionHandler.verify(damagedPlayer, damager)) {
return true;
}
return WorldUtils.checkPlayerIsInWorld(damagedPlayer);
return worldUtils.checkPlayerIsInWorld(damagedPlayer);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.callvdois.daynightpvp.events;
package org.callvdois.daynightpvp.Listeners;

import org.bukkit.Bukkit;
import org.bukkit.World;
Expand All @@ -8,30 +8,32 @@
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.callvdois.daynightpvp.DayNightPvP;
import org.callvdois.daynightpvp.config.ConfigManager;
import org.callvdois.daynightpvp.files.ConfigFile;
import org.callvdois.daynightpvp.utils.SearchUtils;
import org.callvdois.daynightpvp.vault.LoseMoneyOnDeath;

import java.util.List;

public class DeathEvent implements Listener {
public class DeathListener implements Listener {

private final ConfigManager configManager;
private final ConfigFile configFile;
private final SearchUtils searchUtils;

public DeathEvent() {
configManager = new ConfigManager();
public DeathListener() {
configFile = new ConfigFile();
searchUtils = new SearchUtils();
}

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player killed = event.getEntity();
Player killer = event.getEntity().getKiller();
World world = event.getEntity().getWorld();
List<World> worldList = configManager.getDayNightPvpWorlds();
List<World> worldList = configFile.getDayNightPvpWorlds();

if (configManager.getPvpKeepInventoryWhenKilledByPlayer()) {
if (configFile.getPvpKeepInventoryWhenKilledByPlayer()) {
if (killer != null) {
if (SearchUtils.worldExistsInWorldList(worldList, world.getName())) {
if (searchUtils.worldExistsInWorldList(worldList, world.getName())) {
event.setKeepInventory(true);
event.getDrops().clear();
event.setKeepLevel(true);
Expand All @@ -40,7 +42,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
}

Bukkit.getScheduler().runTaskAsynchronously(DayNightPvP.getInstance(), () -> {
if (configManager.getVaultLoseMoneyOnDeathEnabled() && DayNightPvP.vaultIsPresent) {
if (configFile.getVaultLoseMoneyOnDeathEnabled() && DayNightPvP.vaultIsPresent) {
if (killer != null) {
for (PermissionAttachmentInfo permission : event.getEntity().getEffectivePermissions()) {
if (permission.getPermission().startsWith("dnp.losemoney")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.callvdois.daynightpvp.events;
package org.callvdois.daynightpvp.Listeners;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.callvdois.daynightpvp.DayNightPvP;
import org.callvdois.daynightpvp.service.UpdateChecker;
import org.callvdois.daynightpvp.services.UpdateServices;

public class JoinEvent implements Listener {
private final UpdateChecker updateChecker;
public class JoinListener implements Listener {
private final UpdateServices updateServices;

public JoinEvent() {
updateChecker = new UpdateChecker();
public JoinListener() {
updateServices = new UpdateServices();
}

@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (event.getPlayer().hasPermission("dnp.admin")) {
Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateChecker.checkUpdate(event), 100);
Bukkit.getServer().getScheduler().runTaskLater(DayNightPvP.getInstance(), () -> updateServices.checkUpdate(event), 100);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.callvdois.daynightpvp.Listeners;

import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.callvdois.daynightpvp.DayNightPvP;
import org.callvdois.daynightpvp.files.ConfigFile;

public class ListenersHandler {

private final ConfigFile configFile;

public ListenersHandler() {
configFile = new ConfigFile();
}

public void register() {
registerJoinListener();
registerEntityListener();
registerDeathListener();
}

public void unregisterAll() {
HandlerList.unregisterAll(DayNightPvP.getInstance());
}

private void registerJoinListener() {
if (configFile.getUpdateChecker()) {
Bukkit.getPluginManager().registerEvents(new JoinListener(), DayNightPvP.getInstance());
}
}

private void registerEntityListener() {
Bukkit.getPluginManager().registerEvents(new DamageListener(), DayNightPvP.getInstance());
}

private void registerDeathListener() {
boolean vaultLoseMoneyOnDeath = configFile.getVaultLoseMoneyOnDeathEnabled();
boolean keepInventoryWhenKilledByPlayer = configFile.getPvpKeepInventoryWhenKilledByPlayer();

if (vaultLoseMoneyOnDeath || keepInventoryWhenKilledByPlayer) {
Bukkit.getPluginManager().registerEvents(new DeathListener(), DayNightPvP.getInstance());
}
}

}
Loading

0 comments on commit d4f61da

Please sign in to comment.