generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from RappyLabyAddons/feat/activity
Actual complete overhaul
- Loading branch information
Showing
28 changed files
with
1,233 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 30 additions & 75 deletions
105
core/src/main/java/com/rappytv/toolwarn/config/TbwConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,60 @@ | ||
package com.rappytv.toolwarn.config; | ||
|
||
import com.rappytv.toolwarn.config.subconfig.TbwSoundSubConfig; | ||
import com.rappytv.toolwarn.ui.ToolConfigActivity; | ||
import com.rappytv.toolwarn.util.WarnTool; | ||
import net.labymod.api.addon.AddonConfig; | ||
import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget.SliderSetting; | ||
import net.labymod.api.client.gui.screen.activity.Activity; | ||
import net.labymod.api.client.gui.screen.widget.widgets.activity.settings.ActivitySettingWidget.ActivitySetting; | ||
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting; | ||
import net.labymod.api.configuration.loader.annotation.ConfigName; | ||
import net.labymod.api.configuration.loader.annotation.Exclude; | ||
import net.labymod.api.configuration.loader.annotation.IntroducedIn; | ||
import net.labymod.api.configuration.loader.annotation.SpriteSlot; | ||
import net.labymod.api.configuration.loader.annotation.SpriteTexture; | ||
import net.labymod.api.configuration.loader.annotation.VersionCompatibility; | ||
import net.labymod.api.configuration.loader.property.ConfigProperty; | ||
import net.labymod.api.configuration.settings.annotation.SettingSection; | ||
import net.labymod.api.util.MethodOrder; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ConfigName("settings") | ||
@SpriteTexture(value = "settings") | ||
public class TbwConfiguration extends AddonConfig { | ||
|
||
@SwitchSetting | ||
@SpriteSlot(size = 32) | ||
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true); | ||
@SettingSection("general") | ||
@SwitchSetting | ||
@SpriteSlot(size = 32, x = 1) | ||
private final ConfigProperty<Boolean> openChat = new ConfigProperty<>(true); | ||
@SwitchSetting | ||
@SpriteSlot(size = 32, x = 3) | ||
private final ConfigProperty<Boolean> lastHit = new ConfigProperty<>(true); | ||
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true); | ||
|
||
@SettingSection("sounds") | ||
@SpriteSlot(size = 32, y = 1) | ||
private final TbwSoundSubConfig sounds = new TbwSoundSubConfig(); | ||
@Exclude | ||
private final List<WarnTool> tools = new ArrayList<>(); | ||
|
||
@SettingSection("tools") | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 2) | ||
private final ConfigProperty<Integer> swordPercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 2, x = 1) | ||
private final ConfigProperty<Integer> pickaxePercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 2, x = 2) | ||
private final ConfigProperty<Integer> axePercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 2, x = 3) | ||
private final ConfigProperty<Integer> shovelPercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 3) | ||
@VersionCompatibility("1.14<*") | ||
@IntroducedIn(namespace = "globaltags", value = "1.4.3") | ||
private final ConfigProperty<Integer> crossbowPercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 3, x = 1) | ||
@IntroducedIn(namespace = "globaltags", value = "1.4.3") | ||
private final ConfigProperty<Integer> lighterPercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 3, x = 2) | ||
@IntroducedIn(namespace = "globaltags", value = "1.4.3") | ||
private final ConfigProperty<Integer> shearsPercentage = new ConfigProperty<>(5); | ||
@SliderSetting(steps = 1, min = 1, max = 25) | ||
@SpriteSlot(size = 32, y = 3, x = 3) | ||
@VersionCompatibility("1.13<*") | ||
@IntroducedIn(namespace = "globaltags", value = "1.4.3") | ||
private final ConfigProperty<Integer> tridentPercentage = new ConfigProperty<>(5); | ||
@IntroducedIn(namespace = "toolwarn", value = "1.4.0") | ||
@SpriteSlot(size = 32, x = 1) | ||
@MethodOrder(after = "enabled") | ||
@ActivitySetting | ||
public Activity toolConfig() { | ||
return new ToolConfigActivity(); | ||
} | ||
|
||
@Override | ||
public ConfigProperty<Boolean> enabled() { | ||
return enabled; | ||
} | ||
public ConfigProperty<Boolean> openChat() { | ||
return openChat; | ||
} | ||
public ConfigProperty<Boolean> lastHit() { | ||
return lastHit; | ||
} | ||
|
||
public TbwSoundSubConfig sounds() { | ||
return sounds; | ||
public List<WarnTool> getTools() { | ||
return tools; | ||
} | ||
|
||
public ConfigProperty<Integer> swordPercentage() { | ||
return swordPercentage; | ||
} | ||
public ConfigProperty<Integer> pickAxePercentage() { | ||
return pickaxePercentage; | ||
} | ||
public ConfigProperty<Integer> axePercentage() { | ||
return axePercentage; | ||
} | ||
public ConfigProperty<Integer> shovelPercentage() { | ||
return shovelPercentage; | ||
} | ||
public ConfigProperty<Integer> crossbowPercentage() { | ||
return crossbowPercentage; | ||
public void removeInvalidTools() { | ||
this.tools.removeIf(entry -> | ||
entry.getWarnAt() < 1 | ||
|| entry.getWarnAt() > 25 | ||
|| entry.getType() == null | ||
); | ||
} | ||
public ConfigProperty<Integer> lighterPercentage() { | ||
return lighterPercentage; | ||
} | ||
public ConfigProperty<Integer> shearsPercentage() { | ||
return shearsPercentage; | ||
} | ||
public ConfigProperty<Integer> tridentPercentage() { | ||
return tridentPercentage; | ||
|
||
@Override | ||
public int getConfigVersion() { | ||
return 2; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
core/src/main/java/com/rappytv/toolwarn/listener/ConfigMigrationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.rappytv.toolwarn.listener; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.rappytv.toolwarn.config.TbwConfiguration; | ||
import com.rappytv.toolwarn.util.WarnSound; | ||
import com.rappytv.toolwarn.util.WarnTool; | ||
import com.rappytv.toolwarn.util.WarnTool.Type; | ||
import net.labymod.api.configuration.loader.Config; | ||
import net.labymod.api.event.Subscribe; | ||
import net.labymod.api.event.labymod.config.ConfigurationVersionUpdateEvent; | ||
|
||
@SuppressWarnings("FieldCanBeLocal") | ||
public class ConfigMigrationListener { | ||
|
||
private final Gson gson = new Gson(); | ||
private final int defaultPercentage = 5; | ||
|
||
@Subscribe | ||
public void onConfigVersionUpdate(ConfigurationVersionUpdateEvent event) { | ||
Class<? extends Config> configClass = event.getConfigClass(); | ||
int usedVersion = event.getUsedVersion(); | ||
|
||
if(configClass == TbwConfiguration.class) { | ||
if(usedVersion == 1) migrateFromOne(event); | ||
} | ||
} | ||
|
||
private void migrateFromOne(ConfigurationVersionUpdateEvent event) { | ||
JsonObject config = event.getJsonObject(); | ||
if(!config.has("sounds")) return; | ||
|
||
JsonObject sounds = config.get("sounds").getAsJsonObject(); | ||
|
||
WarnSound warnSound = WarnSound.NONE; | ||
WarnSound lastHitSound = WarnSound.NONE; | ||
boolean openChat = true; | ||
boolean lastHitWarn = true; | ||
int sword = defaultPercentage; | ||
int pickaxe = defaultPercentage; | ||
int axe = defaultPercentage; | ||
int shovel = defaultPercentage; | ||
int crossbow = defaultPercentage; | ||
int lighter = defaultPercentage; | ||
int shears = defaultPercentage; | ||
int trident = defaultPercentage; | ||
|
||
try { | ||
warnSound = WarnSound.valueOf(sounds.get("warnSound").getAsString()); | ||
lastHitSound = WarnSound.valueOf(sounds.get("lastHitSound").getAsString()); | ||
openChat = config.get("openChat").getAsBoolean(); | ||
lastHitWarn = config.get("lastHit").getAsBoolean(); | ||
sword = config.get("swordPercentage").getAsInt(); | ||
pickaxe = config.get("pickaxePercentage").getAsInt(); | ||
axe = config.get("axePercentage").getAsInt(); | ||
shovel = config.get("shovelPercentage").getAsInt(); | ||
crossbow = config.get("crossbowPercentage").getAsInt(); | ||
lighter = config.get("lighterPercentage").getAsInt(); | ||
shears = config.get("shearsPercentage").getAsInt(); | ||
trident = config.get("tridentPercentage").getAsInt(); | ||
} catch (IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
JsonArray tools = new JsonArray(); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.SWORD, warnSound, lastHitSound, sword, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.PICKAXE, warnSound, lastHitSound, pickaxe, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.AXE, warnSound, lastHitSound, axe, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.SHOVEL, warnSound, lastHitSound, shovel, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.CROSSBOW, warnSound, lastHitSound, crossbow, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.LIGHTER, warnSound, lastHitSound, lighter, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.SHEARS, warnSound, lastHitSound, shears, openChat, lastHitWarn))); | ||
tools.add(gson.toJsonTree(new WarnTool(Type.TRIDENT, warnSound, lastHitSound, trident, openChat, lastHitWarn))); | ||
|
||
config.add("tools", tools); | ||
event.setJsonObject(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.