#Subtract and Addtime pdc instance
1 messages · Page 1 of 1 (latest)
wdym
public void PlayerDeathEvent(PlayerDeathEvent event) {
Player p = event.getEntity();
subtractTime(p, 1);
p.sendMessage(DIALOG+ ChatColor.DARK_RED +"You Died... this means you have lost one hour of your life!");
Entity n = event.getEntity().getKiller();
if (n instanceof Player){
Player np = (Player) n;
addTime(np,1);
p.sendMessage(DIALOG+ChatColor.GREEN + "You killed someone, you get 1 Hour!");
}
}
I see the m,essage here
It tells me You Died but it dosent - time
show your getTime
the command?
method
why is your key showing red?
thats an error, red = warning
hover over it and it shows no warning?
I'm expecting a static warning
ok
not an error my g
I see no reason for it to not be working. It looks fine
I can't check it here at the moment. slightly busy
@chrome stone remind me when your back
make sure .minus affects the variable
you may have to do expires = expires.minus(hours, ChronoUnit.HOURS);
I was thinking that I should probs try it tho
I just check it returns a copy, so yes you have to reassign it
you'll have to update teh add method too
ohh rlyyy
makes sense
wannna test it w/ me or nah
/**
* Add time to a Players Death Clock.
*
* @param player the Player to add time to.
* @param hours the hours to remove.
*/
public static void addTime(Player player, long hours) {
PersistentDataContainer pdc = player.getPersistentDataContainer();
Instant expires = Instant.ofEpochMilli(pdc.getOrDefault(key, PersistentDataType.LONG, Instant.now().toEpochMilli()));
expires = expires.plus(hours, ChronoUnit.HOURS);
pdc.set(key, PersistentDataType.LONG, expires.toEpochMilli());
}
/**
* Subtract time from a Players Deathclock.
*
* @param player the Player to remove time from.
* @param hours the number of hours to remove.
*/
public static void subtractTime(Player player, long hours) {
PersistentDataContainer pdc = player.getPersistentDataContainer();
Instant expires = Instant.ofEpochMilli(pdc.getOrDefault(key, PersistentDataType.LONG, Instant.now().toEpochMilli()));
expires = expires.minus(hours, ChronoUnit.HOURS);
pdc.set(key, PersistentDataType.LONG, expires.toEpochMilli());
}```