removed unused config code

This commit is contained in:
YouHaveTrouble
2021-03-18 00:55:34 +01:00
parent 5a7b38e62f
commit 9249fe754b
5 changed files with 54 additions and 81 deletions
@@ -64,8 +64,6 @@ public final class TogglePvp extends JavaPlugin {
} }
public void reloadPluginConfig() { public void reloadPluginConfig() {
saveDefaultConfig();
reloadConfig();
configCache = new ConfigCache(); configCache = new ConfigCache();
} }
@@ -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);
}
}
@@ -35,18 +35,15 @@ public class PlayerJoinAndLeaveListener implements Listener {
return; return;
SmartCache smartCache = TogglePvp.getPlugin().getSmartCache(); SmartCache smartCache = TogglePvp.getPlugin().getSmartCache();
long now = Instant.now().getEpochSecond(); PlayerData playerData = smartCache.getPlayerData(player.getUniqueId());
long combatTime = smartCache.getPlayerData(player.getUniqueId()).getCombattime();
if (combatTime <= now) if (!playerData.isInCombat())
return; return;
player.setHealth(0); player.setHealth(0);
if (TogglePvp.getPlugin().getConfigCache().isPunish_for_combat_logout_announce()) if (TogglePvp.getPlugin().getConfigCache().isPunish_for_combat_logout_announce())
PluginMessages.broadcastMessage(player, TogglePvp.getPlugin().getConfigCache().getPunish_for_combat_logout_message()); PluginMessages.broadcastMessage(player, TogglePvp.getPlugin().getConfigCache().getPunish_for_combat_logout_message());
PlayerData playerData = TogglePvp.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
playerData.setCombattime(now - 1);
} }
} }
@@ -9,6 +9,7 @@ import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
@@ -26,8 +27,7 @@ public class PlayerManager {
playerList.put(p.getUniqueId(), playerData); playerList.put(p.getUniqueId(), playerData);
} }
combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvp.getPlugin(), () -> { combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(TogglePvp.getPlugin(), () -> playerList.forEach(((uuid, playerData) -> {
playerList.forEach(((uuid, playerData) -> {
if (!CombatTimer.isInCombat(uuid)) { if (!CombatTimer.isInCombat(uuid)) {
if (playerData.getLastCombatCheck()) { if (playerData.getLastCombatCheck()) {
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
@@ -48,8 +48,7 @@ public class PlayerManager {
} else { } else {
playerData.setLastCombatCheck(true); playerData.setLastCombatCheck(true);
} }
})); })), 20, 20);
}, 20, 20);
} }
@@ -62,6 +61,10 @@ public class PlayerManager {
PlayerData data = playerList.get(uuid); PlayerData data = playerList.get(uuid);
if (data == null) if (data == null)
return; return;
Player player = Bukkit.getPlayer(uuid);
if (player == null || player.isDead())
return;
data.refreshCombatTime(); data.refreshCombatTime();
data.setInCombat(true); data.setInCombat(true);
} catch (Exception ignored) { } catch (Exception ignored) {
-52
View File
@@ -1,52 +0,0 @@
settings:
# Decides if pvp should be enabled or disabled by default
pvp_enabled_by_default: false
# Prevents dumping lava and pufferfish bucket, placing wither roses and lighting blocks on fire near players with pvp off
lava_and_fire_stopper:
enabled: true
radius: 2.5
# Disables channeling (trident enchant) lightning strike
# You may want to keep it disabled because players with pvp off can use it to attack players with pvp on
channeling_enchant_disabled: false
# Makes it so only pet owner can interact with it.
# Useful if you don't want people renaming other people's pets.
only_owner_can_interact_with_pet: false
# Time (in seconds) to keep player in combat
combat_time: 25
# Time (in seconds) that player can't be harmed by other player after logging in
login_protection_time: 0
# Time (in seconds) that player can't be harmed by other player after teleporting
teleport_protection_time: 0
# Kill the player if they log out during combat
punish_for_combat_logout:
enabled: true
announce: true
message: "&f%player% logged out while in combat. What a loser."
# Time (in seconds) to keep player data in memory when players goes offline.
# This is used for checking if offline players pvp state.
# Adjust only if you know what you're doing. NEVER set to less than 6.
cache_time: 30
messages:
pvp_enabled: "&cYou enabled PvP!"
pvp_disabled: "&cYou disabled PvP!"
cannot_attack_victim: "&cYou can't attack players that have PvP turned off!"
cannot_attack_attacker: "&cYou can't attack players while you have PvP turned off!"
cannot_attack_pets_victim: "&cYou can't attack pets of players that have PvP turned off"
cannot_attack_pets_attacker: "&cYou can't attack pets while you have PvP turned off"
no_permission: "&cYou don't have permission to use that."
no_such_command: "&cNo such command."
pvp_enabled_others: "&cYou've enabled %player%'s PvP."
pvp_disabled_others: "&cYou've disabled %player%'s PvP."
entering_combat: "&cEntering combat"
leaving_combat: "&cLeaving combat"
cant_do_that_during_combat: "&cYou can't do that while in combat!"