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 / Cleanup] Sign rework (WIP) #679

Open
wants to merge 123 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
ed29a0a
begin new sign API
DerToaster98 Aug 1, 2024
0825279
add base class for signs and registration
DerToaster98 Aug 1, 2024
b66b5e0
add craft sign => For stuff like cruise signs or remote signs
DerToaster98 Aug 1, 2024
6a3ad90
implement listener that calls the individual registered signs
DerToaster98 Aug 1, 2024
9ca4816
add base for cruise-like signs
DerToaster98 Aug 2, 2024
c80df99
add overloaded internalProcessing method for craftsigns
DerToaster98 Aug 2, 2024
07e829e
add method to get ident of sign instance
DerToaster98 Aug 2, 2024
edbd6ef
call detect event with the sign
DerToaster98 Aug 2, 2024
0b3f467
migrate name sign to new sign API
DerToaster98 Aug 2, 2024
95cbe5b
organize imports
DerToaster98 Aug 2, 2024
f82bb7b
reimplement release sign with new sign api
DerToaster98 Aug 2, 2024
4692881
reimplement scuttle sign with new sign API
DerToaster98 Aug 2, 2024
08611a9
register release and scuttle signs
DerToaster98 Aug 2, 2024
d4f9cbb
migrate Move and RMove signs
DerToaster98 Aug 2, 2024
8f92799
move perm check to canPlayerUseOn
DerToaster98 Aug 4, 2024
81cf5a9
migrate helm sign
DerToaster98 Aug 4, 2024
99aa146
rename method to "onCraftisBusy" is it isn't always a parent craft bu…
DerToaster98 Aug 4, 2024
a66a0af
allow double colons in idents
DerToaster98 Aug 4, 2024
c4623f5
add comment for later
DerToaster98 Aug 4, 2024
9575095
make sign listener abstract and add abstraction layer to signs
DerToaster98 Aug 10, 2024
2997b1e
initialize sign listener like the version specific stuff
DerToaster98 Aug 10, 2024
604abeb
refactor sign base classes to use the abstraction class
DerToaster98 Aug 10, 2024
c1bf27d
add base for info signs
DerToaster98 Aug 10, 2024
0edd8cb
refactors
DerToaster98 Aug 10, 2024
d679689
add 1.21 implementation of signlistener
DerToaster98 Aug 10, 2024
02fe15e
fix imports
DerToaster98 Aug 10, 2024
ef9ca4b
add 1.20 implementation of listener
DerToaster98 Aug 10, 2024
383683e
add 1.18 signListener implementation
DerToaster98 Aug 10, 2024
f8e6c02
migrate teleport sign and fix move sign
DerToaster98 Aug 10, 2024
7260f9d
fix helm sign
DerToaster98 Aug 10, 2024
7b77377
add comment in TeleportSign
DerToaster98 Aug 10, 2024
ddec33c
migrate PilotSign
DerToaster98 Aug 10, 2024
a3b2c52
migrate cruise sign
DerToaster98 Aug 10, 2024
6913afe
forgot that
DerToaster98 Aug 10, 2024
57c9d98
migrate cruise signs
DerToaster98 Aug 10, 2024
38c644a
fix namesign
DerToaster98 Aug 10, 2024
0d61dd5
migrate speed sign
DerToaster98 Aug 10, 2024
f9681d4
own wrapper for SignTranslateEvent
DerToaster98 Aug 10, 2024
50b83dc
actually return something
DerToaster98 Aug 10, 2024
d95c1d0
migrate speed sign
DerToaster98 Aug 10, 2024
2a53a7c
forgot those
DerToaster98 Aug 10, 2024
35ea966
move status sign class
DerToaster98 Aug 11, 2024
d882603
add constants for colors and add enum for update reason
DerToaster98 Aug 11, 2024
1ede8b7
migrate status sign
DerToaster98 Aug 11, 2024
b546e7a
fix speed sign
DerToaster98 Aug 11, 2024
1bcae23
migrate craft pilot sign
DerToaster98 Aug 14, 2024
e89dbf5
register calls
DerToaster98 Aug 14, 2024
01cf53c
remove old sign
DerToaster98 Aug 14, 2024
540d89f
add helper methods
DerToaster98 Aug 14, 2024
47638bd
add todo notes
DerToaster98 Aug 15, 2024
bea521b
move status sign back to where it was
DerToaster98 Aug 19, 2024
e9b7c62
subscribe to event to re-register the craft sigsn
DerToaster98 Aug 19, 2024
5efcc73
remove unnecessary if
DerToaster98 Aug 19, 2024
4537421
Optional => Nullable string
DerToaster98 Aug 19, 2024
69d701d
typo fix
DerToaster98 Aug 19, 2024
b307c87
add overloaded register method
DerToaster98 Aug 19, 2024
8219dc3
Optional<Craft> => Nullable Craft
DerToaster98 Aug 19, 2024
0b3d5d1
remove static modifier
DerToaster98 Aug 19, 2024
344afce
refactor equals function
DerToaster98 Aug 19, 2024
a133c7b
documentation
DerToaster98 Aug 20, 2024
3a261a6
small corrections
DerToaster98 Aug 20, 2024
a755453
add base for subcraft signs
DerToaster98 Aug 20, 2024
e78f2fd
migrate Remote Sign
DerToaster98 Aug 27, 2024
ebc5a3b
Migrate subcraft rotate sign
DerToaster98 Aug 27, 2024
e493b78
fix refactor artifact
DerToaster98 Aug 27, 2024
dc0075c
remove unneeded variable => use the field!
DerToaster98 Aug 27, 2024
f8414ed
migrate contacts sign
DerToaster98 Aug 28, 2024
36fbe17
fix error
DerToaster98 Aug 28, 2024
1b512f2
add isEmpty() method and add implementation for equals
DerToaster98 Aug 28, 2024
c84a81a
if the other is null it will be false. Always
DerToaster98 Aug 28, 2024
48add81
begin migrating SignTranslateEvent to use the signwrapper (issue #688)
DerToaster98 Aug 28, 2024
104be46
add methods to directly allow Component as header dient
DerToaster98 Aug 28, 2024
22f1520
use new methods
DerToaster98 Aug 28, 2024
c583ab4
todo notes
DerToaster98 Aug 28, 2024
dce6e0f
use new methods in SignTranslateEvent
DerToaster98 Aug 28, 2024
514a447
add facing value to event
DerToaster98 Aug 29, 2024
fb0446e
add more utility and itnerface methods
DerToaster98 Aug 29, 2024
376986c
call the adatper
DerToaster98 Aug 29, 2024
4e407a3
implement methods in adatpers
DerToaster98 Aug 29, 2024
9531e36
adjust information signs
DerToaster98 Aug 29, 2024
630dd47
deprecation note
DerToaster98 Aug 29, 2024
13831c2
Merge branch 'main' into sign-rework
DerToaster98 Aug 29, 2024
9b20ae0
fix method name
DerToaster98 Aug 29, 2024
68c62a1
fix compile errors
DerToaster98 Aug 29, 2024
92141d4
fix release sign => it is not dependant on a craft existing!
DerToaster98 Aug 29, 2024
2df78c5
fix startup error => can't retrieve ident while registering
DerToaster98 Sep 5, 2024
960b30a
fix getSignWrappers() method for sign => NPE
DerToaster98 Sep 5, 2024
060d8b4
fix status sign
DerToaster98 Sep 5, 2024
debb191
craft is nullable
DerToaster98 Sep 5, 2024
39e08a5
corrections to BlockFace access
DerToaster98 Sep 5, 2024
9b7ea60
more fixes regarding getting the blockface of a sign...
DerToaster98 Sep 5, 2024
48a9bc1
NPE prevention
DerToaster98 Sep 5, 2024
ca35cd3
add TODO note
DerToaster98 Sep 5, 2024
464fcd6
remove spaces from suffix
DerToaster98 Sep 5, 2024
b65562e
correction => if the ident has trailing : => don't add them yourself …
DerToaster98 Sep 5, 2024
132f179
startup correction
DerToaster98 Sep 5, 2024
5ff7af8
forgot the space
DerToaster98 Sep 5, 2024
9fb1917
avoid double inversion
DerToaster98 Sep 5, 2024
e09c26d
crafttype is specified in second, not the third line
DerToaster98 Sep 5, 2024
6b1d67f
typo
DerToaster98 Sep 5, 2024
eb50ec4
remote sign correction => don't use old list, use HashMap and use com…
DerToaster98 Sep 5, 2024
8e76762
fix information signs not updating
DerToaster98 Sep 6, 2024
d86b510
comment out debug logs
DerToaster98 Sep 6, 2024
5ac3fc6
call update on the state, not on the block...
DerToaster98 Sep 6, 2024
7bf7297
more elegant solution
DerToaster98 Sep 6, 2024
0178865
actually perform the update, event uses the signwrapper under the hoo…
DerToaster98 Sep 6, 2024
9da541b
fix status sign (reimplement based on @Vaan1310 changes)
DerToaster98 Sep 6, 2024
26d1497
NPE prevention
DerToaster98 Sep 6, 2024
1153498
remove unnecessary toUpperCase()
DerToaster98 Sep 6, 2024
731aae7
add eventtype enum (to api classes)
DerToaster98 Sep 6, 2024
baad4f8
refactor for eventtype enum (implementations)
DerToaster98 Sep 6, 2024
cdd55d1
refactor for eventtype enum (implementations (simple))
DerToaster98 Sep 6, 2024
f4eef4a
Status Sign: round to 2 decimals
DerToaster98 Sep 6, 2024
4bc2ad4
supply eventType and use nullable for sign get access
DerToaster98 Sep 10, 2024
21c61c0
just call it override
DerToaster98 Sep 10, 2024
9acc31a
add registry base class, implement it, and use it
DerToaster98 Sep 10, 2024
aef31b4
adjust comment
DerToaster98 Sep 10, 2024
970d49d
adjust comment
DerToaster98 Sep 10, 2024
0da888d
remove old code
DerToaster98 Sep 10, 2024
bf29040
index out of bounds exception patch
DerToaster98 Sep 21, 2024
d44c29d
add getter for crafttype
DerToaster98 Sep 29, 2024
ca320fc
cherry pick commit
DerToaster98 Oct 5, 2024
dcddc05
cherry pick commit
DerToaster98 Oct 5, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package net.countercraft.movecraft.listener;public class SignListener {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package net.countercraft.movecraft.sign;public class AbstractCraftSign {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package net.countercraft.movecraft.sign;

import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.util.MathUtils;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public abstract class AbstractMovecraftSign {

private static final Map<String, AbstractMovecraftSign> SIGNS = Collections.synchronizedMap(new HashMap<>());

public static boolean hasBeenRegistered(final String ident) {
return SIGNS.containsKey(ident);
}

public static Optional<AbstractMovecraftSign> tryGet(final String ident) {
String identToUse = ident.toUpperCase();
if (identToUse.indexOf(":") >= 0) {
identToUse = identToUse.split(":")[0];
}
return Optional.ofNullable(SIGNS.getOrDefault(identToUse, null));
}

public static void forceRegister(final String ident, final @Nonnull AbstractMovecraftSign instance) {
register(ident, instance, true);
}

public static void register(final String ident, final @Nonnull AbstractMovecraftSign instance, boolean allowOverride) {
if (allowOverride) {
SIGNS.put(ident.toUpperCase(), instance);
} else {
SIGNS.putIfAbsent(ident.toUpperCase(), instance);
}
}

protected final Optional<String> optPermission;

public AbstractMovecraftSign() {
this(null);
}

public AbstractMovecraftSign(String permissionNode) {
this.optPermission = Optional.ofNullable(permissionNode);
}

// Return true to cancel the event
public boolean processSignClick(Action clickType, Sign sign, Player player) {
if (!this.isSignValid(clickType, sign, player)) {
return false;
}
if (!this.canPlayerUseSign(clickType, sign, player)) {
return false;
}

return internalProcessSign(clickType, sign, player, getCraft(sign));
}

protected boolean canPlayerUseSign(Action clickType, Sign sign, Player player) {
if (this.optPermission.isPresent()) {
return player.hasPermission(this.optPermission.get());
}
return true;
}

protected Optional<Craft> getCraft(Sign sign) {
return Optional.ofNullable(MathUtils.getCraftByPersistentBlockData(sign.getLocation()));
}

public abstract boolean shouldCancelEvent(boolean processingSuccessful, @Nullable Action type, boolean sneaking);
protected abstract boolean isSignValid(Action clickType, Sign sign, Player player);
protected abstract boolean internalProcessSign(Action clickType, Sign sign, Player player, Optional<Craft> craft);
public abstract boolean processSignChange(SignChangeEvent event);

}