9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-31 04:46:36 +00:00
This commit is contained in:
XiaoMoMi
2024-08-30 23:42:49 +08:00
parent 6f54585538
commit b149e08ba1
17 changed files with 541 additions and 262 deletions

View File

@@ -33,6 +33,7 @@ import net.momirealms.customfishing.api.mechanic.item.ItemManager;
import net.momirealms.customfishing.api.mechanic.loot.LootManager;
import net.momirealms.customfishing.api.mechanic.market.MarketManager;
import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager;
import net.momirealms.customfishing.api.mechanic.misc.hologram.HologramManager;
import net.momirealms.customfishing.api.mechanic.misc.placeholder.PlaceholderManager;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager;
@@ -84,6 +85,7 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin {
protected TotemManager totemManager;
protected FishingManager fishingManager;
protected GameManager gameManager;
protected HologramManager hologramManager;
/**
* Constructs a new BukkitCustomFishingPlugin instance.
@@ -358,6 +360,15 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin {
return translationManager;
}
/**
* Retrieves the HologramManager.
*
* @return the {@link HologramManager}
*/
public HologramManager getHologramManager() {
return hologramManager;
}
/**
* Logs a debug message.
*

View File

@@ -35,11 +35,11 @@ public interface ActionManager<T> extends Reloadable {
/**
* Registers a custom action type with its corresponding factory.
*
* @param type The type identifier of the action.
* @param actionFactory The factory responsible for creating instances of the action.
* @param actionFactory The factory responsible for creating instances of the action.
* @param type The type identifier of the action.
* @return True if registration was successful, false if the type is already registered.
*/
boolean registerAction(String type, ActionFactory<T> actionFactory);
boolean registerAction(ActionFactory<T> actionFactory, String... type);
/**
* Unregisters a custom action type.

View File

@@ -31,5 +31,6 @@ public enum ActionTrigger {
TIMER,
INTERACT,
REEL,
NEW_SIZE_RECORD
NEW_SIZE_RECORD,
END
}

View File

@@ -207,6 +207,7 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
* Ends the game for the gaming player.
*/
protected void endGame() {
if (!isValid()) return;
destroy();
boolean success = isSuccessful();
BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> {

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.misc.hologram;
import net.momirealms.sparrow.heart.feature.entity.FakeNamedEntity;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
public class Hologram {
private final FakeNamedEntity entity;
private Set<Player> set1 = new HashSet<>();
private int ticksRemaining = 0;
public Hologram(FakeNamedEntity entity) {
this.entity = entity;
}
public void name(String json) {
entity.name(json);
}
public void destroy() {
for (Player player : set1) {
entity.destroy(player);
}
set1.clear();
}
public void setTicksRemaining(int ticks) {
ticksRemaining = ticks;
}
public boolean reduceTicks() {
ticksRemaining--;
return ticksRemaining < 0;
}
public void updateNearbyPlayers(Set<Player> set2) {
Set<Player> intersectionSet = new HashSet<>(set1);
intersectionSet.retainAll(set2);
Set<Player> uniqueToSet1 = new HashSet<>(set1);
uniqueToSet1.removeAll(set2);
Set<Player> uniqueToSet2 = new HashSet<>(set2);
uniqueToSet2.removeAll(set1);
for (Player p : uniqueToSet1) {
entity.destroy(p);
}
for (Player p : uniqueToSet2) {
entity.spawn(p);
}
for (Player p : intersectionSet) {
entity.updateMetaData(p);
}
set1 = set2;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.misc.hologram;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.common.helper.VersionHelper;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask;
import net.momirealms.sparrow.heart.SparrowHeart;
import net.momirealms.sparrow.heart.feature.entity.FakeNamedEntity;
import net.momirealms.sparrow.heart.feature.entity.armorstand.FakeArmorStand;
import net.momirealms.sparrow.heart.feature.entity.display.FakeTextDisplay;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class HologramManager implements Reloadable {
private final BukkitCustomFishingPlugin plugin;
private final ConcurrentHashMap<Location, Hologram> holograms = new ConcurrentHashMap<>();
private SchedulerTask task;
public HologramManager(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
@Override
public void load() {
this.task = plugin.getScheduler().sync().runRepeating(() -> {
ArrayList<Location> toRemove = new ArrayList<>();
for (Map.Entry<Location, Hologram> entry : holograms.entrySet()) {
if (entry.getValue().reduceTicks()) {
toRemove.add(entry.getKey());
entry.getValue().destroy();
}
}
for (Location location : toRemove) {
holograms.remove(location);
}
}, 1,1, null);
}
@Override
public void unload() {
if (this.task != null) {
this.task.cancel();
}
for (Hologram hologram : holograms.values()) {
hologram.destroy();
}
holograms.clear();
}
public void createHologram(Location location, String json, int ticks, boolean displayEntity, int[] rgba, Set<Player> viewers) {
Hologram hologram = holograms.get(location);
if (hologram == null) {
FakeNamedEntity fakeNamedEntity;
if (displayEntity && VersionHelper.isVersionNewerThan1_19_4()) {
FakeTextDisplay textDisplay = SparrowHeart.getInstance().createFakeTextDisplay(location);
textDisplay.rgba(rgba[0], rgba[1], rgba[2], rgba[3]);
fakeNamedEntity = textDisplay;
} else {
FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location);
armorStand.small(true);
armorStand.invisible(true);
fakeNamedEntity = armorStand;
}
hologram = new Hologram(fakeNamedEntity);
hologram.name(json);
hologram.updateNearbyPlayers(viewers);
hologram.setTicksRemaining(ticks);
holograms.put(location, hologram);
} else {
hologram.name(json);
hologram.updateNearbyPlayers(viewers);
hologram.setTicksRemaining(ticks);
}
}
}

View File

@@ -35,11 +35,11 @@ public interface RequirementManager<T> extends Reloadable {
/**
* Registers a custom requirement type with its corresponding factory.
*
* @param type The type identifier of the requirement.
* @param requirementFactory The factory responsible for creating instances of the requirement.
* @param type The type identifier of the requirement.
* @return True if registration was successful, false if the type is already registered.
*/
boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory<T> requirementFactory);
boolean registerRequirement(@NotNull RequirementFactory<T> requirementFactory, @NotNull String... type);
/**
* Unregisters a custom requirement type.