Skip to content

Commit

Permalink
Merge pull request #1 from Lezurex/multiple-gamemodes
Browse files Browse the repository at this point in the history
Multiple gamemodes
  • Loading branch information
VoxCrafterLP authored Dec 31, 2020
2 parents b178f01 + 30f007b commit 773b9e6
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 164 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ eclipse
run

*.log
*.log.gz
*.log.gz

# minecraft

.saves
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# LabyCookies
This is a free-to-use addon for the Minecraft Modification "LabyMod". It was originally developed by [VoxCrafter_LP](https://github.com/VoxCrafterLP) and is now under development of [Lezurex](https://github.com/Lezurex). It automatically gets the stats of all the players
in a game of "Cookies" on the Minecraft network GommeHD.net.
in an available gamemode on the Minecraft network [GommeHD.net](https://gommehd.net).

## Installation
To install this addon, just download the [latest release](https://github.com/Lezurex/LabyCookies/releases) on the right and copy the .jar into the LabyMod addons folder located at `MINECRAFT_FOLDER\LabyMod\addons-1.8`.
To install this addon, just download the [latest release](https://github.com/Lezurex/LabyCookies/releases) on the right and copy the .jar into the LabyMod addons folder located at `MINECRAFT_FOLDER\LabyMod\addons-1.8`. <br>
To locate your minecraft folder (on Windows), you have to press `CTRL + R` and type in `%appdata%\.minecraft`. You will be automatically redirected to your minecraft folder.

## Usage
After the installation, you can just join a game of "Cookies" and let the addon request the stats for you.
After the installation, you can just join a game of a gamemode of your choice and let the addon request the stats for you.

## Features
- Automatically gets a joined player's stats
Expand Down
Binary file removed saves/New World/DIM-1/data/villages_nether.dat
Binary file not shown.
Binary file removed saves/New World/DIM-1/forcedchunks.dat
Binary file not shown.
Binary file removed saves/New World/DIM1/data/villages_end.dat
Binary file not shown.
Binary file removed saves/New World/DIM1/forcedchunks.dat
Binary file not shown.
Binary file removed saves/New World/data/Mineshaft.dat
Binary file not shown.
Binary file removed saves/New World/data/villages.dat
Binary file not shown.
Binary file removed saves/New World/forcedchunks.dat
Binary file not shown.
Binary file removed saves/New World/level.dat
Binary file not shown.
Binary file removed saves/New World/level.dat_mcr
Binary file not shown.
Binary file removed saves/New World/level.dat_old
Binary file not shown.
Binary file not shown.
Binary file removed saves/New World/region/r.-1.0.mca
Binary file not shown.
Binary file removed saves/New World/region/r.0.0.mca
Binary file not shown.
Binary file removed saves/New World/session.lock
Binary file not shown.

This file was deleted.

83 changes: 63 additions & 20 deletions src/main/java/com/voxcrafterlp/statsaddon/StatsAddon.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.voxcrafterlp.statsaddon;

import com.google.common.collect.Lists;
import com.voxcrafterlp.statsaddon.events.*;
import com.voxcrafterlp.statsaddon.events.MessageReceiveEventHandler;
import com.voxcrafterlp.statsaddon.events.ServerMessageEvent;
import net.labymod.api.LabyModAPI;
import net.labymod.api.LabyModAddon;
import net.labymod.settings.elements.*;
import net.labymod.utils.Consumer;
import net.labymod.utils.Material;
import net.labymod.utils.ModColor;

import java.util.HashMap;
import java.util.List;
Expand All @@ -29,18 +31,17 @@ public class StatsAddon extends LabyModAddon {
public List<String> checkedPlayers;

private static StatsAddon statsAddon;
private boolean isPlayingCookies;
private String currentGamemode;
private List<String> playersJoined = Lists.newCopyOnWriteArrayList();

private Map<String, Boolean> enabledGamemods = new HashMap<>();

@Override
public void onEnable() {
statsAddon = this;
isPlayingCookies = false;
currentGamemode = null;

//EVENT REGISTRATION
//new PluginMessageEventHandler().register();
new MessageReceiveEventHandler().register();
new ServerMessageEvent().register();
System.out.println("LabyCookies enabled");
Expand All @@ -54,10 +55,19 @@ public void loadConfig() {
this.alertEnabled = !this.getConfig().has("alertEnabled") || this.getConfig().get("alertEnabled").getAsBoolean();
this.cooldown = this.getConfig().has("cooldown") ? this.getConfig().get("cooldown").getAsInt() : 1000;
this.warnLevel = this.getConfig().has("warnLevel") ? this.getConfig().get("warnLevel").getAsInt() : 100;

this.getGamemodes().forEach((string, material) -> {
if(enabledGamemods.containsKey(string))
enabledGamemods.replace(string, (!this.getConfig().has(string) || this.getConfig().get(string).getAsBoolean()));
else
enabledGamemods.put(string, (!this.getConfig().has(string) || this.getConfig().get(string).getAsBoolean()));
});
}

@Override
protected void fillSettings(List<SettingsElement> list) {
list.add(new HeaderElement(ModColor.cl('b') + "General settings"));

list.add(new BooleanElement("Enabled", new ControlElement.IconData(Material.LEVER), new Consumer<Boolean>() {
@Override
public void accept(Boolean accepted) {
Expand Down Expand Up @@ -94,30 +104,63 @@ public void accept(Boolean accepted) {
getConfig().addProperty("alertEnabled", accepted);
saveConfig();
}
}, this.enabled));

//======================================// Gamemodes
}, this.alertEnabled));


//Gamemodes
list.add(new HeaderElement(ModColor.cl('a') + "Enabled gamemodes"));

this.getGamemodes().forEach((string, material) -> {
list.add(new BooleanElement(string, new ControlElement.IconData(material), new Consumer<Boolean>() {
@Override
public void accept(Boolean enabled) {
if(enabledGamemods.containsKey(string))
enabledGamemods.replace(string, enabled);
else
enabledGamemods.put(string, enabled);
getConfig().addProperty(string, enabled);
saveConfig();
}
}, enabledGamemods.get(string)));
});
}

/*list.add(new BooleanElement("Cookies", new ControlElement.IconData(Material.COOKIE), new Consumer<Boolean>() {
@Override
public void accept(Boolean accepted) {
alertEnabled = accepted;
getConfig().addProperty("alertEnabled", accepted);
saveConfig();
}
}, this.enabled));*/
/**
* Fills the map with a list of all gamemodes which have stats enabled
* @return Filled map
*/
private Map<String, Material> getGamemodes() {
Map<String, Material> map = new HashMap<String, Material>();

map.put("Cookies", Material.COOKIE);
map.put("SkyWars", Material.GRASS);
map.put("BedWars", Material.BED);
map.put("Cores", Material.BEACON);
map.put("JumpLeague", Material.DIAMOND_BOOTS);
map.put("TTT", Material.STICK);
map.put("SpeedUHC", Material.GOLDEN_APPLE);
map.put("EnderGames", Material.ENDER_PEARL);
map.put("MasterBuilders", Material.IRON_PICKAXE);
map.put("SurvivalGames", Material.IRON_SWORD);
map.put("QuickSurvivalGames", Material.IRON_SWORD);

return map;
}

public static StatsAddon getStatsAddon() { return statsAddon; }
public static StatsAddon getInstance() { return statsAddon; }

public void setCurrentGamemode(String currentGamemode) { this.currentGamemode = currentGamemode; }

public String getCurrentGamemode() { return currentGamemode; }

@Override
public LabyModAPI getApi() { return super.getApi(); }

public boolean isPlayingCookies() { return isPlayingCookies; }
public List<String> getPlayersJoined() { return playersJoined; }

public void setPlayingCookies(boolean playingCookies) { isPlayingCookies = playingCookies; }
public Map<String, Boolean> getEnabledGamemods() { return enabledGamemods; }

public List<String> getPlayersJoined() { return playersJoined; }
public String getGamemodePrefix() { return "\u00A78[\u00A7b" + getCurrentGamemode() + "-Stats\u00A78] "; }

public String getPrefix() { return "\u00A78[\u00A7bLabyCookies\u00A78] "; }
public String getPrefix() { return "\u00A78[\u00A7bStatsAddon\u00A78] "; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import net.labymod.api.events.MessageReceiveEvent;
import net.labymod.main.LabyMod;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
* This file was created by VoxCrafter_LP & Lezurex!
Expand All @@ -23,23 +21,23 @@ public class MessageReceiveEventHandler {
private String lastPlayerName;

public void register() {
StatsAddon.getStatsAddon().getApi().getEventManager().register(new MessageReceiveEvent() {
StatsAddon.getInstance().getApi().getEventManager().register(new MessageReceiveEvent() {
@Override
public boolean onReceive(String formatted, String unFormatted) {

if(StatsAddon.getStatsAddon().isPlayingCookies() && unFormatted.contains("»") && !unFormatted.contains(Minecraft.getMinecraft().thePlayer.getGameProfile().getName())) {
if(StatsAddon.getInstance().getCurrentGamemode() != null && unFormatted.contains("»") && !unFormatted.contains(Minecraft.getMinecraft().thePlayer.getGameProfile().getName())) {
new Thread(() -> {
try {
Thread.sleep(StatsAddon.getStatsAddon().cooldown);
Thread.sleep(StatsAddon.getInstance().cooldown);
} catch (InterruptedException exception) {
exception.printStackTrace();
}

List<String> playerNames = Lists.newCopyOnWriteArrayList();
Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().forEach((loadedPlayer) -> {
if(!StatsAddon.getStatsAddon().getPlayersJoined().contains(loadedPlayer.getGameProfile().getName())) {
if(!StatsAddon.getInstance().getPlayersJoined().contains(loadedPlayer.getGameProfile().getName())) {
playerNames.add(loadedPlayer.getGameProfile().getName());
StatsAddon.getStatsAddon().getPlayersJoined().add(loadedPlayer.getGameProfile().getName());
StatsAddon.getInstance().getPlayersJoined().add(loadedPlayer.getGameProfile().getName());
}

});
Expand All @@ -48,7 +46,7 @@ public boolean onReceive(String formatted, String unFormatted) {

}).start();
}
if(StatsAddon.getStatsAddon().isPlayingCookies() && StatsAddon.getStatsAddon().enabled) {
if(StatsAddon.getInstance().getCurrentGamemode() != null && StatsAddon.getInstance().enabled) {
new Thread(() -> {
if(unFormatted.toLowerCase().contains("-=")) {
lastPlayerName = getNameFromStatsLine(unFormatted);
Expand All @@ -59,16 +57,16 @@ public boolean onReceive(String formatted, String unFormatted) {

if(!content[1].contains("-")) {
int rank = Integer.parseInt(content[1].replace("\u00A7e", "").replace(" ", "").replace(".", "").replace(",", "").replace("'", "").replace("\u00A7r", ""));
if(rank < StatsAddon.getStatsAddon().warnLevel) {
if(rank < StatsAddon.getInstance().warnLevel) {
try {
Thread.sleep(20);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
if(!lastPlayerName.equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getName())) {
LabyMod.getInstance().displayMessageInChat(StatsAddon.getStatsAddon().getPrefix() + "\u00A74Achtung! \u00A77Potentiell gef\u00E4hrlicher Gegner\u00A77!");
LabyMod.getInstance().displayMessageInChat(StatsAddon.getStatsAddon().getPrefix() + "\u00A77Platz \u00A7e#" + rank + " \u00A77Name\u00A78: \u00A7c" + lastPlayerName);
if(StatsAddon.getStatsAddon().alertEnabled) {
LabyMod.getInstance().displayMessageInChat(StatsAddon.getInstance().getGamemodePrefix() + "\u00A74Achtung! \u00A77Potentiell gef\u00E4hrlicher Gegner\u00A77!");
LabyMod.getInstance().displayMessageInChat(StatsAddon.getInstance().getGamemodePrefix() + "\u00A77Platz \u00A7e#" + rank + " \u00A77Name\u00A78: \u00A7c" + lastPlayerName);
if(StatsAddon.getInstance().alertEnabled) {
new Thread(() -> {
for (int i = 0; i < 5; i++) {
Minecraft.getMinecraft().thePlayer.playSound("note.pling", 1, 1);
Expand Down

This file was deleted.

Loading

0 comments on commit 773b9e6

Please sign in to comment.