Compare commits
13 Commits
develop-de
...
78f87d97f0
| Author | SHA1 | Date | |
|---|---|---|---|
| 78f87d97f0 | |||
| db13a9f0a2 | |||
| 09abfefe33 | |||
| bd3546abc8 | |||
| 8a7a0453ce | |||
| 64d0d817c0 | |||
| 713561bf07 | |||
| 4be3e528b1 | |||
| 53fca580f3 | |||
| 20fb4bf9fb | |||
| c42d259909 | |||
| 5c82c8d6da | |||
| 5910847172 |
@@ -6,6 +6,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CraftAttackApi {
|
public class CraftAttackApi {
|
||||||
@@ -25,4 +26,8 @@ public class CraftAttackApi {
|
|||||||
public static void withAuthorizationSecret(URIBuilder builder) {
|
public static void withAuthorizationSecret(URIBuilder builder) {
|
||||||
builder.addParameter("secret", apiSecret);
|
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 class CraftAttackReportRepository extends ReportRepository {
|
||||||
public CraftAttackReportRepository() {
|
public CraftAttackReportRepository() {
|
||||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||||
|
|||||||
@@ -21,18 +21,17 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
|||||||
public void onPlayerChatEvent(AsyncChatEvent event) {
|
public void onPlayerChatEvent(AsyncChatEvent event) {
|
||||||
event.renderer(
|
event.renderer(
|
||||||
(source, sourceDisplayName, message, viewer) ->
|
(source, sourceDisplayName, message, viewer) ->
|
||||||
Component.text("")
|
Component.text()
|
||||||
.append(this.getAppliance().getReportablePlayerName(source))
|
.append(this.getAppliance().getReportablePlayerName(source))
|
||||||
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
||||||
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
||||||
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
boolean wasHidden = event.joinMessage() == null;
|
if(event.joinMessage() == null) return;
|
||||||
event.joinMessage(null);
|
|
||||||
if(wasHidden) return;
|
|
||||||
IteratorUtil.onlinePlayers(player -> {
|
IteratorUtil.onlinePlayers(player -> {
|
||||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
@@ -45,9 +44,7 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||||
boolean wasHidden = event.quitMessage() == null;
|
if(event.quitMessage() == null) return;
|
||||||
event.quitMessage(null);
|
|
||||||
if(wasHidden) return;
|
|
||||||
IteratorUtil.onlinePlayers(player -> {
|
IteratorUtil.onlinePlayers(player -> {
|
||||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
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.ReportRepository;
|
||||||
import eu.mhsl.craftattack.spawn.common.api.repositories.VaroReportRepository;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||||
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
||||||
@@ -64,7 +63,7 @@ public class Report extends Appliance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {
|
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {
|
||||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(VaroReportRepository.class)
|
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||||
.createReport(reportRequest);
|
.createReport(reportRequest);
|
||||||
|
|
||||||
switch(createdReport.status()) {
|
switch(createdReport.status()) {
|
||||||
@@ -115,7 +114,7 @@ public class Report extends Appliance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void queryReports(Player issuer) {
|
public void queryReports(Player issuer) {
|
||||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(VaroReportRepository.class)
|
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||||
.queryReports(issuer.getUniqueId());
|
.queryReports(issuer.getUniqueId());
|
||||||
|
|
||||||
if(userReports.status() != 200) {
|
if(userReports.status() != 200) {
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|||||||
class PlayerLimiterListener extends ApplianceListener<PlayerLimit> {
|
class PlayerLimiterListener extends ApplianceListener<PlayerLimit> {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogin(AsyncPlayerPreLoginEvent playerPreLoginEvent) {
|
public void onLogin(AsyncPlayerPreLoginEvent playerPreLoginEvent) {
|
||||||
playerPreLoginEvent.kickMessage(
|
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit()) {
|
||||||
new DisconnectInfo(
|
playerPreLoginEvent.kickMessage(
|
||||||
"Hohe Serverauslastung",
|
new DisconnectInfo(
|
||||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
"Hohe Serverauslastung",
|
||||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||||
playerPreLoginEvent.getUniqueId()
|
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||||
).getComponent()
|
playerPreLoginEvent.getUniqueId()
|
||||||
);
|
).getComponent()
|
||||||
|
);
|
||||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit())
|
|
||||||
playerPreLoginEvent.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
playerPreLoginEvent.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class FeedbackRepository extends HttpRepository {
|
public class FeedbackRepository extends HttpRepository {
|
||||||
public FeedbackRepository() {
|
public FeedbackRepository() {
|
||||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Request(String event, List<UUID> users) {
|
public record Request(String event, List<UUID> users) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class WhitelistRepository extends HttpRepository {
|
public class WhitelistRepository extends HttpRepository {
|
||||||
public WhitelistRepository() {
|
public WhitelistRepository() {
|
||||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public record UserData(
|
public record UserData(
|
||||||
@@ -21,10 +21,12 @@ public class WhitelistRepository extends HttpRepository {
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record UserQuery(UUID uuid) {}
|
||||||
|
|
||||||
public ReqResp<UserData> getUserData(UUID userId) {
|
public ReqResp<UserData> getUserData(UUID userId) {
|
||||||
return this.get(
|
return this.post(
|
||||||
"user",
|
"player",
|
||||||
parameters -> parameters.addParameter("uuid", userId.toString()),
|
new UserQuery(userId),
|
||||||
UserData.class
|
UserData.class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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)
|
if(response.status() != HttpStatus.OK)
|
||||||
throw new IllegalStateException(String.format("Http Reponse %d", response.status()));
|
throw new IllegalStateException(String.format("Unwanted response %d!", response.status()));
|
||||||
|
|
||||||
return response.data();
|
return response.data();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
local.gradle.example
Normal file
24
local.gradle.example
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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" }
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
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