Skip to content

Commit

Permalink
Merge pull request #1 from Sfiguz7/master
Browse files Browse the repository at this point in the history
合并上游
  • Loading branch information
haiman233 committed Mar 17, 2022
2 parents 22f5456 + cfc9836 commit ae7bd81
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else if (args[0].equalsIgnoreCase("walkthrough")) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "TranscEndence > " + ChatColor.GRAY +
"https://github.com/Sfiguz7/TranscEndence/wiki/Walkthrough-guide-thingy");
} else if (args[0].equalsIgnoreCase("list")) {
Set<UUID> uuids =
TranscEndence.getRegistry().getDaxiEffectPlayers().keySet();
StringBuilder list = new StringBuilder().append(ChatColor.LIGHT_PURPLE);
if (uuids.isEmpty()) {
list.append("There are no players with Daxis!");
} else {
for (UUID uuid : uuids) {
list.append(Bukkit.getOfflinePlayer(uuid).getName()).append(' ');
}
}
sender.sendMessage(list.toString());
} else {
sendHelp(sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand All @@ -31,7 +32,8 @@
public class Daxi extends SlimefunItem {

private final Daxi.Type type;
TranscEndence instance = TranscEndence.getInstance();
private static final TranscEndence INSTANCE = TranscEndence.getInstance();
private static final FileConfiguration CONFIG = INSTANCE.getConfig();

public Daxi(Type type) {
super(TEItems.transcendence, type.slimefunItem, TERecipeType.NANOBOT_CRAFTER, type.recipe);
Expand Down Expand Up @@ -59,7 +61,7 @@ private void onItemRightClick(PlayerRightClickEvent event) {
Set<Daxi.Type> effects = activePlayers.get(uuid);
if (effects.contains(type)) {
p.sendMessage(ChatColor.LIGHT_PURPLE +
TranscEndence.getInstance().getConfig().getString("options.already-have-daxi-effect"));
CONFIG.getString("options.already-have-daxi-effect"));
return;
} else {
effects.add(type);
Expand All @@ -68,7 +70,7 @@ private void onItemRightClick(PlayerRightClickEvent event) {
startAnimation(p);
applyEffect(p, type);
p.sendMessage(ChatColor.LIGHT_PURPLE +
TranscEndence.getInstance().getConfig().getString("options.daxi-message-intro") + "\n" + type.message);
CONFIG.getString("options.daxi-message-intro") + "\n" + type.message);
event.cancel();
if (event.getHand() == EquipmentSlot.HAND) {
event.getPlayer().getInventory().setItemInMainHand(null);
Expand Down Expand Up @@ -112,12 +114,12 @@ private void startAnimation(Player p) {
}

for (int i = 0; i < lasttick; i++) {
instance.getServer().getScheduler().runTaskLater(instance, () -> moveArmorStands(armorstands, armorstandslocations), i);
INSTANCE.getServer().getScheduler().runTaskLater(INSTANCE, () -> moveArmorStands(armorstands, armorstandslocations), i);
}

ThreadLocalRandom random = ThreadLocalRandom.current();

instance.getServer().getScheduler().runTaskLater(instance, () -> {
INSTANCE.getServer().getScheduler().runTaskLater(INSTANCE, () -> {
for (ArmorStand as : armorstands) {
//Clearing from registry as they won't exist anymore
TranscEndence.getRegistry().getDaxiArmorStands().remove(as);
Expand Down Expand Up @@ -155,7 +157,7 @@ private void moveArmorStands(ArmorStand[] as, Vector[] asv) {
}

public static void applyEffect(Player p, Type type) {
p.addPotionEffect(new PotionEffect(type.effect, Integer.MAX_VALUE, type.amplifier));
p.addPotionEffect(new PotionEffect(type.effect, Integer.MAX_VALUE, type.level));
}

public static void reapplyEffects(Player p) {
Expand All @@ -175,48 +177,48 @@ public enum Type {
new ItemStack[] {TEItems.ZOT_UP, TEItems.ZOT_UP, TEItems.ZOT_UP, TEItems.ZOT_UP},
new Color[] {Color.RED, Color.RED, Color.FUCHSIA, Color.FUCHSIA},
PotionEffectType.INCREASE_DAMAGE,
3,
TranscEndence.getInstance().getConfig().getString("options.daxi-message-strength")
CONFIG.getInt("daxi-effects.strength-level"),
CONFIG.getString("options.daxi-message-strength")
),
ABSORPTION(TEItems.DAXI_ABSORPTION,
new ItemStack[] {TEItems.ZOT_DOWN_2, TEItems.ZOT_DOWN_2, TEItems.ZOT_DOWN_2, TEItems.ZOT_DOWN_2},
new ItemStack[] {TEItems.ZOT_DOWN, TEItems.ZOT_DOWN, TEItems.ZOT_DOWN, TEItems.ZOT_DOWN},
new Color[] {Color.YELLOW, Color.YELLOW, Color.ORANGE, Color.ORANGE},
PotionEffectType.ABSORPTION,
5,
TranscEndence.getInstance().getConfig().getString("options.daxi-message-absorption")
CONFIG.getInt("daxi-effects.absorption-level"),
CONFIG.getString("options.daxi-message-absorption")
),
FORTITUDE(TEItems.DAXI_FORTITUDE,
new ItemStack[] {TEItems.ZOT_LEFT_2, TEItems.ZOT_LEFT_2, TEItems.ZOT_LEFT_2, TEItems.ZOT_LEFT_2},
new ItemStack[] {TEItems.ZOT_LEFT, TEItems.ZOT_LEFT, TEItems.ZOT_LEFT, TEItems.ZOT_LEFT},
new Color[] {Color.LIME, Color.LIME, Color.GREEN, Color.GREEN},
PotionEffectType.DAMAGE_RESISTANCE,
4,
TranscEndence.getInstance().getConfig().getString("options.daxi-message-fortitude")
CONFIG.getInt("daxi-effects.fortitude-level"),
CONFIG.getString("options.daxi-message-fortitude")
),
SATURATION(TEItems.DAXI_SATURATION,
new ItemStack[] {TEItems.ZOT_RIGHT_2, TEItems.ZOT_RIGHT_2, TEItems.ZOT_RIGHT_2, TEItems.ZOT_RIGHT_2},
new ItemStack[] {TEItems.ZOT_RIGHT, TEItems.ZOT_RIGHT, TEItems.ZOT_RIGHT, TEItems.ZOT_RIGHT},
new Color[] {Color.AQUA, Color.AQUA, Color.TEAL, Color.TEAL},
PotionEffectType.SATURATION,
1,
TranscEndence.getInstance().getConfig().getString("options.daxi-message-saturation")
CONFIG.getInt("daxi-effects.saturation-level"),
CONFIG.getString("options.daxi-message-saturation")
),
REGENERATION(TEItems.DAXI_REGENERATION,
new ItemStack[] {TEItems.ZOT_UP_2, TEItems.ZOT_LEFT_2, TEItems.ZOT_RIGHT_2, TEItems.ZOT_DOWN_2},
new ItemStack[] {TEItems.ZOT_UP, TEItems.ZOT_LEFT, TEItems.ZOT_RIGHT, TEItems.ZOT_DOWN},
new Color[] {Color.RED, Color.YELLOW, Color.LIME, Color.AQUA},
PotionEffectType.REGENERATION,
2,
TranscEndence.getInstance().getConfig().getString("options.daxi-message-regeneration")
CONFIG.getInt("daxi-effects.regeneration-level"),
CONFIG.getString("options.daxi-message-regeneration")
);

private final SlimefunItemStack slimefunItem;
private final ItemStack[] zotsAnimation;
private final Color[] colors;
private final ItemStack[] recipe;
private final PotionEffectType effect;
private final int amplifier;
private final int level;
private final String message;

Type(SlimefunItemStack itemStack, ItemStack[] zots, ItemStack[] zotsAnimation, Color[] colors,
Expand All @@ -229,12 +231,12 @@ public enum Type {
zots[1], TEItems.STABLE_INGOT, zots[2],
TEItems.STABLE_BLOCK, zots[3], TEItems.STABLE_BLOCK};
this.effect = effect;
this.amplifier = level - 1;
this.level = level - 1;
this.message = message;
}

public int getTypeEffectAmplifier() {
return this.amplifier;
public int getTypeEffectLevel() {
return this.level;
}

public static final Daxi.Type[] values = values();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.sfiguz7.transcendence.implementation.listeners;

import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import me.sfiguz7.transcendence.TranscEndence;
import me.sfiguz7.transcendence.implementation.items.items.Daxi;
import me.sfiguz7.transcendence.lists.TEItems;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -18,13 +20,24 @@

public class DaxiDeathListener implements Listener {

public static final NamespacedKey TINKER_PROTECTION = new NamespacedKey(TranscEndence.getInstance(), "tinker");

public DaxiDeathListener(JavaPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@EventHandler(priority = LOWEST, ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent e) {
Player p = e.getEntity();

/*
* Tinker adds a PDC long to players if they have a full set of Daxi gear. This long is 5 seconds
* worth of Daxi-loss-on-death protection.
*/
if (PersistentDataAPI.getLong(p, TINKER_PROTECTION) >= System.currentTimeMillis()) {
return;
}

UUID uuid = p.getUniqueId();
Map<UUID, Set<Daxi.Type>> activePlayers = TranscEndence.getRegistry().getDaxiEffectPlayers();
if (activePlayers.get(uuid) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onEffectModificationEvent(EntityPotionEffectEvent e) {
if (newEffect != null) {
final Daxi.Type daxiType = getEffectDaxiType(e.getModifiedType());
if (daxiType != null
&& newEffect.getAmplifier() != daxiType.getTypeEffectAmplifier()) {
&& newEffect.getAmplifier() != daxiType.getTypeEffectLevel()) {
final Player p = (Player) e.getEntity();
if (TranscEndence.getRegistry().getToggledPlayers().contains(p.getUniqueId())) {
return;
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ options:
droppable-unstable-ingots: true
unstable-ingots-message-undroppable: "Unstable Ingots are undroppable!"

daxi-effects:
strength-level: 3
absorption-level: 5
fortitude-level: 4
saturation-level: 1
regeneration-level: 2

guide:
recieve-on-first-join: true

0 comments on commit ae7bd81

Please sign in to comment.