Compare commits
10 Commits
8d5c369877
...
dc93ba6e7e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc93ba6e7e | ||
|
|
67bd8ce8d0 | ||
|
|
68304098fb | ||
|
|
e83b811d34 | ||
|
|
13e01bff91 | ||
|
|
e8c728158d | ||
|
|
ae805966da | ||
|
|
92ab01bee1 | ||
|
|
d8a19c4b02 | ||
|
|
d96496d42e |
|
|
@ -8,6 +8,7 @@ import com.alttd.fishingevent.config.NPCLocationConfig;
|
|||
import com.alttd.fishingevent.fish_generator.FishGenerator;
|
||||
import com.alttd.fishingevent.gui.GUIListener;
|
||||
import com.alttd.fishingevent.listeners.CatchFish;
|
||||
import com.alttd.fishingevent.listeners.PlayerJoin;
|
||||
import com.alttd.fishingevent.npc.NPCManager;
|
||||
import com.alttd.fishingevent.objects.RarityManager;
|
||||
import com.alttd.fishingevent.points.LoadTask;
|
||||
|
|
@ -65,6 +66,7 @@ public final class FishingEvent extends JavaPlugin {
|
|||
private void registerEvents(@NotNull PluginManager pluginManager) {
|
||||
pluginManager.registerEvents(new CatchFish(this, logger, new FishGenerator(new RarityManager(Config.RARITY.RARITY_SET), logger), PointsManagement.getInstance()), this);
|
||||
pluginManager.registerEvents(new GUIListener(), this);
|
||||
pluginManager.registerEvents(new PlayerJoin(), this);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.alttd.fishingevent.commands;
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.End;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.Leaderboard;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.Points;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.Start;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.*;
|
||||
import com.alttd.fishingevent.config.Messages;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import org.bukkit.command.*;
|
||||
|
|
@ -34,7 +31,8 @@ public class FishCommand implements CommandExecutor, TabExecutor {
|
|||
new Points(),
|
||||
new Leaderboard(),
|
||||
new Start(),
|
||||
new End()
|
||||
new End(),
|
||||
new Time()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package com.alttd.fishingevent.commands.fish_subcommands;
|
||||
|
||||
import com.alttd.fishingevent.commands.SubCommand;
|
||||
import com.alttd.fishingevent.timer.EventManager;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
public class Time extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!EventManager.getInstance().isRunning()) {
|
||||
commandSender.sendMiniMessage("<red>The event is not running...</red>", null);
|
||||
return true;
|
||||
}
|
||||
Duration timeRemaining = EventManager.getInstance().getTimeRemaining();
|
||||
//TODO move message to config
|
||||
commandSender.sendMiniMessage("There is <gold><hour></gold> hour(s), <gold><minute></gold> minute(s), and <gold><second></gold> second(s) remaining.", TagResolver.resolver(
|
||||
Placeholder.parsed("hour", String.valueOf(timeRemaining.toHoursPart())),
|
||||
Placeholder.parsed("minute", String.valueOf(timeRemaining.toMinutesPart())),
|
||||
Placeholder.parsed("second", String.valueOf(timeRemaining.toSecondsPart()))
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "time";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return "<red>Invalid command use</red>";
|
||||
}
|
||||
}
|
||||
|
|
@ -275,19 +275,19 @@ public class Config extends AbstractConfig {
|
|||
|
||||
ArrayList<Prize> prizes = new ArrayList<>();
|
||||
for (String key : configurationSection.getKeys(false)) {
|
||||
String prefix = npcPrefix + "prizes." + key + ".";
|
||||
String stringMaterial = config.getString(prefix, "material", Material.STONE.name());
|
||||
String prizePrefix = npcPrefix + "prizes." + key + ".";
|
||||
String stringMaterial = config.getString(prizePrefix, "material", Material.STONE.name());
|
||||
Material material = Material.getMaterial(stringMaterial);
|
||||
if (material == null) {
|
||||
config.logger.warning("Invalid material [%] in prizes for NPC [%] at prize [%]", stringMaterial, npcKey, key);
|
||||
continue;
|
||||
}
|
||||
|
||||
int price = config.getInt(prefix, "price", 1);
|
||||
ItemStack itemStack = new ItemStack(material, config.getInt(prefix, "amount", 1));
|
||||
int price = config.getInt(prizePrefix, "price", 1);
|
||||
ItemStack itemStack = new ItemStack(material, config.getInt(prizePrefix, "amount", 1));
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(MiniMessage.miniMessage().deserialize(config.getString(prefix, "item-name", "<red>item name</red>")));
|
||||
itemMeta.lore(config.getStringList(npcPrefix, "item-lore", List.of("<green>item</green>", "<red>lore</red>")).stream()
|
||||
itemMeta.displayName(MiniMessage.miniMessage().deserialize(config.getString(prizePrefix, "item-name", "<red>item name</red>")));
|
||||
itemMeta.lore(config.getStringList(prizePrefix, "item-lore", List.of("<green>item</green>", "<red>lore</red>")).stream()
|
||||
.map(line -> MiniMessage.miniMessage().deserialize(line, Placeholder.parsed("price", String.valueOf(price))))
|
||||
.collect(Collectors.toList()));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
|
@ -295,9 +295,9 @@ public class Config extends AbstractConfig {
|
|||
prizes.add(
|
||||
new Prize(
|
||||
itemStack,
|
||||
config.getString(prefix, "command", "example command for <player>"),
|
||||
config.getString(prefix, "permission", "example.permission"),
|
||||
config.getString(prefix, "name", "Prize Name"),
|
||||
config.getString(prizePrefix, "command", "example command for <player>"),
|
||||
config.getString(prizePrefix, "permission", "example.permission"),
|
||||
config.getString(prizePrefix, "name", "Prize Name"),
|
||||
price)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.alttd.fishingevent.fish;
|
|||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.config.Fishes;
|
||||
import com.alttd.fishingevent.objects.Rarity;
|
||||
import com.alttd.fishingevent.timer.EventManager;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
@ -93,15 +94,26 @@ public class Fish {
|
|||
* @return a random length for this fish
|
||||
*/
|
||||
public float generateLength(int luckLevel) {
|
||||
float modifiedMaxLength = limitMaxLengthBasedOnTime();
|
||||
|
||||
float modifiedMinLength = minLength;
|
||||
if (luckLevel >= 1 && luckLevel <= 5) {
|
||||
float improvement = luckLevel * 0.1f * (maxLength - minLength);
|
||||
float availableSpace = maxLength - minLength - 1;
|
||||
float improvement = luckLevel * 0.1f * (modifiedMaxLength - minLength);
|
||||
float availableSpace = modifiedMaxLength - minLength - 1;
|
||||
|
||||
modifiedMinLength += Math.min(improvement, availableSpace);
|
||||
}
|
||||
|
||||
return new Random().nextFloat(modifiedMinLength, maxLength);
|
||||
return new Random().nextFloat(modifiedMinLength, modifiedMaxLength);
|
||||
}
|
||||
|
||||
private float limitMaxLengthBasedOnTime() {
|
||||
if (maxLength <= 6000)
|
||||
return maxLength;
|
||||
long secondsRemaining = EventManager.getInstance().getTimeRemaining().toSeconds();
|
||||
if ((maxLength - minLength) < 2000)
|
||||
return maxLength;
|
||||
return Math.max(minLength + 2000, maxLength - secondsRemaining);
|
||||
}
|
||||
|
||||
public net.kyori.adventure.text.@NotNull Component fishName() {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ public class FishGenerator {
|
|||
|
||||
public Optional<Fish> getFish(int luckLevel, FishType fishType) {
|
||||
int maxChanceRange = rarityManager.getMaxChanceRange(fishType);
|
||||
int rarityValue = CustomRandom.generateNumber(0, maxChanceRange, luckLevel + 1);
|
||||
int attempts = luckLevel < 3 ? 1 : (luckLevel < 5 ? 2 : 3); //starts at 1, then 2 at lvl 3 and 3 at lvl 5
|
||||
int rarityValue = CustomRandom.generateNumber(0, maxChanceRange, attempts);
|
||||
Optional<Rarity> optionalRarity = rarityManager.getRarityFromNumber(fishType, rarityValue);
|
||||
if (optionalRarity.isEmpty())
|
||||
return Optional.empty();
|
||||
|
|
|
|||
|
|
@ -110,7 +110,8 @@ public class CatchFish implements Listener {
|
|||
return;
|
||||
}
|
||||
handleFishCaught(event);
|
||||
} else if (event.getState().equals(PlayerFishEvent.State.IN_GROUND)) {
|
||||
} else if (event.getState().equals(PlayerFishEvent.State.IN_GROUND) || event.getState().equals(PlayerFishEvent.State.REEL_IN)) {
|
||||
stopLavaFishStart(uuid);
|
||||
handleLavaFishCaught(event);
|
||||
} else {
|
||||
stopLavaFishStart(uuid);
|
||||
|
|
@ -133,7 +134,7 @@ public class CatchFish implements Listener {
|
|||
}
|
||||
ItemStack fishingRod = optionalFishingROd.get();
|
||||
if (fishingRod.getItemMeta() instanceof Damageable damageable) {
|
||||
return damageable.getDamage() >= Material.FISHING_ROD.getMaxDurability();
|
||||
return damageable.getDamage() > Material.FISHING_ROD.getMaxDurability();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -161,11 +162,21 @@ public class CatchFish implements Listener {
|
|||
return;
|
||||
CaughtFishData caughtFishData = optionalFishData.get();
|
||||
player.getInventory().addItem(caughtFishData.fishItem()).values()
|
||||
.forEach(item -> player.getWorld().dropItem(player.getLocation(), item).setOwner(player.getUniqueId()));
|
||||
.forEach(item -> {
|
||||
Item dropItem = player.getWorld().dropItem(player.getLocation(), item);
|
||||
dropItem.setOwner(player.getUniqueId());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!dropItem.isDead())
|
||||
dropItem.remove();
|
||||
}
|
||||
}.runTaskLater(fishingEvent, 60 * 20);
|
||||
});
|
||||
player.updateInventory();
|
||||
player.getWorld().spawn(player.getLocation(), ExperienceOrb.class).setExperience(10);
|
||||
ScoreboardManager.getInstance().updateScoreboard(player, caughtFishData.length(), caughtFishData.fish());
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> <gold><length> cm</gold></green>", //TODO move to config
|
||||
TagResolver.resolver(
|
||||
Placeholder.component("rarity", caughtFishData.fish().getRarity().displayName()),
|
||||
Placeholder.component("name", caughtFishData.fish().fishName()),
|
||||
|
|
@ -174,6 +185,12 @@ public class CatchFish implements Listener {
|
|||
}
|
||||
|
||||
private void handleFishCaught(PlayerFishEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
LavaFishing lavaFishing = activeLavaFishers.get(uuid);
|
||||
if (lavaFishing != null) {
|
||||
lavaFishing.cancel();
|
||||
activeLavaFishers.remove(uuid);
|
||||
}
|
||||
Entity caught = event.getCaught();
|
||||
if (!(caught instanceof Item item)) {
|
||||
logger.warning("% did not catch an item", event.getPlayer().getName());
|
||||
|
|
@ -187,8 +204,15 @@ public class CatchFish implements Listener {
|
|||
CaughtFishData caughtFishData = optionalFishData.get();
|
||||
item.setItemStack(caughtFishData.fishItem());
|
||||
item.setOwner(player.getUniqueId());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!item.isDead())
|
||||
item.remove();
|
||||
}
|
||||
}.runTaskLater(fishingEvent, 60 * 20);
|
||||
ScoreboardManager.getInstance().updateScoreboard(player, caughtFishData.length(), caughtFishData.fish());
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> <gold><length> cm</gold></green>", //TODO move to config
|
||||
TagResolver.resolver(
|
||||
Placeholder.component("rarity", caughtFishData.fish().getRarity().displayName()),
|
||||
Placeholder.component("name", caughtFishData.fish().fishName()),
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class LavaFishing extends BukkitRunnable {
|
|||
private final int fireProtection;
|
||||
private final int unbreaking;
|
||||
private final int minWaitTime = 60;
|
||||
private final int maxWaitTime = 500;
|
||||
private final int maxWaitTime = 400;
|
||||
private boolean isBiting;
|
||||
private int timeUntilHookDamage;
|
||||
private boolean shouldDamageHook;
|
||||
|
|
@ -81,7 +81,7 @@ public class LavaFishing extends BukkitRunnable {
|
|||
}
|
||||
if (item.getItemMeta() instanceof Damageable damageable) {
|
||||
int damage = damageable.getDamage();
|
||||
damageable.setDamage(Math.min(++damage, Material.FISHING_ROD.getMaxDurability()));
|
||||
damageable.setDamage(Math.min(++damage, Material.FISHING_ROD.getMaxDurability() - 1));
|
||||
item.setItemMeta(damageable);
|
||||
} else {
|
||||
logger.warning("This item can't be damaged");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.alttd.fishingevent.listeners;
|
||||
|
||||
import com.alttd.fishingevent.scoreboard.ScoreboardManager;
|
||||
import com.alttd.fishingevent.timer.EventManager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (EventManager.getInstance().isRunning())
|
||||
ScoreboardManager.getInstance().showScoreboard(event.getPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -79,6 +79,11 @@ public class ScoreboardManager {
|
|||
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
|
||||
}
|
||||
|
||||
public void showScoreboard(Player player) {
|
||||
if (scoreboard != null)
|
||||
player.setScoreboard(scoreboard);
|
||||
}
|
||||
|
||||
private void resetScoreBoard() {
|
||||
playerScores.values().forEach(playerScore -> scoreboard.resetScores(playerScore.player()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,4 +80,10 @@ public class EventManager {
|
|||
)))));
|
||||
server.sendMessage(message.get());
|
||||
}
|
||||
|
||||
public Duration getTimeRemaining() {
|
||||
if (duration == null)
|
||||
return Duration.ofMillis(0);
|
||||
return duration.minus(Duration.between(startTime, Instant.now()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user