Compare commits
2 Commits
53dbeff829
...
develop-de
| Author | SHA1 | Date | |
|---|---|---|---|
| aad1fcafa6 | |||
| 9fca7430a8 |
@@ -6,7 +6,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CraftAttackApi {
|
||||
@@ -26,8 +25,4 @@ public class CraftAttackApi {
|
||||
public static void withAuthorizationSecret(URIBuilder builder) {
|
||||
builder.addParameter("secret", apiSecret);
|
||||
}
|
||||
|
||||
public static void withAuthorizationHeader(HttpRequest.Builder builder) {
|
||||
builder.header("Authorization", apiSecret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.UUID;
|
||||
|
||||
public class CraftAttackReportRepository extends ReportRepository {
|
||||
public CraftAttackReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.VaroReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
||||
@@ -63,7 +64,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(VaroReportRepository.class)
|
||||
.createReport(reportRequest);
|
||||
|
||||
switch(createdReport.status()) {
|
||||
@@ -114,7 +115,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
public void queryReports(Player issuer) {
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(VaroReportRepository.class)
|
||||
.queryReports(issuer.getUniqueId());
|
||||
|
||||
if(userReports.status() != 200) {
|
||||
|
||||
@@ -38,8 +38,7 @@ public class Settings extends Appliance {
|
||||
BorderWarning,
|
||||
LocatorBar,
|
||||
InfoBars,
|
||||
CoordinateDisplay,
|
||||
Bloodmoon
|
||||
CoordinateDisplay
|
||||
}
|
||||
|
||||
public static Settings instance() {
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import net.kyori.adventure.resource.ResourcePackInfo;
|
||||
import net.kyori.adventure.resource.ResourcePackRequest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import spark.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
public class DeviceFingerprinting extends Appliance {
|
||||
public record PackInfo(@NotNull String url, @NotNull UUID uuid, @NotNull String hash) {
|
||||
private static final String failingUrl = "http://127.0.0.1:0";
|
||||
public PackInfo asFailing() {
|
||||
return new PackInfo(failingUrl, this.uuid, this.hash);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PackStatus {
|
||||
UNCACHED,
|
||||
CACHED,
|
||||
INVALID;
|
||||
|
||||
public static PackStatus fromBukkitStatus(PlayerResourcePackStatusEvent.Status status) {
|
||||
return switch(status) {
|
||||
case DISCARDED -> CACHED;
|
||||
case FAILED_DOWNLOAD -> UNCACHED;
|
||||
default -> INVALID;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlayerStatus {
|
||||
PREPARATION,
|
||||
TESTING,
|
||||
FINISHED,
|
||||
NEW
|
||||
}
|
||||
|
||||
private List<PackInfo> packs;
|
||||
private final Map<Player, FingerprintData> fingerprints = new WeakHashMap<>();
|
||||
private final UUID basePackId = UUID.randomUUID();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.packs = this.readPacksFromConfig();
|
||||
}
|
||||
|
||||
public void startFingerprinting(Player player) {
|
||||
this.fingerprints.put(player, FingerprintData.create(player));
|
||||
Main.logger().info(String.format("Sending base ressource-pack with id '%s' to '%s'%n", this.basePackId, player.getName()));
|
||||
this.sendPack(player, new PackInfo("http://localhost:8080/api/devicefingerprinting/base.zip", this.basePackId, "3296e8bdd30b4f7cffd11c780a1dc70da2948e71"));
|
||||
}
|
||||
|
||||
public void onPackUpdate(Player player, UUID packId, PlayerResourcePackStatusEvent.Status status) {
|
||||
if(!this.fingerprints.containsKey(player)) return;
|
||||
FingerprintData playerFingerprint = this.fingerprints.get(player);
|
||||
if(!playerFingerprint.isInTestingOrPreparation()) return;
|
||||
|
||||
if(packId.equals(this.basePackId)) {
|
||||
Main.logger().info(String.format("Base pack for '%s' updated: '%s'", player.getName(), status));
|
||||
|
||||
if(status != PlayerResourcePackStatusEvent.Status.ACCEPTED) return;
|
||||
Main.logger().info(String.format("Base pack loaded successfully, sending now all packs to '%s'...", player.getName()));
|
||||
playerFingerprint.setTesting();
|
||||
this.packs.forEach(pack -> this.sendPack(player, pack.asFailing()));
|
||||
return;
|
||||
}
|
||||
|
||||
PackInfo pack = this.packs.stream()
|
||||
.filter(packInfo -> Objects.equals(packInfo.uuid, packId))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
if(pack == null) return;
|
||||
int packIndex = this.packs.indexOf(pack);
|
||||
|
||||
List<PackStatus> pendingPacks = playerFingerprint.getPendingPacks();
|
||||
PackStatus newPackStatus = PackStatus.fromBukkitStatus(status);
|
||||
if(newPackStatus == PackStatus.INVALID) return;
|
||||
pendingPacks.set(packIndex, newPackStatus);
|
||||
|
||||
playerFingerprint.updateFingerprint();
|
||||
if(Objects.requireNonNull(playerFingerprint.getStatus()) == PlayerStatus.NEW) {
|
||||
Main.logger().info(String.format("Sending fingerprint packs to Player '%s', as it is a unseen Player!", player.getName()));
|
||||
this.sendNewFingerprint(player, Objects.requireNonNull(playerFingerprint.getFingerPrint()));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendNewFingerprint(Player player, long fingerprintId) {
|
||||
for (int i = 0; i < this.packs.size(); i++) {
|
||||
if ((fingerprintId & (1L << i)) != 0) {
|
||||
PackInfo pack = this.packs.get(i);
|
||||
this.sendPack(player, pack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPack(Player player, PackInfo pack) {
|
||||
player.sendResourcePacks(
|
||||
ResourcePackRequest.resourcePackRequest()
|
||||
.required(true)
|
||||
.packs(ResourcePackInfo.resourcePackInfo(pack.uuid, URI.create(pack.url), pack.hash))
|
||||
);
|
||||
}
|
||||
|
||||
private List<DeviceFingerprinting.PackInfo> readPacksFromConfig() {
|
||||
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/deviceFingerprinting/packs.json")))) {
|
||||
Type packListType = new TypeToken<List<DeviceFingerprinting.PackInfo>>(){}.getType();
|
||||
List<DeviceFingerprinting.PackInfo> packs = new Gson().fromJson(reader, packListType);
|
||||
if (packs.isEmpty()) throw new IllegalStateException("No resource packs found in packs.json.");
|
||||
return packs;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to parse packs.json.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
apiBuilder.rawGet(
|
||||
"base.zip",
|
||||
(request, response) -> this.servePack("base.zip", response)
|
||||
);
|
||||
|
||||
for(int i = 0; i < this.packs.size(); i++) {
|
||||
int packIndex = i;
|
||||
apiBuilder.rawGet(
|
||||
String.format("packs/%d", i),
|
||||
(request, response) -> this.servePack(String.valueOf(packIndex), response)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private Object servePack(String name, Response response) {
|
||||
try {
|
||||
String resourcePath = String.format("/deviceFingerprinting/packs/%s", name);
|
||||
var inputStream = Main.class.getResourceAsStream(resourcePath);
|
||||
|
||||
if (inputStream == null) {
|
||||
throw new IllegalStateException("Pack file not found: " + resourcePath);
|
||||
}
|
||||
|
||||
response.header("Content-Type", "application/zip");
|
||||
response.header("Content-Disposition", String.format("attachment; filename=\"pack-%s.zip\"", name));
|
||||
|
||||
var outputStream = response.raw().getOutputStream();
|
||||
inputStream.transferTo(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
return HttpServer.nothing;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(String.format("Failed to serve pack '%s'", name), e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<PackInfo> getPacks() {
|
||||
return this.packs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PlayerJoinListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
class FingerprintData {
|
||||
public final Player player;
|
||||
private DeviceFingerprinting.PlayerStatus status;
|
||||
private @Nullable Long fingerPrint;
|
||||
private final List<DeviceFingerprinting.PackStatus> pendingPacks;
|
||||
int packCount = Main.instance().getAppliance(DeviceFingerprinting.class).getPacks().size();
|
||||
|
||||
private FingerprintData(Player player) {
|
||||
this.player = player;
|
||||
this.status = DeviceFingerprinting.PlayerStatus.PREPARATION;
|
||||
this.fingerPrint = null;
|
||||
this.pendingPacks = Arrays.asList(new DeviceFingerprinting.PackStatus[this.packCount]);
|
||||
}
|
||||
|
||||
public static FingerprintData create(Player player) {
|
||||
return new FingerprintData(player);
|
||||
}
|
||||
|
||||
public void setTesting() {
|
||||
this.status = DeviceFingerprinting.PlayerStatus.TESTING;
|
||||
}
|
||||
|
||||
public void updateFingerprint() {
|
||||
long fingerPrint = 0;
|
||||
for (int i = 0; i < this.pendingPacks.size(); i++) {
|
||||
var status = this.pendingPacks.get(i);
|
||||
if(status == null) return;
|
||||
switch (status) {
|
||||
case CACHED:
|
||||
fingerPrint |= 1L << i;
|
||||
break;
|
||||
case UNCACHED:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(fingerPrint == 0) {
|
||||
this.status = DeviceFingerprinting.PlayerStatus.NEW;
|
||||
this.fingerPrint = this.createNewFingerprint();
|
||||
Main.logger().info(String.format("Player %s's was marked as a new Player!", this.player.getName()));
|
||||
} else {
|
||||
this.status = DeviceFingerprinting.PlayerStatus.FINISHED;
|
||||
this.fingerPrint = fingerPrint;
|
||||
}
|
||||
|
||||
Main.logger().info(String.format("Player %s's fingerprint is '%s'", this.player.getName(), fingerPrint));
|
||||
}
|
||||
|
||||
private long createNewFingerprint() {
|
||||
long id = 0;
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < this.packCount / 2; i++) {
|
||||
while (true) {
|
||||
int bitIndex = random.nextInt(this.packCount);
|
||||
if ((id & (1L << bitIndex)) == 0) {
|
||||
id |= 1L << bitIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<DeviceFingerprinting.PackStatus> getPendingPacks() {
|
||||
return this.pendingPacks;
|
||||
}
|
||||
|
||||
public DeviceFingerprinting.PlayerStatus getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public @Nullable Long getFingerPrint() {
|
||||
return this.fingerPrint;
|
||||
}
|
||||
|
||||
public boolean isInTestingOrPreparation() {
|
||||
return this.status == DeviceFingerprinting.PlayerStatus.TESTING || this.status == DeviceFingerprinting.PlayerStatus.PREPARATION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||
|
||||
class PlayerJoinListener extends ApplianceListener<DeviceFingerprinting> {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
this.getAppliance().startFingerprinting(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResourcePackEvent(PlayerResourcePackStatusEvent event) {
|
||||
this.getAppliance().onPackUpdate(
|
||||
event.getPlayer(),
|
||||
event.getID(),
|
||||
event.getStatus()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,16 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
class PlayerLimiterListener extends ApplianceListener<PlayerLimit> {
|
||||
@EventHandler
|
||||
public void onLogin(AsyncPlayerPreLoginEvent playerPreLoginEvent) {
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit()) {
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit())
|
||||
playerPreLoginEvent.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
common/src/main/resources/deviceFingerprinting/README.md
Normal file
5
common/src/main/resources/deviceFingerprinting/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
## Files originally from "TrackPack"
|
||||
https://github.com/ALaggyDev/TrackPack/blob/main/README.md
|
||||
|
||||
|
||||
Discovered by: [Laggy](https://github.com/ALaggyDev/) and [NikOverflow](https://github.com/NikOverflow)
|
||||
33
common/src/main/resources/deviceFingerprinting/gen_packs.py
Normal file
33
common/src/main/resources/deviceFingerprinting/gen_packs.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import zipfile
|
||||
import hashlib
|
||||
import uuid
|
||||
import json
|
||||
|
||||
SERVER_URL = "http://localhost:8080/api/devicefingerprinting"
|
||||
packs = []
|
||||
|
||||
def file_sha1(path):
|
||||
h = hashlib.sha1()
|
||||
with open(path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(8192), b""):
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
|
||||
for i in range(0, 24):
|
||||
path = f"packs/{i}"
|
||||
|
||||
with zipfile.ZipFile(path, mode="w") as zf:
|
||||
zf.writestr(
|
||||
"pack.mcmeta",
|
||||
'{"pack":{"pack_format":22,"supported_formats":[22,1000],"description":"pack ' + str(i) + '"}}',
|
||||
)
|
||||
|
||||
hash = file_sha1(path)
|
||||
packs.append({
|
||||
"url": f"{SERVER_URL}/packs/{i}",
|
||||
"uuid": str(uuid.uuid4()),
|
||||
"hash": hash
|
||||
})
|
||||
|
||||
with open("packs.json", "w") as f:
|
||||
json.dump(packs, f, indent=4)
|
||||
122
common/src/main/resources/deviceFingerprinting/packs.json
Normal file
122
common/src/main/resources/deviceFingerprinting/packs.json
Normal file
@@ -0,0 +1,122 @@
|
||||
[
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/0",
|
||||
"uuid": "b35f6e2f-1b50-4493-85be-fb18bd90f9bb",
|
||||
"hash": "7a39af839ea6484431f7b707759546bea991d435"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/1",
|
||||
"uuid": "71095b62-d5ef-4ab2-ba3b-3c1b403f5e34",
|
||||
"hash": "a9192ee73df1c5cff2c188fac6e9e638a1e7b6ce"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/2",
|
||||
"uuid": "a4dba0a2-f8f2-4a81-bbb2-a9a818820330",
|
||||
"hash": "6b85b0eb54865dae70bbda89746d83717dc2a214"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/3",
|
||||
"uuid": "79fa2dc4-8c84-45fc-a09f-d89906f0d900",
|
||||
"hash": "c7abf7a316f7e8c98985e8317a8b649e824e9f79"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/4",
|
||||
"uuid": "15702c9b-a22b-426d-b48a-3d65b0368e9a",
|
||||
"hash": "10cd0e2c46f192deb87ac75c149827d44a713017"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/5",
|
||||
"uuid": "3d702d41-8e2f-4920-8dd0-1fd2146da9fb",
|
||||
"hash": "8ad517d259e800b88a38ff00ee6721d5656822f2"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/6",
|
||||
"uuid": "c20a2e47-ef43-49da-a80d-adf238df3695",
|
||||
"hash": "798677405a4fd678892e1cf55585c8c91f82e1e2"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/7",
|
||||
"uuid": "7ce51b81-1263-4919-9f4e-bb749ffe6e2e",
|
||||
"hash": "af473b8eb7572f35d307bede5f2e20f263c0d804"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/8",
|
||||
"uuid": "0c70d586-fe48-4ffc-86b0-6b9ec3bfe045",
|
||||
"hash": "2fb698ff88f2436637641f3b2e6792201feb5144"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/9",
|
||||
"uuid": "c7af75a8-0b72-495d-a0ff-c1c40e229c13",
|
||||
"hash": "cf660460798eecf451d639873cc1fedc4661db1b"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/10",
|
||||
"uuid": "248dbce6-4b2a-44b5-b038-8d718b0ced99",
|
||||
"hash": "a8ebe708d0f3747c76e4e5e68db5dcb561922706"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/11",
|
||||
"uuid": "10979174-cb02-40eb-a754-275551ad608d",
|
||||
"hash": "54961b48db1582a1a0981c8cc9be5ae0f3122cf3"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/12",
|
||||
"uuid": "a361cfa7-674c-4493-a4cf-4baff851f276",
|
||||
"hash": "013719dc8da79c96b45a1c5319c20bffe1a56cc9"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/13",
|
||||
"uuid": "24b39bdb-ada9-40ec-9e3a-132c74b81dc6",
|
||||
"hash": "206898c6b6600d2648b2d79c61fc6255b19587d9"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/14",
|
||||
"uuid": "158fc5b4-be2c-4f7a-98cb-af5993adcc90",
|
||||
"hash": "061b266a7c526fb3a3152a4ea70ca5592e0b503c"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/15",
|
||||
"uuid": "4f9097a7-be02-48ad-919c-f292307f8490",
|
||||
"hash": "45a667a0fe06246defabca14ef1271fb6db5a1ac"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/16",
|
||||
"uuid": "3ce31e60-7e8a-4fb1-8c6d-da9065bea798",
|
||||
"hash": "75bb12e46203d49e89aa9a826d267552372758bc"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/17",
|
||||
"uuid": "cd978e5c-3de0-4ada-8ec5-3a88a305eec6",
|
||||
"hash": "5b20261f7be03e83e9c52307f1408b0c5e58358c"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/18",
|
||||
"uuid": "75001e58-3999-4779-a1d1-43ab161770ce",
|
||||
"hash": "544420cffb6c17113c06fb49eeba892c208719d3"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/19",
|
||||
"uuid": "6a7005a9-c2ca-476d-9a12-07d120ee121a",
|
||||
"hash": "fcc066a4d3193b60b102e3d906ad8dc0b0fcf65b"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/20",
|
||||
"uuid": "521c0d84-d82e-49ef-b096-d9b90f15aa19",
|
||||
"hash": "4545835983ec7f07d02675a69181a80dc396f038"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/21",
|
||||
"uuid": "c1b590c5-43fc-41e3-83c0-47f35b14f845",
|
||||
"hash": "8d4c670eaefc0482734e839b72758226dde13bc3"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/22",
|
||||
"uuid": "43958a18-c087-4f2b-a6ea-066231606eb1",
|
||||
"hash": "004282602f7bdbb7cd7724f23aae23876f224092"
|
||||
},
|
||||
{
|
||||
"url": "http://localhost:8080/api/devicefingerprinting/packs/23",
|
||||
"uuid": "4b91ac81-9de4-4c2b-a876-47e621496d10",
|
||||
"hash": "dae68eae109e08ea4c4c943905502eb331939f64"
|
||||
}
|
||||
]
|
||||
1
common/src/main/resources/deviceFingerprinting/packs/.gitignore
vendored
Normal file
1
common/src/main/resources/deviceFingerprinting/packs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!base.zip
|
||||
BIN
common/src/main/resources/deviceFingerprinting/packs/0
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/0
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/1
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/1
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/10
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/10
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/11
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/11
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/12
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/12
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/13
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/13
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/14
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/14
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/15
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/15
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/16
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/16
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/17
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/17
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/18
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/18
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/19
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/19
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/2
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/2
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/20
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/20
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/21
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/21
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/22
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/22
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/23
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/23
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/3
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/3
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/4
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/4
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/5
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/5
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/6
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/6
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/7
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/7
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/8
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/8
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/9
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/9
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/base.zip
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/base.zip
Normal file
Binary file not shown.
@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import spark.Request;
|
||||
import spark.Spark;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -43,12 +44,16 @@ public class HttpServer {
|
||||
this.applianceName = appliance.getClass().getSimpleName().toLowerCase();
|
||||
}
|
||||
|
||||
public void rawGet(String path, BiFunction<Request, spark.Response, Object> onCall) {
|
||||
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
|
||||
}
|
||||
|
||||
public void get(String path, Function<Request, Object> onCall) {
|
||||
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
|
||||
}
|
||||
|
||||
public void rawPost(String path, Function<Request, Object> onCall) {
|
||||
Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
|
||||
public void rawPost(String path, BiFunction<Request, spark.Response, Object> onCall) {
|
||||
Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
|
||||
}
|
||||
|
||||
public <TRequest> void post(String path, Class<TRequest> clazz, RequestProvider<TRequest, Request, Object> onCall) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
|
||||
public class FeedbackRepository extends HttpRepository {
|
||||
public FeedbackRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
}
|
||||
|
||||
public record Request(String event, List<UUID> users) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.UUID;
|
||||
|
||||
public class WhitelistRepository extends HttpRepository {
|
||||
public WhitelistRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
}
|
||||
|
||||
public record UserData(
|
||||
@@ -21,12 +21,10 @@ public class WhitelistRepository extends HttpRepository {
|
||||
) {
|
||||
}
|
||||
|
||||
private record UserQuery(UUID uuid) {}
|
||||
|
||||
public ReqResp<UserData> getUserData(UUID userId) {
|
||||
return this.post(
|
||||
"player",
|
||||
new UserQuery(userId),
|
||||
return this.get(
|
||||
"user",
|
||||
parameters -> parameters.addParameter("uuid", userId.toString()),
|
||||
UserData.class
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.commands.BloodmoonCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonEntityDamageListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonMonsterDeathListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonPlayerJoinListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonTimeListener;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Bloodmoon extends Appliance {
|
||||
// für alle Dimensionen? einstellbar machen?
|
||||
|
||||
public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.of(
|
||||
EntityType.ZOMBIE, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
),
|
||||
EntityType.SKELETON, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 3.5, 1)
|
||||
),
|
||||
EntityType.SPIDER, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.POISON, 4, 1),
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.NAUSEA, 6, 10)
|
||||
),
|
||||
EntityType.CREEPER, Set.of(
|
||||
new MobEffect.LightningMobEffect()
|
||||
),
|
||||
EntityType.HUSK, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
),
|
||||
EntityType.DROWNED, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
),
|
||||
EntityType.WITCH, Set.of(),
|
||||
EntityType.ZOMBIE_VILLAGER, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
),
|
||||
EntityType.PHANTOM, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.LEVITATION, 1.5, 3)
|
||||
),
|
||||
EntityType.ENDERMAN, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 2.5, 2)
|
||||
)
|
||||
);
|
||||
public final int expMultiplier = 4;
|
||||
public final double mobDamageMultipier = 2;
|
||||
public final double mobHealthMultiplier = 3;
|
||||
|
||||
private boolean isActive = false;
|
||||
private final BossBar bossBar = BossBar.bossBar(
|
||||
Component.text("Blutmond", NamedTextColor.DARK_RED),
|
||||
1f,
|
||||
BossBar.Color.RED,
|
||||
BossBar.Overlay.NOTCHED_12,
|
||||
Set.of(BossBar.Flag.CREATE_WORLD_FOG, BossBar.Flag.DARKEN_SCREEN)
|
||||
);
|
||||
private final boolean hordesEnabled = true;
|
||||
private final int hordeSpawnRateTicks = 800;
|
||||
private final int hordeSpawnRateVariationTicks = 800;
|
||||
private final int hordeMinPopulation = 3;
|
||||
private final int hordeMaxPopulation = 10;
|
||||
private final int hordeSpawnDistance = 10;
|
||||
private final List<EntityType> hordeMobList = List.of(
|
||||
EntityType.ZOMBIE,
|
||||
EntityType.SKELETON,
|
||||
EntityType.SPIDER
|
||||
);
|
||||
private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new HashMap<>();
|
||||
public final int bloodmoonLength = 12000;
|
||||
public final int ticksPerDay = 24000;
|
||||
private final int bloodmoonFreeDaysAtStart = 3;
|
||||
private final int bloodmoonStartTime = 12000;
|
||||
private final int bloodmoonDayInterval = 2;
|
||||
private final int minBonusDrops = 1;
|
||||
private final int maxBonusDrops = 4;
|
||||
private final Map<ItemStack, Integer> bonusDropWeightMap = Map.of(
|
||||
new ItemStack(Material.IRON_INGOT, 5), 10,
|
||||
new ItemStack(Material.GOLD_INGOT, 2), 5,
|
||||
new ItemStack(Material.DIAMOND, 1), 1,
|
||||
new ItemStack(Material.IRON_BLOCK, 1), 5,
|
||||
new ItemStack(Material.GOLD_BLOCK, 1), 2
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(BloodmoonSetting.class);
|
||||
}
|
||||
|
||||
public boolean bloodmoonIsActive() {
|
||||
return this.isActive;
|
||||
}
|
||||
|
||||
public void startBloodmoon() {
|
||||
this.isActive = true;
|
||||
Bukkit.getOnlinePlayers().forEach(this::addPlayerToBossBar);
|
||||
this.startHordeSpawning(this.getRandomHordeSpawnDelay());
|
||||
this.sendStartMessages();
|
||||
}
|
||||
|
||||
public void stopBloodmoon() {
|
||||
this.isActive = false;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.hideBossBar(this.bossBar));
|
||||
this.sendStopMessages();
|
||||
}
|
||||
|
||||
public boolean isStartTick(long tick) {
|
||||
long day = tick / this.ticksPerDay;
|
||||
if(day % this.bloodmoonDayInterval != 0 || day - this.bloodmoonFreeDaysAtStart <= 0) return false;
|
||||
long time = tick - (day * this.ticksPerDay);
|
||||
return time == this.bloodmoonStartTime;
|
||||
}
|
||||
|
||||
private int getRandomHordeSpawnDelay() {
|
||||
return this.hordeSpawnRateTicks + ThreadLocalRandom.current().nextInt(this.hordeSpawnRateVariationTicks);
|
||||
}
|
||||
|
||||
private void startHordeSpawning(int delay) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> this.startHordeSpawning(delay, player));
|
||||
}
|
||||
|
||||
private void startHordeSpawning(int delay, Player player) {
|
||||
@Nullable BukkitTask task = this.hordeSpawnTasks.get(player);
|
||||
if(task != null) task.cancel();
|
||||
task = Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> {
|
||||
if(!this.bloodmoonIsActive()) return;
|
||||
this.spawnRandomHorde();
|
||||
this.startHordeSpawning(this.getRandomHordeSpawnDelay(), player);
|
||||
},
|
||||
delay
|
||||
);
|
||||
this.hordeSpawnTasks.put(player, task);
|
||||
}
|
||||
|
||||
public void addPlayerToBossBar(Player player) {
|
||||
if(!this.getBloodmoonSetting(player)) return;
|
||||
player.showBossBar(this.bossBar);
|
||||
}
|
||||
|
||||
public boolean isAffectedMob(Entity entity) {
|
||||
return this.affectedMobEffectMap.containsKey(entity.getType());
|
||||
}
|
||||
|
||||
public boolean getBloodmoonSetting(Player player) {
|
||||
return Settings.instance().getSetting(
|
||||
player,
|
||||
Settings.Key.Bloodmoon,
|
||||
Boolean.class
|
||||
);
|
||||
}
|
||||
|
||||
public void spawnRandomHorde() {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) return;
|
||||
if(!this.hordesEnabled) return;
|
||||
List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(this::getBloodmoonSetting)
|
||||
.filter(player -> player.getGameMode().equals(GameMode.SURVIVAL))
|
||||
.toList();
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size()));
|
||||
EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size()));
|
||||
int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
|
||||
this.spawnHorde(player, hordeSize, hordeEntityType);
|
||||
}
|
||||
|
||||
public void sendWarningMessage(Player p) {
|
||||
p.sendMessage(Component.text("Der Blutmond waltet in diesem Augenblick!", NamedTextColor.RED));
|
||||
}
|
||||
|
||||
public void sendAnnouncementMessages() {
|
||||
this.sendMessage(Component.text("Der Blutmond naht; morgen wird er den Himmel beherrschen", NamedTextColor.GOLD));
|
||||
}
|
||||
|
||||
public void sendPreStartMessages() {
|
||||
this.sendMessage(Component.text("Der Himmel ist heute Nacht ungewöhnlich düster", NamedTextColor.DARK_PURPLE));
|
||||
}
|
||||
|
||||
private void spawnHorde(Player player, int size, EntityType type) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
double spawnRadiant = ThreadLocalRandom.current().nextDouble(0, 2*Math.PI);
|
||||
Location mobSpawnLocation = player.getLocation().add(
|
||||
Math.sin(spawnRadiant)*this.hordeSpawnDistance,
|
||||
0,
|
||||
Math.cos(spawnRadiant)*this.hordeSpawnDistance
|
||||
);
|
||||
mobSpawnLocation.setY(player.getWorld().getHighestBlockYAt(mobSpawnLocation) + 1);
|
||||
player.getWorld().spawnEntity(mobSpawnLocation, type);
|
||||
player.getWorld().strikeLightningEffect(mobSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getRandomBonusDrops() {
|
||||
int itemCount = ThreadLocalRandom.current().nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
|
||||
List<ItemStack> result = new ArrayList<>();
|
||||
for(int i = 0; i < itemCount; i++) {
|
||||
result.add(this.getRandomBonusDrop());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ItemStack getRandomBonusDrop() {
|
||||
int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum();
|
||||
int randomInt = ThreadLocalRandom.current().nextInt(0, totalWeight + 1);
|
||||
int cumulativeWeight = 0;
|
||||
for(Map.Entry<ItemStack, Integer> entry : this.bonusDropWeightMap.entrySet()) {
|
||||
cumulativeWeight += entry.getValue();
|
||||
if(randomInt <= cumulativeWeight) return entry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendMessage(Component message) {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) return;
|
||||
List<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(this::getBloodmoonSetting)
|
||||
.toList();
|
||||
onlinePlayers.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
private void sendStartMessages() {
|
||||
this.sendMessage(
|
||||
Component.empty()
|
||||
.append(Component.text("Der Blutmond ist über uns", NamedTextColor.DARK_RED, TextDecoration.BOLD))
|
||||
.appendNewline()
|
||||
.append(Component.text("Erfahrung vervielfacht sich und Mobs lassen reichere Beute fallen", NamedTextColor.RED))
|
||||
.appendNewline()
|
||||
.append(Component.text("Mobs sind erstarkt und belegen dich mit finsteren Debuffs", NamedTextColor.RED))
|
||||
);
|
||||
}
|
||||
|
||||
private void sendStopMessages() {
|
||||
this.sendMessage(Component.text("Der Blutmond weicht...", NamedTextColor.GREEN, TextDecoration.BOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new BloodmoonMonsterDeathListener(),
|
||||
new BloodmoonPlayerJoinListener(),
|
||||
new BloodmoonEntityDamageListener(),
|
||||
new BloodmoonTimeListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(
|
||||
new BloodmoonCommand()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.CategorizedSetting;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.SettingCategory;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.util.world.InteractSounds;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class BloodmoonSetting extends BoolSetting implements CategorizedSetting {
|
||||
public BloodmoonSetting() {
|
||||
super(Settings.Key.Bloodmoon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingCategory category() {
|
||||
return SettingCategory.Misc; // TODO: mehr als 8 bug fixen
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String title() {
|
||||
return "Blutmond";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String description() {
|
||||
return "Kämpfe während dem Blutmond gegen stärkere Monster mit besseren Drops. Kann nicht während dem Blutmond geändert werden!";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Material icon() {
|
||||
return Material.CLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Settings deaktivierbar machen
|
||||
|
||||
@Override
|
||||
protected void change(Player player, ClickType clickType) {
|
||||
if(Main.instance().getAppliance(Bloodmoon.class).bloodmoonIsActive()) {
|
||||
InteractSounds.of(player).delete();
|
||||
player.sendMessage(Component.text("Während dem Blutmond kann diese Einstellung nicht geändert werden!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
super.change(player, clickType);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public abstract class MobEffect {
|
||||
public abstract void apply(Player p);
|
||||
|
||||
public static class PotionMobEffect extends MobEffect {
|
||||
private final PotionEffect effect;
|
||||
public PotionMobEffect(PotionEffectType type, double seconds, int amplifier) {
|
||||
this.effect = new PotionEffect(type, (int) (seconds * Ticks.TICKS_PER_SECOND), amplifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Player p) {
|
||||
p.addPotionEffect(this.effect);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LightningMobEffect extends MobEffect {
|
||||
@Override
|
||||
public void apply(Player p) {
|
||||
p.getWorld().strikeLightning(p.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.commands;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
|
||||
public BloodmoonCommand() {
|
||||
super("bloodmoon");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
if(args.length == 0) {
|
||||
sender.sendMessage("Bloodmoon is currently %s.".formatted(this.getAppliance().bloodmoonIsActive() ? "active" : "inactive"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch(args[0]) {
|
||||
case "start": {
|
||||
this.getAppliance().startBloodmoon();
|
||||
sender.sendMessage("Started bloodmoon.");
|
||||
break;
|
||||
}
|
||||
case "stop": {
|
||||
this.getAppliance().stopBloodmoon();
|
||||
sender.sendMessage("Stopped bloodmoon.");
|
||||
break;
|
||||
}
|
||||
default: throw new Error("No such option: '%s' !".formatted(args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(args.length == 1) return List.of("start", "stop");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class BloodmoonEntityDamageListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
Entity damagerEntity = event.getDamager();
|
||||
if(damagerEntity instanceof Projectile projectile) {
|
||||
if(!(projectile.getShooter() instanceof Entity shooter)) return;
|
||||
damagerEntity = shooter;
|
||||
}
|
||||
if(!(damagerEntity instanceof LivingEntity damager && event.getEntity() instanceof LivingEntity receiver)) return;
|
||||
if(event.getFinalDamage() == 0) return;
|
||||
|
||||
if(this.getAppliance().isAffectedMob(damager) && receiver instanceof Player player) {
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
event.setDamage(event.getDamage() * this.getAppliance().mobDamageMultipier);
|
||||
this.getAppliance().affectedMobEffectMap.get(damager.getType()).forEach(mobEffect -> mobEffect.apply(player));
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isAffectedMob(receiver) && damager instanceof Player player) {
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
event.setDamage(event.getDamage() / this.getAppliance().mobHealthMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
public class BloodmoonMonsterDeathListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onMonsterDeath(EntityDeathEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
if(!(event.getDamageSource().getCausingEntity() instanceof Player player)) return;
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
LivingEntity entity = event.getEntity();
|
||||
if(!this.getAppliance().isAffectedMob(entity)) return;
|
||||
|
||||
event.setDroppedExp(event.getDroppedExp() * this.getAppliance().expMultiplier);
|
||||
event.getDrops().addAll(this.getAppliance().getRandomBonusDrops());
|
||||
entity.getWorld().strikeLightningEffect(entity.getLocation());
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class BloodmoonPlayerJoinListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
this.getAppliance().addPlayerToBossBar(event.getPlayer());
|
||||
this.getAppliance().sendWarningMessage(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class BloodmoonTimeListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onServerTick(ServerTickStartEvent event) {
|
||||
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime())) {
|
||||
this.getAppliance().startBloodmoon();
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() - this.getAppliance().bloodmoonLength)) {
|
||||
this.getAppliance().stopBloodmoon();
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() + this.getAppliance().ticksPerDay)) {
|
||||
this.getAppliance().sendAnnouncementMessages();
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() + 1000)) {
|
||||
this.getAppliance().sendPreStartMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.ironGolemAnimation;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class IronGolemAnimation extends Appliance {
|
||||
record BlockChange(Block original, BlockData fakeBlock) {}
|
||||
|
||||
public void onGolemSpawn(IronGolem golem) {
|
||||
this.modifyGolem(golem, false);
|
||||
Location golemLocation = golem.getLocation();
|
||||
|
||||
BlockData bodyBlockData = Bukkit.createBlockData(Material.IRON_BLOCK);
|
||||
BlockData headBlockData = Bukkit.createBlockData(
|
||||
Material.CARVED_PUMPKIN,
|
||||
blockData -> ((Directional) blockData).setFacing(golem.getFacing())
|
||||
);
|
||||
Vector facingVector = golem.getFacing().getDirection().rotateAroundY(Math.toRadians(90));
|
||||
Block golemCenterBlock = golemLocation.getBlock().getRelative(BlockFace.UP);
|
||||
|
||||
List<BlockChange> buildBlocks = List.of(
|
||||
new BlockChange(golemCenterBlock.getRelative(BlockFace.DOWN), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock, bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getLocation().add(facingVector).getBlock(), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getLocation().add(facingVector.multiply(-1)).getBlock(), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getRelative(BlockFace.UP), headBlockData)
|
||||
);
|
||||
|
||||
Collection<Player> viewers = golemLocation.getNearbyPlayers(golemLocation.getWorld().getViewDistance() * 16);
|
||||
BiConsumer<Location, BlockData> changeBlockForViewers = (location, blockData) -> {
|
||||
viewers.forEach(player -> player.sendBlockChange(location, blockData));
|
||||
golem.getWorld().playSound(
|
||||
location,
|
||||
blockData.getSoundGroup().getPlaceSound(),
|
||||
SoundCategory.BLOCKS,
|
||||
1f,
|
||||
1f
|
||||
);
|
||||
};
|
||||
for(int i = 0; i < buildBlocks.size(); i++) {
|
||||
BlockChange blockChange = buildBlocks.get(i);
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> changeBlockForViewers.accept(blockChange.original.getLocation(), blockChange.fakeBlock),
|
||||
6L * i
|
||||
);
|
||||
}
|
||||
|
||||
Consumer<List<BlockChange>> restoreBlockChanges = (blocks) -> {
|
||||
buildBlocks.forEach((blockChange) -> changeBlockForViewers.accept(
|
||||
blockChange.original().getLocation(),
|
||||
blockChange.original.getBlockData()
|
||||
));
|
||||
|
||||
this.modifyGolem(golem, true);
|
||||
this.spawnEffect(buildBlocks);
|
||||
};
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> restoreBlockChanges.accept(buildBlocks),
|
||||
6L * buildBlocks.size() + 2
|
||||
);
|
||||
}
|
||||
|
||||
private void spawnEffect(List<BlockChange> buildBlocks) {
|
||||
buildBlocks.forEach((blockChange) -> {
|
||||
World world = blockChange.original.getLocation().getWorld();
|
||||
world.spawnParticle(
|
||||
Particle.BLOCK,
|
||||
blockChange.original.getLocation().add(0.5, 0.5, 0.5),
|
||||
50,
|
||||
blockChange.fakeBlock
|
||||
);
|
||||
world.playSound(
|
||||
blockChange.original.getLocation(),
|
||||
blockChange.fakeBlock.getSoundGroup().getBreakSound(),
|
||||
SoundCategory.BLOCKS,
|
||||
1f,
|
||||
1f
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public void modifyGolem(IronGolem golem, boolean setVisible) {
|
||||
golem.setInvisible(!setVisible);
|
||||
golem.setInvulnerable(!setVisible);
|
||||
golem.setAI(setVisible);
|
||||
golem.setGravity(setVisible);
|
||||
golem.setCollidable(setVisible);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new NaturalIronGolemSpawnEvent()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.ironGolemAnimation;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
class NaturalIronGolemSpawnEvent extends ApplianceListener<IronGolemAnimation> {
|
||||
@EventHandler
|
||||
public void onGolemSpawn(CreatureSpawnEvent event) {
|
||||
if(!(event.getEntity() instanceof IronGolem golem)) return;
|
||||
if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE) return;
|
||||
this.getAppliance().onGolemSpawn(golem);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
class KeepRecoveryCompassOnDeathListener extends ApplianceListener<RecoveryCompass> {
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
ItemStack source = event.getDrops().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getType() == Material.RECOVERY_COMPASS)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (source == null) return;
|
||||
|
||||
if (source.getAmount() > 1) {
|
||||
source.setAmount(source.getAmount() - 1);
|
||||
} else {
|
||||
event.getDrops().remove(source);
|
||||
}
|
||||
|
||||
ItemStack kept = source.clone();
|
||||
kept.setAmount(1);
|
||||
event.getItemsToKeep().add(kept);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
class PlayerFirstJoinCompassGift extends ApplianceListener<RecoveryCompass> {
|
||||
private final NamespacedKey alreadyGiftedKey = new NamespacedKey(this.getClass().getSimpleName().toLowerCase(), "alreadyGifted".toLowerCase());
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PersistentDataContainer container = player.getPersistentDataContainer();
|
||||
if(container.has(alreadyGiftedKey)) return;
|
||||
player.getInventory().addItem(ItemStack.of(Material.RECOVERY_COMPASS));
|
||||
container.set(alreadyGiftedKey, PersistentDataType.BOOLEAN, true);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecoveryCompass extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PlayerFirstJoinCompassGift(),
|
||||
new KeepRecoveryCompassOnDeathListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class Whitelist extends Appliance {
|
||||
);
|
||||
|
||||
if(response.status() != HttpStatus.OK)
|
||||
throw new IllegalStateException(String.format("Unwanted response %d!", response.status()));
|
||||
throw new IllegalStateException(String.format("Http Reponse %d", response.status()));
|
||||
|
||||
return response.data();
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.phantomReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PhantomReducer extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PhantomSpawnListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.phantomReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.Phantom;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
class PhantomSpawnListener extends ApplianceListener<PhantomReducer> {
|
||||
@EventHandler
|
||||
public void onPhantomSpawn(CreatureSpawnEvent event) {
|
||||
if(!(event.getEntity() instanceof Phantom)) return;
|
||||
if(ThreadLocalRandom.current().nextDouble() > 0.8) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
tasks.register('deployVaroPlugin', Copy) {
|
||||
dependsOn ":varo:shadowJar"
|
||||
from { project(":varo").shadowJar.archivePath }
|
||||
into file('path') // path to plugins folder
|
||||
rename { fileName -> "varo.jar" }
|
||||
}
|
||||
|
||||
tasks.register("uploadVaroPlugin") {
|
||||
dependsOn(":varo:shadowJar")
|
||||
|
||||
doLast {
|
||||
def jarFile = project(":varo").tasks.named("shadowJar").get().outputs.files.singleFile
|
||||
exec {
|
||||
commandLine "scp", "-4", "-P", "22", jarFile.absolutePath, "user@host:path/varo.jar"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('deployCraftAttackPlugin', Copy) {
|
||||
dependsOn ":craftattack:shadowJar"
|
||||
from { project(":craftattack").shadowJar.archivePath }
|
||||
into file('path') // path to plugins folder
|
||||
rename { fileName -> "craftattack.jar" }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.player.PlayerGriefListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AntiGrief extends Appliance {
|
||||
private final Map<Block, UUID> blockRegistry = new HashMap<>();
|
||||
|
||||
public void addTracking(Block block, UUID player) {
|
||||
this.blockRegistry.put(block, player);
|
||||
block.getLocation().getWorld().spawn(block.getLocation(), ItemDisplay.class, itemDisplay -> {
|
||||
itemDisplay.setItemStack(ItemStack.of(Material.FIRE_CHARGE));
|
||||
itemDisplay.teleport(block.getLocation().add(0.5, 0.5, 0.5));
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable UUID getTracked(Block block) {
|
||||
return this.blockRegistry.get(block);
|
||||
}
|
||||
|
||||
public void addDestroyed(Block block, UUID player) {
|
||||
block.getLocation().getWorld().spawn(block.getLocation().add(0.5, 0.5, 0.5), BlockDisplay.class, blockDisplay -> {
|
||||
blockDisplay.setBlock(Material.GOLD_BLOCK.createBlockData());
|
||||
|
||||
Transformation transformation = blockDisplay.getTransformation();
|
||||
transformation.getScale().set(0.3);
|
||||
blockDisplay.setTransformation(transformation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(new PlayerGriefListener());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.player;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.AntiGrief;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerGriefListener extends ApplianceListener<AntiGrief> {
|
||||
@EventHandler
|
||||
public void onIgnite(BlockIgniteEvent event) {
|
||||
Bukkit.broadcast(Component.text(event.getCause().toString()));
|
||||
switch(event.getCause()) {
|
||||
case LAVA:
|
||||
case SPREAD:
|
||||
case EXPLOSION:
|
||||
if(event.getIgnitingBlock() == null) return;
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getIgnitingBlock());
|
||||
this.getAppliance().addTracking(event.getBlock(), ignitedBy);
|
||||
break;
|
||||
|
||||
case FLINT_AND_STEEL:
|
||||
case ENDER_CRYSTAL:
|
||||
case ARROW:
|
||||
case FIREBALL:
|
||||
if(event.getPlayer() == null) return;
|
||||
this.getAppliance().addTracking(event.getBlock(), event.getPlayer().getUniqueId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpread(BlockSpreadEvent event) {
|
||||
if(!event.getBlock().getType().equals(Material.FIRE)) return;
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getBlock());
|
||||
this.getAppliance().addTracking(event.getBlock(), ignitedBy);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDestroy(BlockBurnEvent event) {
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getIgnitingBlock());
|
||||
if(ignitedBy == null) return;
|
||||
this.getAppliance().addDestroyed(event.getBlock(), ignitedBy);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user