Fixed and nerfed speed talisman/ring/relic

This commit is contained in:
Auxilor
2021-01-07 17:46:47 +00:00
parent f07d0cd73b
commit f60f69fe7c
9 changed files with 84 additions and 56 deletions

View File

@@ -20,6 +20,7 @@ import com.willfp.talismans.talismans.util.BlockPlaceListener;
import com.willfp.talismans.talismans.util.TalismanChecks;
import com.willfp.talismans.talismans.util.TalismanCraftListener;
import com.willfp.talismans.talismans.util.WatcherTriggers;
import com.willfp.talismans.talismans.util.equipevent.SyncTalismanEquipEventTask;
import com.willfp.talismans.talismans.util.equipevent.TalismanEquipEventListeners;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@@ -29,13 +30,6 @@ import java.util.List;
@SuppressWarnings("unused")
public class TalismansPlugin extends AbstractEcoPlugin {
/**
* Listeners to call {@link com.willfp.talismans.talismans.util.equipevent.TalismanEquipEvent}.
* <p>
* Instance stored to reschedule timer.
*/
private final TalismanEquipEventListeners talismanEquipEventListeners = new TalismanEquipEventListeners(this);
/**
* Internal constructor called by bukkit on plugin load.
*/
@@ -94,8 +88,7 @@ public class TalismansPlugin extends AbstractEcoPlugin {
}
}, 1);
});
talismanEquipEventListeners.scheduleAutocheck();
SyncTalismanEquipEventTask.scheduleAutocheck(this);
}
/**
@@ -158,7 +151,7 @@ public class TalismansPlugin extends AbstractEcoPlugin {
new WatcherTriggers(this),
new BlockPlaceListener(),
new TalismanCraftListener(),
talismanEquipEventListeners
new TalismanEquipEventListeners(this)
);
}

View File

@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class SpeedRelic extends Talisman {
private static final UUID MODIFIER_UUID = UUID.randomUUID();
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed_relic".getBytes());
private static AttributeModifier MODIFIER = new AttributeModifier(MODIFIER_UUID, "speed_relic", 0.05, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
public SpeedRelic() {

View File

@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class SpeedRing extends Talisman {
private static final UUID MODIFIER_UUID = UUID.randomUUID();
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed_ring".getBytes());
private static AttributeModifier MODIFIER = new AttributeModifier(MODIFIER_UUID, "speed_ring", 0.05, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
public SpeedRing() {

View File

@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class SpeedTalisman extends Talisman {
private static final UUID MODIFIER_UUID = UUID.randomUUID();
private static final UUID MODIFIER_UUID = UUID.nameUUIDFromBytes("speed_talisman".getBytes());
private static AttributeModifier MODIFIER = new AttributeModifier(MODIFIER_UUID, "speed_talisman", 0.05, AttributeModifier.Operation.MULTIPLY_SCALAR_1);
public SpeedTalisman() {

View File

@@ -0,0 +1,63 @@
package com.willfp.talismans.talismans.util.equipevent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.talismans.talismans.Talisman;
import com.willfp.talismans.talismans.util.TalismanChecks;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class SyncTalismanEquipEventTask {
/**
* Cache for the scheduler.
*/
private static final Map<UUID, Set<Talisman>> syncCache = Collections.synchronizedMap(new HashMap<>());
/**
* Schedule sync repeating updater task.
*
* @param plugin The plugin to schedule for.
*/
public static void scheduleAutocheck(@NotNull final AbstractEcoPlugin plugin) {
plugin.getScheduler().syncRepeating(() -> {
for (Player player : plugin.getServer().getOnlinePlayers()) {
UUID uuid = player.getUniqueId();
Set<Talisman> buildingBefore = syncCache.get(uuid);
if (buildingBefore == null) {
buildingBefore = new HashSet<>();
}
Set<Talisman> before = buildingBefore;
Set<Talisman> after = TalismanChecks.getTalismansOnPlayer(player);
for (Talisman talisman : new HashSet<>(before)) {
if (after.contains(talisman)) {
before.remove(talisman);
after.remove(talisman);
}
}
syncCache.put(uuid, after);
after.removeAll(before);
for (Talisman talisman : after) {
Bukkit.getPluginManager().callEvent(new TalismanEquipEvent(player, talisman, EquipType.EQUIP));
}
before.removeAll(after);
for (Talisman talisman : before) {
Bukkit.getPluginManager().callEvent(new TalismanEquipEvent(player, talisman, EquipType.UNEQUIP));
}
}
}, 80, 80);
}
}

View File

@@ -18,16 +18,10 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class TalismanEquipEventListeners extends PluginDependent implements Listener {
private final Map<UUID, Set<Talisman>> syncCache = Collections.synchronizedMap(new HashMap<>());
/**
* Initialize new listeners and link them to a plugin.
*
@@ -117,9 +111,17 @@ public class TalismanEquipEventListeners extends PluginDependent implements List
Set<Talisman> inCache = TalismanChecks.getTalismansOnPlayer(player, false, extra);
this.getPlugin().getScheduler().runLater(() -> {
Set<Talisman> newSet = TalismanChecks.getTalismansOnPlayer(player, false, extra);
Set<Talisman> newSet = TalismanChecks.getTalismansOnPlayer(player, false);
for (Talisman talisman : new HashSet<>(newSet)) {
if (inCache.contains(talisman)) {
newSet.remove(talisman);
inCache.remove(talisman);
}
}
newSet.removeAll(inCache);
for (Talisman talisman : newSet) {
Bukkit.getPluginManager().callEvent(new TalismanEquipEvent(player, talisman, EquipType.EQUIP));
}
@@ -130,34 +132,4 @@ public class TalismanEquipEventListeners extends PluginDependent implements List
}
}, 1);
}
/**
* Schedule sync repeating updater task.
*/
public void scheduleAutocheck() {
this.getPlugin().getScheduler().syncRepeating(() -> {
for (Player player : this.getPlugin().getServer().getOnlinePlayers()) {
UUID uuid = player.getUniqueId();
Set<Talisman> before = syncCache.get(uuid);
if (before == null) {
before = new HashSet<>();
}
Set<Talisman> after = TalismanChecks.getTalismansOnPlayer(player);
syncCache.put(uuid, after);
after.removeAll(before);
for (Talisman talisman : after) {
Bukkit.getPluginManager().callEvent(new TalismanEquipEvent(player, talisman, EquipType.EQUIP));
}
before.removeAll(after);
for (Talisman talisman : before) {
Bukkit.getPluginManager().callEvent(new TalismanEquipEvent(player, talisman, EquipType.UNEQUIP));
}
}
}, 80, 80);
}
}

View File

@@ -1,5 +1,5 @@
name: "Speed Relic"
description: Move 40% faster.
description: Move 25% faster.
enabled: true
obtaining:
@@ -24,4 +24,4 @@ general-config:
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDRiYTRhYjRmOTNiODJlNjE0MTI4OTgwMWMzOWUwYmMyNzBjYmU1MTc5ZGY3NmU4NWI1NDMwNmMyNzhjMTdkYSJ9fX0=
config:
percentage-bonus: 40
percentage-bonus: 25

View File

@@ -1,5 +1,5 @@
name: "Speed Ring"
description: Move 25% faster.
description: Move 10 faster.
enabled: true
obtaining:
@@ -24,4 +24,4 @@ general-config:
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTNjZTc2NjAyZDNmZWM3YzAyNzNkYTYwMDA5MDA3YmU0MTQwYWM5ZmFjMDM0MTQ1MGMwNzU3ZTUzZDc1MTU3NyJ9fX0=
config:
percentage-bonus: 25
percentage-bonus: 10

View File

@@ -1,5 +1,5 @@
name: "Speed Talisman"
description: Move 10% faster.
description: Move 5% faster.
enabled: true
obtaining:
@@ -24,4 +24,4 @@ general-config:
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODYyNGJhY2I1ZjE5ODZlNjQ3N2FiY2U0YWU3ZGNhMTgyMGE1MjYwYjYyMzNiNTViYTFkOWJhOTM2Yzg0YiJ9fX0=
config:
percentage-bonus: 10
percentage-bonus: 5