Skip to content

Commit

Permalink
begin migrating SignTranslateEvent to use the signwrapper (issue APDe…
Browse files Browse the repository at this point in the history
  • Loading branch information
DerToaster98 committed Aug 28, 2024
1 parent c84a81a commit 48add81
Showing 1 changed file with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,85 @@

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.sign.AbstractSignListener;
import net.kyori.adventure.text.Component;
import org.bukkit.block.BlockFace;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// TODO: Rewrite to use the adventure API
public class SignTranslateEvent extends CraftEvent{
private static final HandlerList HANDLERS = new HandlerList();
@NotNull private final List<MovecraftLocation> locations;
@NotNull private final String[] lines;
@NotNull private final AbstractSignListener.SignWrapper backing;
private boolean updated = false;

@Deprecated(forRemoval = true)
public SignTranslateEvent(@NotNull Craft craft, @NotNull String[] lines, @NotNull List<MovecraftLocation> locations) throws IndexOutOfBoundsException{
super(craft);
this.locations = locations;
if(lines.length!=4)
throw new IndexOutOfBoundsException();
this.lines=lines;
List<Component> components = new ArrayList<>();
for (String s : lines) {
components.add(Component.text(s));
}
this.backing = new AbstractSignListener.SignWrapper(null, components::get, components, components::set, BlockFace.SELF);
}

public SignTranslateEvent(@NotNull Craft craft, @NotNull AbstractSignListener.SignWrapper backing, @NotNull List<MovecraftLocation> locations) throws IndexOutOfBoundsException{
super(craft);
this.locations = locations;
this.backing = backing;
}

@NotNull
@Deprecated
@Deprecated(forRemoval = true)
public String[] getLines() {
// TODO: Why does this set it to updated? This is just reading...
this.updated = true;
return lines;
return backing.rawLines();
}

@Deprecated(forRemoval = true)
public String getLine(int index) throws IndexOutOfBoundsException{
if(index > 3 || index < 0)
throw new IndexOutOfBoundsException();
return lines[index];
return backing.getRaw(index);
}

@Deprecated(forRemoval = true)
public void setLine(int index, String line){
if(index > 3 || index < 0)
throw new IndexOutOfBoundsException();
this.updated = true;
lines[index]=line;
backing.line(index, Component.text(line));
}

public Component line(int index) {
return backing.line(index);
}

public void line(int index, Component component) {
this.updated = true;
backing.line(index, component);
}

public String getRaw(int index) {
return backing.getRaw(index);
}

public String[] rawLines() {
return backing.rawLines();
}

public List<Component> lines() {
return backing.lines();
}

// Bukkit crap
@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down

0 comments on commit 48add81

Please sign in to comment.