Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Sign rework api (part 1 of 2 for sign rework PR) #706

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a8a44db
sign rework - add API classes
DerToaster98 Aug 31, 2024
766cb8c
utility method to get Rotation by action
DerToaster98 Aug 31, 2024
2074d9d
necessary changes to SignTranslateEvent => use components (basically...)
DerToaster98 Aug 31, 2024
e4292f1
signListener implementations
DerToaster98 Aug 31, 2024
301b0bf
add instance for sign listener
DerToaster98 Aug 31, 2024
ff84ee8
add base signs (most basic signs that exist)
DerToaster98 Aug 31, 2024
7107633
forgot action import
DerToaster98 Aug 31, 2024
df4d4ef
fix getSignWrappers() method for sign => NPE
DerToaster98 Sep 5, 2024
f9e1ff6
corrections to BlockFace access
DerToaster98 Sep 5, 2024
b6bbdab
more fixes regarding getting the blockface of a sign...
DerToaster98 Sep 5, 2024
674c132
NPE prevention
DerToaster98 Sep 5, 2024
cb19e75
add TODO note
DerToaster98 Sep 5, 2024
bf4c7c9
remove spaces from suffix
DerToaster98 Sep 5, 2024
8422b22
Startup correction cherry picked
DerToaster98 Sep 5, 2024
221d0f2
correction => if the ident has trailing : => don't add them yourself …
DerToaster98 Sep 5, 2024
1e60c83
startup correction
DerToaster98 Sep 5, 2024
719a1ec
forgot the space
DerToaster98 Sep 5, 2024
956c8c5
crafttype is specified in second, not the third line
DerToaster98 Sep 5, 2024
8e1e7c7
typo
DerToaster98 Sep 5, 2024
4eda66f
fix information signs not updating
DerToaster98 Sep 6, 2024
d9afa5f
comment out debug logs
DerToaster98 Sep 6, 2024
19e2171
call update on the state, not on the block...
DerToaster98 Sep 6, 2024
6d8b47a
more elegant solution
DerToaster98 Sep 6, 2024
94ccf3c
add eventtype enum (to api classes)
DerToaster98 Sep 6, 2024
0a7fd09
refactor for eventtype enum (implementations (simple))
DerToaster98 Sep 6, 2024
a611a4f
supply eventType and use nullable for sign get access
DerToaster98 Sep 10, 2024
be724f9
just call it override
DerToaster98 Sep 10, 2024
8c0e50e
add registry base class, implement it, and use it
DerToaster98 Sep 10, 2024
8a2af8b
adjust comment
DerToaster98 Sep 10, 2024
0bfce90
adjust comment
DerToaster98 Sep 10, 2024
17b458e
remove old code
DerToaster98 Sep 10, 2024
4a6941a
remove 1.18 signListener
DerToaster98 Sep 11, 2024
000d987
fix build errors
DerToaster98 Sep 11, 2024
8349dd8
properly implement shouldCancel method (API + examples)
DerToaster98 Sep 11, 2024
e0f09d1
add override items and tools
DerToaster98 Sep 11, 2024
c68ff55
small tweaks regarding interactions
DerToaster98 Sep 11, 2024
e4ecbf9
NPE prevention
DerToaster98 Sep 11, 2024
6ab1baa
respect edits with dyecolors, wax, etc
DerToaster98 Sep 12, 2024
4a1f985
extract base elements from Cruise sign into a toggle sign
DerToaster98 Sep 12, 2024
b697375
update signs after detect
DerToaster98 Sep 12, 2024
b4f9032
cancel sign clicks on crafts in all cases
DerToaster98 Sep 12, 2024
35ea71e
only cancel when sign is empty
DerToaster98 Sep 12, 2024
9653b43
fix override param
DerToaster98 Sep 13, 2024
78d19f3
fix subcraft sign creation
DerToaster98 Sep 15, 2024
a4e21ec
Merge branch 'APDevTeam:main' into sign-rework-api
DerToaster98 Sep 17, 2024
889a5cf
Remote version specific SignListener implementations
DerToaster98 Sep 13, 2024
754f22e
adapt to refactoring
DerToaster98 Sep 13, 2024
ff1fd2f
use newer method
DerToaster98 Sep 13, 2024
ab2ebb7
fix compile errors and remove old code
DerToaster98 Sep 13, 2024
8c14dda
apply default text and implement processSignChange
DerToaster98 Sep 15, 2024
e864150
correct typo
DerToaster98 Sep 15, 2024
8f9ee61
return true
DerToaster98 Sep 17, 2024
c722fbb
call stuff for the other side, if that side is a movecraft sign
DerToaster98 Sep 17, 2024
ab7ae64
fix compile errors
DerToaster98 Sep 17, 2024
9d850ce
add getter for crafttype
DerToaster98 Sep 29, 2024
9d35183
check if player actually is the pilot of that craft
DerToaster98 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.countercraft.movecraft.config.Settings;
import net.countercraft.movecraft.craft.ChunkManager;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry;
import net.countercraft.movecraft.features.contacts.ContactsCommand;
import net.countercraft.movecraft.features.contacts.ContactsManager;
import net.countercraft.movecraft.features.contacts.ContactsSign;
Expand Down Expand Up @@ -59,6 +58,7 @@ public class Movecraft extends JavaPlugin {
private SmoothTeleport smoothTeleport;
private AsyncManager asyncManager;
private WreckManager wreckManager;
private SignListener abstractSignListener;

public static synchronized Movecraft getInstance() {
return instance;
Expand Down Expand Up @@ -213,22 +213,25 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
getServer().getPluginManager().registerEvents(new ChunkManager(), this);
getServer().getPluginManager().registerEvents(new AscendSign(), this);
getServer().getPluginManager().registerEvents(new CraftSign(), this);
getServer().getPluginManager().registerEvents(new CruiseSign(), this);
getServer().getPluginManager().registerEvents(new DescendSign(), this);
getServer().getPluginManager().registerEvents(new HelmSign(), this);
getServer().getPluginManager().registerEvents(new MoveSign(), this);
getServer().getPluginManager().registerEvents(new NameSign(), this);
getServer().getPluginManager().registerEvents(new PilotSign(), this);
getServer().getPluginManager().registerEvents(new RelativeMoveSign(), this);
getServer().getPluginManager().registerEvents(new ReleaseSign(), this);
getServer().getPluginManager().registerEvents(new RemoteSign(), this);
getServer().getPluginManager().registerEvents(new SpeedSign(), this);
getServer().getPluginManager().registerEvents(new SubcraftRotateSign(), this);
getServer().getPluginManager().registerEvents(new TeleportSign(), this);
getServer().getPluginManager().registerEvents(new ScuttleSign(), this);
getServer().getPluginManager().registerEvents(new CraftPilotListener(), this);
getServer().getPluginManager().registerEvents(new CraftReleaseListener(), this);
getServer().getPluginManager().registerEvents(new CraftTypeListener(), this);
getServer().getPluginManager().registerEvents(new SignListener(), this);

// Signs
AbstractMovecraftSign.register("Release", new ReleaseSign());

var contactsManager = new ContactsManager();
contactsManager.runTaskTimerAsynchronously(this, 0, 20);
Expand Down Expand Up @@ -340,4 +343,8 @@ public AsyncManager getAsyncManager() {
public @NotNull WreckManager getWreckManager(){
return wreckManager;
}

public SignListener getAbstractSignListener() {
return abstractSignListener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.countercraft.movecraft.processing.effects.Effect;
import net.countercraft.movecraft.processing.functions.CraftSupplier;
import net.countercraft.movecraft.processing.tasks.detection.DetectionTask;
import net.countercraft.movecraft.sign.AbstractMovecraftSign;
import net.countercraft.movecraft.sign.CraftPilotSign;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -96,6 +98,9 @@ private CraftManager(boolean loadCraftTypes) {
craftTypes = loadCraftTypes();
else
craftTypes = new HashSet<>();

// Since the event is only created in reload cases...
AbstractMovecraftSign.registerCraftPilotSigns(CraftManager.getInstance().getCraftTypes(), CraftPilotSign::new);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.countercraft.movecraft.listener;

import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.events.TypesReloadedEvent;
import net.countercraft.movecraft.sign.AbstractMovecraftSign;
import net.countercraft.movecraft.sign.CraftPilotSign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class CraftTypeListener implements Listener {

@EventHandler
public void onReload(TypesReloadedEvent event) {
AbstractMovecraftSign.registerCraftPilotSigns(CraftManager.getInstance().getCraftTypes(), CraftPilotSign::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.countercraft.movecraft.craft.SinkingCraft;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.events.CraftReleaseEvent;
import net.countercraft.movecraft.events.SignTranslateEvent;
import net.countercraft.movecraft.sign.SignListener;
import net.countercraft.movecraft.util.CollectionUtils;
import net.countercraft.movecraft.util.MathUtils;
import net.countercraft.movecraft.util.Tags;
Expand Down Expand Up @@ -201,55 +201,7 @@ public void doUpdate() {
}

private void sendSignEvents() {
Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {
@Override
public int hashCode(String[] strings) {
return Arrays.hashCode(strings);
}

@Override
public boolean equals(String[] a, String[] b) {
return Arrays.equals(a, b);
}
});
Map<MovecraftLocation, Sign> signStates = new HashMap<>();

for (MovecraftLocation location : craft.getHitBox()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) block.getState();
if (!signs.containsKey(sign.getLines()))
signs.put(sign.getLines(), new ArrayList<>());
signs.get(sign.getLines()).add(location);
signStates.put(location, sign);
}
}
for (Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()) {
SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
Bukkit.getServer().getPluginManager().callEvent(event);
// if(!event.isUpdated()){
// continue;
// }
// TODO: This is implemented only to fix client caching
// ideally we wouldn't do the update and would instead fake it out to the player
for (MovecraftLocation location : entry.getValue()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
BlockData data = block.getBlockData();
if (!(state instanceof Sign)) {
continue;
}
Sign sign = signStates.get(location);
if (event.isUpdated()) {
for (int i = 0; i < 4; i++) {
sign.setLine(i, entry.getKey()[i]);
}
}
sign.update(false, false);
block.setBlockData(data);
}
}
SignListener.INSTANCE.processSignTranslation(craft, true);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.countercraft.movecraft.craft.SinkingCraft;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.events.CraftReleaseEvent;
import net.countercraft.movecraft.events.SignTranslateEvent;
import net.countercraft.movecraft.sign.SignListener;
import net.countercraft.movecraft.util.MathUtils;
import net.countercraft.movecraft.util.Tags;
import net.countercraft.movecraft.util.hitboxes.HitBox;
Expand Down Expand Up @@ -303,54 +303,7 @@ private LinkedList<MovecraftLocation> hullSearch(SetHitBox validExterior) {
}

private void sendSignEvents(){
Object2ObjectMap<String[], List<MovecraftLocation>> signs = new Object2ObjectOpenCustomHashMap<>(new Hash.Strategy<String[]>() {
@Override
public int hashCode(String[] strings) {
return Arrays.hashCode(strings);
}

@Override
public boolean equals(String[] a, String[] b) {
return Arrays.equals(a, b);
}
});
Map<MovecraftLocation, Sign> signStates = new HashMap<>();

for (MovecraftLocation location : craft.getHitBox()) {
Block block = location.toBukkit(craft.getWorld()).getBlock();
if(!Tag.SIGNS.isTagged(block.getType())){
continue;
}
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
if(!signs.containsKey(sign.getLines()))
signs.put(sign.getLines(), new ArrayList<>());
signs.get(sign.getLines()).add(location);
signStates.put(location, sign);
}
}
for(Map.Entry<String[], List<MovecraftLocation>> entry : signs.entrySet()){
SignTranslateEvent event = new SignTranslateEvent(craft, entry.getKey(), entry.getValue());
Bukkit.getServer().getPluginManager().callEvent(event);
// if(!event.isUpdated()){
// continue;
// }
// TODO: This is implemented only to fix client caching
// ideally we wouldn't do the update and would instead fake it out to the player
for(MovecraftLocation location : entry.getValue()){
Block block = location.toBukkit(craft.getWorld()).getBlock();
BlockState state = block.getState();
if (!(state instanceof Sign)) {
continue;
}
Sign sign = signStates.get(location);
for(int i = 0; i<4; i++){
sign.setLine(i, entry.getKey()[i]);
}
sign.update(false, false);
}
}
SignListener.INSTANCE.processSignTranslation(craft, false);
}

@NotNull
Expand Down
Loading