Skip to content

Commit

Permalink
respawn fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Apr 17, 2024
1 parent c2dd598 commit 90fc1d8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 99 deletions.
4 changes: 2 additions & 2 deletions src/me/stevemmmmm/thepitremake/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import me.stevemmmmm.thepitremake.game.WorldSelection;
import me.stevemmmmm.thepitremake.game.duels.DuelingManager;
import me.stevemmmmm.thepitremake.game.duels.GameUtility;
import me.stevemmmmm.thepitremake.game.killstreaks.Death;
import me.stevemmmmm.thepitremake.game.killstreaks.Killstreak;
import me.stevemmmmm.thepitremake.managers.enchants.LivesSystem;
import me.stevemmmmm.thepitremake.managers.enchants.BowManager;
import me.stevemmmmm.thepitremake.managers.enchants.CustomEnchant;
Expand Down Expand Up @@ -184,7 +184,7 @@ public void onPacketSending(PacketEvent event) {
getServer().getPluginManager().registerEvents(new ChatManagement(), this);
getServer().getPluginManager().registerEvents(new TogglePvPCommand(), this);
getServer().getPluginManager().registerEvents(new AntiFire(), this);
getServer().getPluginManager().registerEvents(new Death(), this);
getServer().getPluginManager().registerEvents(new Killstreak(), this);
getServer().getPluginManager().registerEvents(new LivesSystem(), this);
getServer().getPluginManager().registerEvents(new KillAnnouncementCommand(), this);

Expand Down
17 changes: 14 additions & 3 deletions src/me/stevemmmmm/thepitremake/game/duels/GameUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

package me.stevemmmmm.thepitremake.game.duels;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;

public class GameUtility implements Listener {
Expand All @@ -16,12 +18,21 @@ public GameUtility() {

@EventHandler
public void onJoin(PlayerJoinEvent event) {
event.getPlayer().setMaxHealth(24.0);
event.getPlayer().setFoodLevel(19);
Player player = event.getPlayer();

player.setMaxHealth(24.0);
player.setFoodLevel(19);
player.performCommand("setgold 10000000");

}

@EventHandler
public void onHunger(FoodLevelChangeEvent event) {
event.setCancelled(true);
}

@EventHandler
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
player.performCommand("setgold 10000000");
}
}
25 changes: 0 additions & 25 deletions src/me/stevemmmmm/thepitremake/game/killstreaks/Death.java

This file was deleted.

82 changes: 36 additions & 46 deletions src/me/stevemmmmm/thepitremake/game/killstreaks/Killstreak.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,51 @@
package me.stevemmmmm.thepitremake.game.killstreaks;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class Killstreak {
private static Killstreak instance;
private final Map<UUID, Integer> killStreakMap = new HashMap<>();
public class Killstreak implements Listener {

private Map<UUID, Integer> killCounts;

// static initialization block
static {
instance = new Killstreak();
public Killstreak() {
this.killCounts = new HashMap<>();
}

// private constructor to prevent external instantiation
private Killstreak() {}
public void incrementKillCount(Player player) {
UUID playerId = player.getUniqueId();
int currentKills = killCounts.getOrDefault(playerId, 0);
killCounts.put(playerId, currentKills + 1);

/**
* Returns the instance of this class
* @return the singleton instance of Killstreak
*/
public static Killstreak getInstance() {
return instance;
}
/**
* Get kills from hashmap with key 'UUID'
* @param uuid
* @return
*/

public int getKills(final UUID uuid){
if(!killStreakMap.containsKey(uuid)) return 0;
return killStreakMap.get(uuid);
checkStreak(player);
}

/**
* Add kill into hashmap with key 'uuid'
* @param uuid
*/

public void addKill(final UUID uuid) {
if (killStreakMap.containsKey(uuid)) {
killStreakMap.put(uuid, getKills(uuid) + 1);
} else {
killStreakMap.put(uuid, 1);

private void checkStreak(Player player) {
UUID playerId = player.getUniqueId();
int currentKills = killCounts.getOrDefault(playerId, 0);

if (currentKills % 5 == 0) {
String message = ChatColor.translateAlternateColorCodes('&',
"&c&lSTREAK! &r&7of &c" + currentKills + "&r&7 kills by " + player.getName());

Bukkit.broadcastMessage(message);
}
}
/**
* Reset kills under key 'UUID'
* @param uuid
*/
public void resetKills(final UUID uuid){
if(!killStreakMap.containsKey(uuid)) return;
killStreakMap.remove(uuid);

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
UUID playerId = player.getUniqueId();

if (killCounts.containsKey(playerId)) {
killCounts.remove(playerId);
}
}


}
50 changes: 27 additions & 23 deletions src/me/stevemmmmm/thepitremake/world/AutoRespawn.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package me.stevemmmmm.thepitremake.world;

import java.util.Iterator;
import me.stevemmmmm.thepitremake.core.Main;
import me.stevemmmmm.thepitremake.game.RegionManager;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -13,40 +20,37 @@
import org.bukkit.util.Vector;

public class AutoRespawn implements Listener {
public AutoRespawn() {
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
}

@EventHandler
public void onDeath(PlayerDeathEvent event) {
event.setDeathMessage("");

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

public static void triggerRespawnSequence(Player player) {
Bukkit.getScheduler().runTaskLater(Main.INSTANCE, () -> {
player.spigot().respawn();
resetPlayerState(player);
}, 1L);
}

public static void resetPlayerState(Player player) {
player.setHealth(player.getMaxHealth());
player.teleport(RegionManager.getInstance().getSpawnLocation(player));
player.setFoodLevel(19);
player.setFireTicks(0);
player.setVelocity(new Vector(0, 0, 0));

for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}

player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.INSTANCE, () -> {
Iterator var1 = player.getActivePotionEffects().iterator();

while(var1.hasNext()) {
PotionEffect effect = (PotionEffect)var1.next();
player.removePotionEffect(effect.getType());
}

player.setFoodLevel(19);
player.setHealth(player.getMaxHealth());
((CraftPlayer)player).getHandle().setAbsorptionHearts(0.0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
player.setVelocity(new Vector(0, 0, 0));
player.setFireTicks(0);
}, 1L);
}

}
}

0 comments on commit 90fc1d8

Please sign in to comment.