Skip to content

Commit

Permalink
removed unused config code
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Mar 17, 2021
1 parent 5a7b38e commit 9249fe7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 81 deletions.
2 changes: 0 additions & 2 deletions src/main/java/eu/endermite/togglepvp/TogglePvp.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public void onEnable() {
}

public void reloadPluginConfig() {
saveDefaultConfig();
reloadConfig();
configCache = new ConfigCache();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package eu.endermite.togglepvp.listeners.player;

import eu.endermite.togglepvp.TogglePvp;
import eu.endermite.togglepvp.players.PlayerData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;

@eu.endermite.togglepvp.util.Listener
public class PlayerDeathListener implements Listener {

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerDeath(org.bukkit.event.entity.EntityDeathEvent event) {

if (!(event.getEntity() instanceof Player))
return;

Player player = (Player) event.getEntity();

PlayerData playerData = TogglePvp.getPlugin().getSmartCache().getPlayerData(player.getUniqueId());
playerData.setCombattime(0);
playerData.setLastCombatCheck(false);
playerData.setInCombat(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ public void onPlayerLeave(org.bukkit.event.player.PlayerQuitEvent event) {
return;

SmartCache smartCache = TogglePvp.getPlugin().getSmartCache();
long now = Instant.now().getEpochSecond();
long combatTime = smartCache.getPlayerData(player.getUniqueId()).getCombattime();
PlayerData playerData = smartCache.getPlayerData(player.getUniqueId());

if (combatTime <= now)
if (!playerData.isInCombat())
return;

player.setHealth(0);
if (TogglePvp.getPlugin().getConfigCache().isPunish_for_combat_logout_announce())
PluginMessages.broadcastMessage(player, TogglePvp.getPlugin().getConfigCache().getPunish_for_combat_logout_message());

PlayerData playerData = TogglePvp.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
playerData.setCombattime(now - 1);

}
}
47 changes: 25 additions & 22 deletions src/main/java/eu/endermite/togglepvp/players/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;

import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
Expand All @@ -26,30 +27,28 @@ public PlayerManager() {
playerList.put(p.getUniqueId(), playerData);
}

combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvp.getPlugin(), () -> {
playerList.forEach(((uuid, playerData) -> {
if (!CombatTimer.isInCombat(uuid)) {
if (playerData.getLastCombatCheck()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null)
combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvp.getPlugin(), () -> playerList.forEach(((uuid, playerData) -> {
if (!CombatTimer.isInCombat(uuid)) {
if (playerData.getLastCombatCheck()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null)
return;
PlayerLeaveCombatEvent playerLeaveCombatEvent = new PlayerLeaveCombatEvent(player);
Bukkit.getScheduler().runTask(TogglePvp.getPlugin(), () -> {
Bukkit.getPluginManager().callEvent(playerLeaveCombatEvent);
if (playerLeaveCombatEvent.isCancelled()) {
playerData.refreshCombatTime();
return;
PlayerLeaveCombatEvent playerLeaveCombatEvent = new PlayerLeaveCombatEvent(player);
Bukkit.getScheduler().runTask(TogglePvp.getPlugin(), () -> {
Bukkit.getPluginManager().callEvent(playerLeaveCombatEvent);
if (playerLeaveCombatEvent.isCancelled()) {
playerData.refreshCombatTime();
return;
}
playerData.setLastCombatCheck(false);
playerData.setInCombat(false);
PluginMessages.sendActionBar(uuid, TogglePvp.getPlugin().getConfigCache().getLeaving_combat());
});
}
} else {
playerData.setLastCombatCheck(true);
}
playerData.setLastCombatCheck(false);
playerData.setInCombat(false);
PluginMessages.sendActionBar(uuid, TogglePvp.getPlugin().getConfigCache().getLeaving_combat());
});
}
}));
}, 20, 20);
} else {
playerData.setLastCombatCheck(true);
}
})), 20, 20);

}

Expand All @@ -62,6 +61,10 @@ public void refreshPlayersCombatTime(UUID uuid) {
PlayerData data = playerList.get(uuid);
if (data == null)
return;
Player player = Bukkit.getPlayer(uuid);
if (player == null || player.isDead())
return;

data.refreshCombatTime();
data.setInCombat(true);
} catch (Exception ignored) {
Expand Down
52 changes: 0 additions & 52 deletions src/main/resources/config.yml

This file was deleted.

0 comments on commit 9249fe7

Please sign in to comment.