Skip to content

Commit 3543abc

Browse files
committed
Big refactor, mainly: listener/onTick/settings.txt
1 parent 38c3c61 commit 3543abc

32 files changed

Lines changed: 304 additions & 304 deletions

src/main/java/net/evmodder/evmod/Configs.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ private static final List<IConfigBase> getConfigs(Settings settings){
134134

135135
if(settings.cmdMapArtGroup){
136136
configs.addAll(List.of(MAPART_GROUP_DEFAULT, MAPART_GROUP_UNLOCKED_HANDLING));
137-
if(settings.mapHighlights) configs.add(NEW_MAP_NOTIFIER_IFRAME);
137+
if(settings.onTickIframes) configs.add(NEW_MAP_NOTIFIER_IFRAME);
138138
}
139-
if(settings.mapHighlights) configs.add(MAX_IFRAME_TRACKING_DIST);
139+
if(settings.onTickIframes) configs.add(MAX_IFRAME_TRACKING_DIST);
140140
if(settings.placementHelperIframeAutoPlace){
141141
configs.addAll(List.of(IFRAME_AUTO_PLACER, IFRAME_AUTO_PLACER_MUST_CONNECT, IFRAME_AUTO_PLACER_MUST_MATCH_BLOCK));
142142
if(settings.showNicheConfigs) configs.addAll(List.of(IFRAME_AUTO_PLACER_REACH, IFRAME_AUTO_PLACER_RAYCAST, IFRAME_AUTO_PLACER_ROTATE_PLAYER));
@@ -163,17 +163,15 @@ private static final List<IConfigBase> getConfigs(Settings settings){
163163
MAPART_AUTOREMOVE.setBooleanValue(false);
164164
}
165165
if(settings.mapLoaderBot) configs.add(MAPART_SUPPRESS_BOT);
166-
// if(settings.keybindMapArtMove || settings.keybindMapArtMoveBundle)
167-
configs.addAll(List.of(SKIP_NULL_MAPS, SKIP_VOID_MAPS));
168-
if(settings.mapHighlights) configs.add(SKIP_MONO_COLOR_MAPS);
169-
166+
configs.addAll(List.of(SKIP_NULL_MAPS, SKIP_VOID_MAPS, SKIP_MONO_COLOR_MAPS));
167+
170168
if(settings.gameMessageListener) configs.addAll(List.of(WHISPER_PLAY_SOUND, WHISPER_PLAY_SOUND_UNFOCUSED, WHISPER_PEARL_PULL));
171169
if(!Main.mapArtFeaturesOnly){
172170
configs.add(SCROLL_ORDER);
173171
if(settings.serverJoinListener) configs.add(SEND_ON_SERVER_JOIN);
174172
if(settings.serverQuitListener) configs.add(LOG_COORDS_ON_SERVER_QUIT);
175173
}
176-
if(settings.inventoryRestockAuto) configs.addAll(List.of(INV_RESTOCK_AUTO, INV_RESTOCK_AUTO_FOR_INV_ORGS));
174+
if(settings.containerOpenCloseListener) configs.addAll(List.of(INV_RESTOCK_AUTO, INV_RESTOCK_AUTO_FOR_INV_ORGS));
177175
if(settings.broadcaster) configs.addAll(List.of(TEMP_BROADCAST_ACCOUNT, TEMP_BROADCAST_TIMESTAMP, TEMP_BROADCAST_MSGS));
178176
if(settings.showNicheConfigs) configs.add(DISABLE_DRAG_CLICK_ON_MAPS_AND_BUNDLES);
179177
return configs;
@@ -247,11 +245,11 @@ private static final List<IConfigBase> getConfigs(Settings settings){
247245
if(settings.tooltipRepairCost) configs.add(REPAIR_COST_TOOLTIP);
248246
}
249247
configs.add(INVIS_IFRAMES);
250-
if(settings.mapHighlights){
251-
configs.add(MAP_HIGHLIGHT_IFRAME);
248+
if(settings.tooltipMapHighlights || settings.onTickIframes/* || settings.hotbarHudMixin*/){
249+
if(settings.onTickIframes) configs.add(MAP_HIGHLIGHT_IFRAME);
250+
if(settings.onTickContainer) configs.add(MAP_HIGHLIGHT_CONTAINER_NAME);
252251
if(settings.tooltipMapHighlights) configs.add(MAP_HIGHLIGHT_TOOLTIP);
253252
configs.add(MAP_HIGHLIGHT_HOTBAR_HUD);
254-
if(settings.mapHighlightsInGUIs) configs.add(MAP_HIGHLIGHT_CONTAINER_NAME);
255253
configs.addAll(List.of(
256254
MAP_COLOR_IN_INV, MAP_COLOR_NOT_IN_GROUP, MAP_COLOR_UNLOCKED,
257255
MAP_COLOR_UNLOADED, MAP_COLOR_UNNAMED, MAP_COLOR_IN_IFRAME,

src/main/java/net/evmodder/evmod/KeyCallbacks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import net.evmodder.evmod.apis.ChatBroadcaster;
44
import net.evmodder.evmod.apis.EpearlLookup;
55
import net.evmodder.evmod.apis.RemoteServerSender;
6+
import net.evmodder.evmod.apis.WhisperPlaySound;
67
import net.evmodder.evmod.keybinds.*;
78
import net.evmodder.evmod.listeners.GameMessageFilter;
8-
import net.evmodder.evmod.listeners.WhisperPlaySound;
99
import net.minecraft.client.MinecraftClient;
1010
import net.minecraft.client.gui.screen.Screen;
1111
import net.minecraft.client.gui.screen.ingame.CartographyTableScreen;

src/main/java/net/evmodder/evmod/Main.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@
2525
import net.evmodder.evmod.apis.RemoteServerSender;
2626
import net.evmodder.evmod.apis.TickListener;
2727
import net.evmodder.evmod.apis.Tooltip;
28+
import net.evmodder.evmod.apis.WhisperPlaySound;
2829
import net.evmodder.evmod.commands.*;
2930
import net.evmodder.evmod.keybinds.KeybindCraftingRestock;
3031
import net.evmodder.evmod.keybinds.KeybindInventoryOrganize;
3132
import net.evmodder.evmod.keybinds.KeybindInventoryRestock;
3233
import net.evmodder.evmod.listeners.*;
3334
import net.evmodder.evmod.onTick.AutoPlaceItemFrames;
35+
import net.evmodder.evmod.onTick.ContainerOpenCloseListener;
3436
import net.evmodder.evmod.onTick.MapLoaderBot;
3537
import net.evmodder.evmod.onTick.TooltipMapLoreMetadata;
3638
import net.evmodder.evmod.onTick.TooltipMapNameColor;
3739
import net.evmodder.evmod.onTick.TooltipRepairCost;
38-
import net.evmodder.evmod.onTick.UpdateContainerHighlights;
39-
import net.evmodder.evmod.onTick.UpdateInventoryHighlights;
40-
import net.evmodder.evmod.onTick.UpdateItemFrameHighlights;
40+
import net.evmodder.evmod.onTick.UpdateContainerContents;
41+
import net.evmodder.evmod.onTick.UpdateInventoryContents;
42+
import net.evmodder.evmod.onTick.UpdateItemFrameContents;
4143
import net.fabricmc.loader.api.FabricLoader;
4244
import net.fabricmc.loader.api.metadata.ModMetadata;
4345
import net.minecraft.client.MinecraftClient;
@@ -131,12 +133,12 @@ public class Main{
131133
final KeybindInventoryRestock kbInvRestock = kbInvOrgs == null ? null : new KeybindInventoryRestock(kbInvOrgs);
132134
if(settings.containerOpenCloseListener){
133135
TickListener.register(new ContainerOpenCloseListener(kbInvRestock));
134-
ContainerClickListener.register();
136+
BlockClickListener.register();
135137
}
136138
kbCraftRestock = new KeybindCraftingRestock();
137139

138140
if(settings.placementHelperIframeAutoPlace) new AutoPlaceItemFrames();
139-
if(settings.placementHelperMapArt) new MapHandRestock(settings.placementHelperMapArtAutoPlace, settings.placementHelperMapArtAutoRemove);
141+
if(settings.placementHelperMapArt) new MapHangListener(settings.placementHelperMapArtAutoPlace, settings.placementHelperMapArtAutoRemove);
140142
if(settings.broadcaster) ChatBroadcaster.refreshBroadcast();
141143

142144
if(settings.cmdAssignPearl) new CommandAssignPearl(epearlLookup);
@@ -148,15 +150,10 @@ public class Main{
148150
if(settings.cmdSendAs) new CommandSendAs(remoteSender);
149151
if(settings.cmdTimeOnline) new CommandTimeOnline(remoteSender);
150152

151-
if(settings.mapHighlights){
152-
TickListener.register(new TickListener(){
153-
@Override public void onTickStart(MinecraftClient client){
154-
UpdateInventoryHighlights.onTickStart(client.player);
155-
UpdateItemFrameHighlights.onTickStart(client);
156-
if(settings.mapHighlightsInGUIs) UpdateContainerHighlights.onTickStart(client);
157-
}
158-
});
159-
}
153+
if(settings.onTickInventory) TickListener.register(new UpdateInventoryContents());
154+
if(settings.onTickIframes) TickListener.register(new UpdateItemFrameContents());
155+
if(settings.onTickContainer) TickListener.register(new UpdateContainerContents());
156+
160157
if(settings.tooltipMapHighlights) Tooltip.register(new TooltipMapNameColor());
161158
if(settings.tooltipMapMetadata) Tooltip.register(new TooltipMapLoreMetadata());
162159
if(settings.tooltipRepairCost) Tooltip.register(new TooltipRepairCost());

src/main/java/net/evmodder/evmod/Settings.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ final class Settings{
1414
private final String internalSettingsFile = Main.mapArtFeaturesOnly ? "settings_for_mapart_ver.txt" : "settings.txt";
1515

1616
final boolean showNicheConfigs;
17-
final boolean storeDataInInstanceFolder;
18-
final boolean database, epearlOwners;
17+
final boolean storeDataInInstanceFolder, database, epearlOwners;
1918
final boolean placementHelperIframeAutoPlace, placementHelperMapArt, placementHelperMapArtAutoPlace, placementHelperMapArtAutoRemove;
20-
final boolean mapLoaderBot, inventoryRestockAuto, broadcaster;
21-
final boolean serverJoinListener, serverQuitListener, gameMessageListener, gameMessageFilter, containerOpenCloseListener;
19+
final boolean serverJoinListener, serverQuitListener, gameMessageListener, gameMessageFilter;
20+
final boolean onTickInventory, onTickContainer, onTickIframes, containerOpenCloseListener, mapLoaderBot, broadcaster;
21+
final boolean tooltipMapHighlights, tooltipMapMetadata, tooltipRepairCost;
2222
final boolean cmdAssignPearl, cmdDeletedMapsNearby, cmdExportMapImg, cmdMapArtGroup, cmdMapHashCode, cmdSeen, cmdSendAs, cmdTimeOnline;
23-
final boolean mapHighlights, mapHighlightsInGUIs, tooltipMapHighlights, tooltipMapMetadata, tooltipRepairCost;
2423

2524

2625
private final HashMap<String, Boolean> loadSettings(){
@@ -34,9 +33,17 @@ private final HashMap<String, Boolean> loadSettings(){
3433
}
3534
}//==================================================
3635

37-
HashMap<String, Boolean> config = new HashMap<>();
38-
final String configContents = FileIO.loadFile("settings.txt", getClass().getResourceAsStream("/assets/"+Main.MOD_ID+"/"+internalSettingsFile));
39-
for(String line : configContents.split("\\r?\\n")){
36+
final HashMap<String, Boolean> config = new HashMap<>();
37+
String configContents = FileIO.loadFile("settings.txt", getClass().getResourceAsStream("/assets/"+Main.MOD_ID+"/"+internalSettingsFile));
38+
{//==================================================
39+
// TODO: remove these legacy-patches in a future version
40+
if(configContents.contains("map_highlights:")){
41+
Main.LOGGER.info("EvModConfig: Deleting unusable old settings.txt file (due to name changes; resetting to defaults)");
42+
FileIO.deleteFile("settings.txt");
43+
configContents = FileIO.loadFile("settings.txt", getClass().getResourceAsStream("/assets/"+Main.MOD_ID+"/"+internalSettingsFile));
44+
}
45+
}
46+
for(final String line : configContents.split("\\r?\\n")){
4047
final int sep = line.indexOf(':');
4148
if(sep == -1) continue;
4249
final String key = line.substring(0, sep).trim();
@@ -47,9 +54,9 @@ private final HashMap<String, Boolean> loadSettings(){
4754
return config;
4855
}
4956

50-
private final boolean extractConfigValue(HashMap<String, Boolean> config, String key){
57+
private final boolean extractConfigValue(final HashMap<String, Boolean> config, final String key){
5158
final Boolean value = config.remove(key);
52-
return value != null ? value : false;
59+
return value != null && value;
5360
}
5461

5562
Settings(){
@@ -63,21 +70,21 @@ private final boolean extractConfigValue(HashMap<String, Boolean> config, String
6370
epearlOwners = extractConfigValue(settings, "epearl_owners");
6471
broadcaster = extractConfigValue(settings, "broadcaster");
6572
placementHelperIframeAutoPlace = extractConfigValue(settings, "placement_helper.iframe.autoplace");
66-
placementHelperMapArt = extractConfigValue(settings, "placement_helper.mapart");
73+
onTickInventory = extractConfigValue(settings, "on_tick.inventory");
74+
onTickIframes = extractConfigValue(settings, "on_tick.iframes");
75+
onTickContainer = extractConfigValue(settings, "on_tick.container");
76+
containerOpenCloseListener = extractConfigValue(settings, "listener.container_open");
77+
placementHelperMapArt = onTickInventory && extractConfigValue(settings, "placement_helper.mapart");
6778
placementHelperMapArtAutoPlace = placementHelperMapArt && extractConfigValue(settings, "placement_helper.mapart.autoplace");
6879
placementHelperMapArtAutoRemove = placementHelperMapArt && extractConfigValue(settings, "placement_helper.mapart.autoremove");
6980
mapLoaderBot = extractConfigValue(settings, "map_bot.loader");
7081
serverJoinListener = extractConfigValue(settings, "listener.server_join");
7182
serverQuitListener = extractConfigValue(settings, "listener.server_quit");
7283
gameMessageListener = extractConfigValue(settings, "listener.game_message.read");
7384
gameMessageFilter = extractConfigValue(settings, "listener.game_message.filter");
74-
containerOpenCloseListener = extractConfigValue(settings, "listener.container_open");
75-
mapHighlights = extractConfigValue(settings, "map_highlights");
76-
mapHighlightsInGUIs = extractConfigValue(settings, "map_highlights.in_gui");
77-
tooltipMapHighlights = mapHighlights && extractConfigValue(settings, "tooltip.map_highlights");
85+
tooltipMapHighlights = (onTickInventory || onTickIframes) && extractConfigValue(settings, "tooltip.map_highlights");
7886
tooltipMapMetadata = extractConfigValue(settings, "tooltip.map_metadata");
7987
tooltipRepairCost = extractConfigValue(settings, "tooltip.repair_cost");
80-
inventoryRestockAuto = containerOpenCloseListener && extractConfigValue(settings, "inventory_restock.auto");
8188

8289
cmdAssignPearl = epearlOwners && extractConfigValue(settings, "command.assignpearl");
8390
cmdDeletedMapsNearby = extractConfigValue(settings, "command.deletedmapsnearby");

src/main/java/net/evmodder/evmod/apis/EpearlLookupFabric.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ public final class EpearlLookupFabric extends EpearlLookup{
3434
@Override protected boolean enableKeyXZ(){return Configs.Database.EPEARL_OWNERS_BY_XZ.getBooleanValue();}
3535
@Override protected boolean enableRemoteDbUUID(){return enableKeyUUID() && Configs.Database.SHARE_EPEARL_OWNERS.getBooleanValue();}
3636
@Override protected boolean enableRemoteDbXZ(){return enableKeyXZ() && Configs.Database.SHARE_EPEARL_OWNERS.getBooleanValue();}
37-
public boolean isDisabled(){return !enableKeyUUID() && !enableKeyXZ();} // Only accessor: MixinEntityRenderer
37+
public final boolean isDisabled(){return !enableKeyUUID() && !enableKeyXZ();} // Only accessor: MixinEntityRenderer
3838

3939
private final double DIST_XZ = 64, DIST_Y = 128; // Max dist for which to track/remove pearls
4040
private final double DIST_XZ_SQ = DIST_XZ*DIST_XZ, DIST_Y_SQ = DIST_Y*DIST_Y;
41-
private boolean isWithinDist(PlayerEntity player, PearlDataClient pdc){
41+
private final boolean isWithinDist(final PlayerEntity player, final PearlDataClient pdc){
4242
final double dx = pdc.x()-player.getBlockX(), dy = pdc.y()-player.getBlockY(), dz = pdc.z()-player.getBlockZ();
4343
return dx*dx + dz*dz < DIST_XZ_SQ && dy*dy < DIST_Y_SQ;
4444
}
4545

46-
private final UUID toKeyXZ(Entity epearl){
46+
private final UUID toKeyXZ(final Entity epearl){
4747
return new UUID(Double.doubleToRawLongBits(epearl.getX()), Double.doubleToRawLongBits(epearl.getZ()));
4848
}
49-
private final ChunkPos toChunkPos(PearlDataClient pdc){
49+
private final ChunkPos toChunkPos(final PearlDataClient pdc){
5050
return new ChunkPos(pdc.x()<<4, pdc.z()<<4);
5151
}
5252

53-
public EpearlLookupFabric(RemoteServerSender rms){
53+
public EpearlLookupFabric(final RemoteServerSender rms){
5454
super(rms, Main.LOGGER);
5555
ClientChunkEvents.CHUNK_LOAD.register((phase, listener)->{
5656
if(isDisabled()) return;
@@ -72,7 +72,7 @@ public EpearlLookupFabric(RemoteServerSender rms){
7272
});
7373

7474
TickListener.register(new TickListener(){
75-
@Override public void onTickStart(MinecraftClient client){
75+
@Override public void onTickStart(final MinecraftClient client){
7676
if(isDisabled()) return;
7777
synchronized(recentlyLoadedChunks){
7878
if(client == null || client.player == null || world != client.world || client.world == null){

src/main/java/net/evmodder/evmod/apis/MapStateCacher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import net.evmodder.evmod.Configs;
1515
import net.evmodder.evmod.Main;
1616
import net.evmodder.evmod.config.OptionMapStateCache;
17-
import net.evmodder.evmod.listeners.ContainerClickListener;
17+
import net.evmodder.evmod.listeners.BlockClickListener;
1818
import net.minecraft.client.MinecraftClient;
1919
import net.minecraft.client.world.ClientWorld;
2020
import net.minecraft.component.DataComponentTypes;
@@ -111,7 +111,7 @@ private static final Object getInMemCacheSpecific(String server, String cache){
111111
case BY_PLAYER_EC:
112112
return bySlot == null ? null : (subCache=bySlot.get(server)) == null ? null : subCache.get(getIdForPlayer(false));
113113
case BY_CONTAINER:
114-
return bySlot == null ? null : (subCache=bySlot.get(server)) == null ? null : subCache.get(ContainerClickListener.lastClickedBlockHash);
114+
return bySlot == null ? null : (subCache=bySlot.get(server)) == null ? null : subCache.get(BlockClickListener.lastClickedBlockHash);
115115
default:
116116
throw new RuntimeException("MapStateCacher: Unknown cache type in getInMemCacheSpecific()! "+cache);
117117
}
@@ -192,7 +192,7 @@ public static final boolean saveMapStatesByPos(Stream<ItemStack> items, String c
192192
switch(cache){
193193
case BY_PLAYER_INV: key = getIdForPlayer(true); break;
194194
case BY_PLAYER_EC: key = getIdForPlayer(false); break;
195-
case BY_CONTAINER: key = ContainerClickListener.lastClickedBlockHash; break;
195+
case BY_CONTAINER: key = BlockClickListener.lastClickedBlockHash; break;
196196
default: throw new RuntimeException("MapStateCacher: Unknown cache type in saveMapStatesByPos()! "+cache);
197197
}
198198
if(!deleteCache) bySlotPerServer.put(key, serialStates);
@@ -231,7 +231,7 @@ private static final Object commonCacheLoad(String cache){
231231
switch(cache){
232232
case BY_PLAYER_INV: key = getIdForPlayer(true); break;
233233
case BY_PLAYER_EC: key = getIdForPlayer(false); break;
234-
case BY_CONTAINER: key = ContainerClickListener.lastClickedBlockHash; break;
234+
case BY_CONTAINER: key = BlockClickListener.lastClickedBlockHash; break;
235235
default: throw new RuntimeException("MapStateCacher: Unreachable in commonCacheLoad()!");
236236
}
237237
return bySlot.get(server).get(key);

src/main/java/net/evmodder/evmod/apis/TickListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import net.minecraft.client.MinecraftClient;
55

66
public interface TickListener{
7-
public default void onTickStart(MinecraftClient client){}
8-
public default void onTickEnd(MinecraftClient client){}
7+
public default void onTickStart(final MinecraftClient client){}
8+
public default void onTickEnd(final MinecraftClient client){}
99

10-
public static void register(TickListener tickListener){
10+
public static void register(final TickListener tickListener){
1111
try{
1212
if(!tickListener.getClass().getMethod("onTickStart", MinecraftClient.class).getDeclaringClass().equals(TickListener.class))
1313
ClientTickEvents.START_CLIENT_TICK.register(tickListener::onTickStart);

src/main/java/net/evmodder/evmod/listeners/WhisperPlaySound.java renamed to src/main/java/net/evmodder/evmod/apis/WhisperPlaySound.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.evmodder.evmod.listeners;
1+
package net.evmodder.evmod.apis;
22

33
import net.evmodder.evmod.Configs;
44
import net.evmodder.evmod.Main;

src/main/java/net/evmodder/evmod/commands/CommandExportMapImg.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import net.evmodder.evmod.apis.InvUtils;
3434
import net.evmodder.evmod.apis.MapRelationUtils;
3535
import net.evmodder.evmod.apis.MapRelationUtils.RelatedMapsData;
36-
import net.evmodder.evmod.onTick.UpdateItemFrameHighlights;
36+
import net.evmodder.evmod.onTick.UpdateItemFrameContents;
3737
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
3838
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
3939
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
@@ -629,7 +629,7 @@ private final boolean isReflectedChar(final char l, final char r){
629629
private final HashMap<String, String> cmdMapNames = new HashMap<>();
630630
private long lastNameComputeTs;
631631
private final Set<String> getNearbyMapNames(final ClientPlayerEntity player){
632-
if(!cmdMapNames.isEmpty() && lastNameComputeTs >= UpdateItemFrameHighlights.lastIFrameMapGroupUpdateTs) return cmdMapNames.keySet();
632+
if(!cmdMapNames.isEmpty() && lastNameComputeTs >= UpdateItemFrameContents.lastIFrameMapGroupUpdateTs) return cmdMapNames.keySet();
633633
lastNameComputeTs = System.currentTimeMillis();
634634
cmdMapNames.clear();
635635

src/main/java/net/evmodder/evmod/commands/SepStringArgumentType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import com.mojang.brigadier.arguments.ArgumentType;
55
import com.mojang.brigadier.exceptions.CommandSyntaxException;
66

7+
// A more generalized/simpler alternative to StringArgumentType.word()
8+
// StringArgumentType.word() only allows [a-zA-Z0-9_-.+], whereas this allows ANY char which isn't the 'sep'
9+
710
public class SepStringArgumentType implements ArgumentType<String>{
811
private final char sep;
912

1013
private SepStringArgumentType(final char sep){this.sep = sep;}
11-
public static SepStringArgumentType word(char sep){return new SepStringArgumentType(sep);}
14+
public static SepStringArgumentType word(final char sep){return new SepStringArgumentType(sep);}
1215

1316
@Override public String parse(final StringReader reader) throws CommandSyntaxException{
14-
int start = reader.getCursor();
17+
final int start = reader.getCursor();
1518
while(reader.canRead() && reader.peek() != sep) reader.skip();
1619
return reader.getString().substring(start, reader.getCursor());
1720
}

0 commit comments

Comments
 (0)