Commits vergleichen
305 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
|
47d5f29ae6 | ||
|
552a1ea7fc | ||
|
d77e8e829e | ||
|
bd06bce3dc | ||
|
76ecc8e6e4 | ||
|
820e7fcbb2 | ||
|
94958de2da | ||
|
2214b7dc3d | ||
75e6b28e0e | |||
a1dd919afa | |||
|
2b0b2a08d7 | ||
|
7fc76e5e2a | ||
|
5153609776 | ||
593113bbc3 | |||
|
a62c08b097 | ||
442ba6f483 | |||
|
e253e12994 | ||
|
38bb687c5b | ||
|
30ddf671ae | ||
|
2829706d6b | ||
|
ab6c762323 | ||
|
d5acfa3f5c | ||
|
3370e211f9 | ||
|
29c7732166 | ||
ec3a8a1421 | |||
|
f054710a95 | ||
67f6363852 | |||
7182635558 | |||
|
7d01ebf4ed | ||
|
595c45bb54 | ||
45a61e554f | |||
|
a43e141340 | ||
4a334d8693 | |||
|
6a6833a0e0 | ||
daedbb26a7 | |||
|
d5ab11addd | ||
|
aa22ccf5b4 | ||
|
723b86b955 | ||
|
a116f7e4b1 | ||
680f9d8b3f | |||
|
00dcb10451 | ||
c815cd52fb | |||
|
ddb701cbd6 | ||
929400b4d9 | |||
|
e9ff8a7dc5 | ||
|
a36bae3a8d | ||
|
7502270b96 | ||
|
0c91261d55 | ||
|
add259788d | ||
|
4568ceee36 | ||
106a13bd13 | |||
|
2aec97304d | ||
|
7fa31704f4 | ||
|
95132a17d3 | ||
|
e08e53a554 | ||
5ab6b8832b | |||
|
2861a4e19b | ||
|
18430e13fe | ||
|
e8eeeb729a | ||
792b089e4f | |||
|
b602fb06d0 | ||
18769a6931 | |||
|
f1b3b27c14 | ||
|
fd17b8315f | ||
2ed6008aea | |||
|
a5b90be2db | ||
|
c278b1cfe1 | ||
|
486d04dd66 | ||
f1d929e33b | |||
6f6b61b310 | |||
|
f50d887da5 | ||
|
5d2886c0a5 | ||
|
9d96d5a2a8 | ||
|
07cd605d2c | ||
aeb5ebfc12 | |||
|
7e96d1c846 | ||
|
5595f3177c | ||
|
e931d7157e | ||
|
b64e06479f | ||
|
86cf7e8ca5 | ||
|
69b629d72e | ||
|
143ba020ed | ||
|
d0a08bc331 | ||
|
d81fb4e020 | ||
|
7ddfcb83ec | ||
|
09aa662171 | ||
|
56a72b1e83 | ||
|
295eb82fe9 | ||
|
f7727eb01c | ||
|
4e56760eea | ||
|
f69cbd2724 | ||
|
0d09db2284 | ||
|
47772ad23d | ||
|
83e5324986 | ||
|
8512a7bec5 | ||
|
35988bfcd3 | ||
|
67a34ee5ca | ||
|
5af9cfcaad | ||
|
8b07e93a70 | ||
|
4d9aacfc3e | ||
|
6a3f3f8b0a | ||
|
4e6755033a | ||
|
4422c249dc | ||
|
1a3850600c | ||
|
33d687b216 | ||
|
2eab79cf69 | ||
|
1bcf415186 | ||
|
27dc30619b | ||
|
17a8389703 | ||
|
d170e96542 | ||
|
356b14d49c | ||
|
7a9a2283a9 | ||
|
d5d8c52862 | ||
|
163967483f | ||
|
ed799b2937 | ||
|
d13c415565 | ||
|
39d2205b85 | ||
|
c4296a3781 | ||
|
31e0a0172f | ||
|
bcdad382c7 | ||
|
597c968463 | ||
|
43a04a68bf | ||
|
80967ab4e7 | ||
|
e06d612a0e | ||
|
224127eac6 | ||
|
1aa63255e7 | ||
|
7f4834412d | ||
|
e01ac8ac58 | ||
|
7ece12de47 | ||
|
af19931946 | ||
|
b8e79f9c55 | ||
|
c7b8b5d2da | ||
|
41d4ce2472 | ||
|
4ed5f40fed | ||
|
a6867cb4f9 | ||
|
7cd61fd9a4 | ||
|
3f9f3341a3 | ||
|
e7438029b0 | ||
3755395eab | |||
|
e64c50b566 | ||
|
207826ae8a | ||
9b70f2b365 | |||
|
ae470ffadd | ||
|
4a0cd6c51e | ||
|
3b53926195 | ||
|
687cb4451e | ||
|
41fab57e1a | ||
|
d8d049d5d9 | ||
|
e8db5d86c2 | ||
|
1fc9a43604 | ||
|
488866cee6 | ||
|
eefe92309d | ||
|
c369662a28 | ||
|
870578dcf9 | ||
|
987a00ae51 | ||
|
c0dcb99f7b | ||
|
d80e4cf3e0 | ||
|
2d7ae67335 | ||
|
be25b71cb8 | ||
|
a94f5747a0 | ||
|
5a59578a66 | ||
|
10a63f1876 | ||
|
5ec9fbb6e0 | ||
719b38f5af | |||
aa8d2bfcd0 | |||
|
cf329f4236 | ||
|
6abeed0b02 | ||
|
45cc3abd0a | ||
|
2cd3c3527e | ||
5a835acb80 | |||
5a991de55a | |||
|
827929382a | ||
|
1282f6066c | ||
|
8a78dcbc78 | ||
|
04b49fe827 | ||
|
8a3d8a9c33 | ||
|
dfd20f03b6 | ||
|
234f476672 | ||
|
b7cb909986 | ||
5b8d7bc28f | |||
|
f1db3c2047 | ||
|
2d5bedc63a | ||
|
8781da6a3d | ||
|
a91c352b15 | ||
|
f7481bfa0f | ||
|
2ccc7920d5 | ||
|
3ecd31e80c | ||
|
1da5b65460 | ||
|
1cbe614171 | ||
|
4620e83a82 | ||
|
6ec62d9720 | ||
|
335e2cc437 | ||
|
75edfc8375 | ||
|
ccf155d500 | ||
|
e4346a36e1 | ||
|
8aa0ee4d9d | ||
|
fccdcb2519 | ||
|
b47d85ebe9 | ||
|
0c37cfc3bb | ||
|
1094f4a979 | ||
|
c03fbb65e6 | ||
|
48175de8d8 | ||
|
eeb47f1d08 | ||
|
e71ccc3160 | ||
|
40f4af2a06 | ||
|
3c22840278 | ||
|
c621048014 | ||
|
1644b96886 | ||
|
f62d9e626b | ||
|
3a3c4819f9 | ||
|
5c96da9acd | ||
|
5a03623b14 | ||
|
f837b37b50 | ||
|
fd603f3c7f | ||
|
280b5b2613 | ||
|
7f62ad8005 | ||
|
d1196c6e4e | ||
|
009a1f3fa4 | ||
|
a05116a16c | ||
|
cc15781b44 | ||
|
8053796341 | ||
|
9466a8c981 | ||
|
338980f0d3 | ||
e4dc05ce02 | |||
|
de08488371 | ||
|
21e7bd89af | ||
|
953db69425 | ||
|
1d49a6981b | ||
d9dd64271e | |||
|
c2c686319d | ||
7ded9eefa4 | |||
|
b211f9cf79 | ||
|
2ba51e66e0 | ||
|
f83ba6ab96 | ||
|
b891c5adf1 | ||
|
78c0bc51b9 | ||
|
d1afb344d9 | ||
|
e77680d25a | ||
|
94bf2f3ae6 | ||
|
775d428671 | ||
|
ea5df6cee3 | ||
|
da1ea27f61 | ||
|
2bf0b0c6e8 | ||
85e6aab9e6 | |||
ad9b0aeab0 | |||
016a2a3469 | |||
c2bec98063 | |||
|
ada8fefd62 | ||
|
21aa22d75f | ||
|
a3f5098137 | ||
|
cdac4235f5 | ||
|
b166d8ff6b | ||
|
2c5a50bff3 | ||
|
beb49cdcd1 | ||
|
96b84a798b | ||
|
6e9693d838 | ||
|
2a55f607d3 | ||
|
0ac735c30f | ||
|
b00babdcbd | ||
|
f5e4d725fe | ||
|
ca8a916042 | ||
|
8da1fdac58 | ||
|
927ce1f495 | ||
|
0bf27db398 | ||
|
202e03c957 | ||
|
2cfed8b84d | ||
|
ec10b0fe71 | ||
|
bff63482ef | ||
|
4f266a30ab | ||
|
85512be3a8 | ||
|
67c9f66d13 | ||
|
f2a957c88f | ||
|
d1ff80b9dc | ||
|
41ed83dfe0 | ||
|
2bf3cfbb1d | ||
|
19bb7cc733 | ||
|
17c03f629a | ||
|
f6644d8ad8 | ||
|
4ff706e1ef | ||
|
3d0ebbe743 | ||
|
5556bd7875 | ||
|
5fe0079e30 | ||
|
006a0edef6 | ||
|
6305453e15 | ||
|
a61f1e2c8c | ||
|
78f7e42629 | ||
|
3dddb48d0c | ||
|
37e6628aaa | ||
|
bcb8b31ba9 | ||
|
832484c2a2 | ||
|
7802a03f48 | ||
|
20af36a4a2 | ||
|
0cec90c55c | ||
|
0b70bdfe97 | ||
|
ec93dfd8ec | ||
|
1a6c0de502 | ||
|
b73af3e2ec | ||
|
f94aeeda01 | ||
b58e418ea4 | |||
|
979428d493 | ||
|
84150aadd2 | ||
|
32fb859764 | ||
|
b886745113 | ||
|
27a542590c | ||
|
5de070c90e |
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,5 +1,7 @@
|
||||
# Package Files
|
||||
# Build files
|
||||
*.jar
|
||||
**/bin
|
||||
**/build
|
||||
|
||||
# Gradle
|
||||
.gradle
|
||||
@ -10,6 +12,10 @@ steamwar.properties
|
||||
# IntelliJ IDEA
|
||||
.idea
|
||||
*.iml
|
||||
plugin.yml
|
||||
|
||||
# Other
|
||||
lib
|
||||
lib
|
||||
|
||||
#linkage
|
||||
LinkageUtils.java
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer.record;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.EntityTNTPrimed;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TNTPrimedIterator15 implements TNTPrimedIterator {
|
||||
|
||||
private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0);
|
||||
|
||||
@Override
|
||||
public Stream<TNTPrimed> iterator() {
|
||||
return WORLD.getHandle().entitiesById.values().stream()
|
||||
.filter(EntityTNTPrimed.class::isInstance)
|
||||
.map(entity -> (TNTPrimed) entity.getBukkitEntity());
|
||||
}
|
||||
}
|
@ -106,6 +106,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
||||
|
||||
private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||
private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
|
||||
@Override
|
||||
public void setSelection(Player p, Point minPoint, Point maxPoint) {
|
||||
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
|
||||
@ -190,7 +191,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
||||
public Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint) {
|
||||
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint));
|
||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
||||
@ -203,12 +204,21 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
||||
copy.setCopyingBiomes(false);
|
||||
|
||||
Operations.complete(copy);
|
||||
clipboard.setOrigin(toBlockVector3(copyPoint));
|
||||
return clipboard;
|
||||
} catch (WorldEditException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||
writer.write(clipboard);
|
||||
}
|
||||
@Override
|
||||
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
||||
Clipboard clipboard = copy(minPoint, maxPoint, minPoint);
|
||||
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||
writer.write(clipboard);
|
||||
return true;
|
||||
} catch (WorldEditException | IOException e) {
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.tracer.record;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class TNTPrimedIterator18 implements TNTPrimedIterator {
|
||||
|
||||
private static final Reflection.MethodInvoker getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle");
|
||||
private static final Reflection.MethodInvoker getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class);
|
||||
private static final Reflection.MethodInvoker getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class);
|
||||
private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null);
|
||||
|
||||
@Override
|
||||
public Stream<TNTPrimed> iterator() {
|
||||
return StreamSupport.stream(((Iterable<?>) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Bukkit.getWorlds().get(0))))).spliterator(), false)
|
||||
.map(getBukkitEntity::invoke)
|
||||
.filter(TNTPrimed.class::isInstance)
|
||||
.map(TNTPrimed.class::cast);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,6 @@ public class ScoreboardElement_GENERIC implements LinkageType {
|
||||
@Override
|
||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
||||
buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard");
|
||||
methodBuilder.addLine("BauScoreboard.ELEMENTS.add(" + s + ");");
|
||||
methodBuilder.addLine("BauScoreboard.addElement(" + s + ");");
|
||||
}
|
||||
}
|
||||
|
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
@ -22,16 +22,19 @@ package de.steamwar.bausystem;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
|
||||
import de.steamwar.bausystem.features.world.RamUsage;
|
||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||
import de.steamwar.bausystem.region.loader.Updater;
|
||||
import de.steamwar.bausystem.utils.TickListener;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.command.AbstractValidator;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -49,6 +52,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
// This should be treated as final!
|
||||
public static Message MESSAGE;
|
||||
public static final boolean DEV_SERVER = !System.getProperty("user.home").endsWith("minecraft");
|
||||
|
||||
@Getter
|
||||
private static BauSystem instance;
|
||||
@ -69,32 +73,40 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
} catch (SecurityException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
Bukkit.shutdown();
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||
new Updater(RegionLoader.file, RegionLoader::load);
|
||||
|
||||
LinkageUtils.link();
|
||||
RamUsage.init();
|
||||
TickListener.impl.init();
|
||||
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
|
||||
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
|
||||
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));
|
||||
SWCommandUtils.addValidator("owner", validator(Permission.OWNER));
|
||||
|
||||
// This could disable any watchdog stuff. We need to investigate if this is a problem.
|
||||
/*
|
||||
Thread thread = new Thread(() -> {
|
||||
while (true) {
|
||||
WatchdogThread.tick();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
try {
|
||||
LinkageUtils.link();
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
Bukkit.shutdown();
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
TickListener.impl.init();
|
||||
}
|
||||
|
||||
private <T extends CommandSender> AbstractValidator<T, ?> validator(Permission permission) {
|
||||
return (commandSender, object, messageSender) -> {
|
||||
if (commandSender instanceof Player) {
|
||||
if (permission.hasPermission((Player) commandSender)) {
|
||||
return true;
|
||||
}
|
||||
messageSender.send("NO_PERMISSION");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
thread.setName("WatchdogThread ticker");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
*/
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,43 +20,77 @@
|
||||
package de.steamwar.bausystem;
|
||||
|
||||
import de.steamwar.bausystem.config.BauServer;
|
||||
import de.steamwar.command.CommandMetaData;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.bausystem.features.world.BauMemberUpdate;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Permission {
|
||||
|
||||
WORLD(BauweltMember::isWorld),
|
||||
WORLDEDIT(BauweltMember::isWorldEdit),
|
||||
MEMBER(bauweltMember -> true),
|
||||
OWNER(bauweltMember -> false);
|
||||
OWNER(bauweltMember -> false),
|
||||
SUPERVISOR(bauweltMember -> {
|
||||
return bauweltMember.isSupervisor();
|
||||
}),
|
||||
BUILD(bauweltMember -> {
|
||||
if (isTempOnlySpectator(bauweltMember)) return false;
|
||||
return bauweltMember.isBuild() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
||||
}),
|
||||
/**
|
||||
* Only used for {@link BauMemberUpdate}
|
||||
*/
|
||||
REAL_SPECTATOR(bauweltMember -> {
|
||||
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
||||
}),
|
||||
/**
|
||||
* Primarily used for {@link de.steamwar.bausystem.linkage.specific.GuiItem}
|
||||
*/
|
||||
MEMBER(bauweltMember -> {
|
||||
return true;
|
||||
});
|
||||
|
||||
private static final Set<Integer> TEMP_ONLY_SPECTATOR = new HashSet<>();
|
||||
|
||||
private static boolean isTempOnlySpectator(BauweltMember bauweltMember) {
|
||||
return TEMP_ONLY_SPECTATOR.contains(bauweltMember.getMemberID());
|
||||
}
|
||||
|
||||
public static boolean isTempOnlySpectator(Player player) {
|
||||
return TEMP_ONLY_SPECTATOR.contains(SteamwarUser.get(player.getUniqueId()).getId());
|
||||
}
|
||||
|
||||
public static void forceOnlySpectator(Player player) {
|
||||
TEMP_ONLY_SPECTATOR.add(SteamwarUser.get(player.getUniqueId()).getId());
|
||||
BauMemberUpdate.baumemberUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used by {@link BauMemberUpdate}
|
||||
*/
|
||||
public static void removeForceOnlySpectator(Player player) {
|
||||
TEMP_ONLY_SPECTATOR.remove(SteamwarUser.get(player.getUniqueId()).getId());
|
||||
}
|
||||
|
||||
private final Predicate<BauweltMember> permissionPredicate;
|
||||
|
||||
public boolean hasPermission(Player member) {
|
||||
if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
||||
if (bauMember == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return permissionPredicate.test(bauMember);
|
||||
public boolean hasPermission(BauweltMember bauweltMember) {
|
||||
if (bauweltMember == null) return false;
|
||||
return permissionPredicate.test(bauweltMember);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player member, Permission permission) {
|
||||
return permission.hasPermission(member);
|
||||
public boolean hasPermission(Player member) {
|
||||
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
||||
return this != REAL_SPECTATOR;
|
||||
}
|
||||
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
||||
if (bauweltMember == null) return this == REAL_SPECTATOR;
|
||||
return permissionPredicate.test(bauweltMember);
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ public class Config implements Listener {
|
||||
|
||||
public void saveAll() {
|
||||
playerConfigurations.forEach((uuid, yapionObject) -> {
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\+", "\\");
|
||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||
});
|
||||
playerConfigurations.clear();
|
||||
@ -112,7 +112,7 @@ public class Config implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (playerConfigurations.containsKey(uuid)) {
|
||||
YAPIONObject yapionObject = playerConfigurations.get(uuid);
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\\\");
|
||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class AttributeRemoveCommand extends SWCommand {
|
||||
|
||||
@Register({"all"})
|
||||
@Register({"*"})
|
||||
public void genericCommand(Player player) {
|
||||
public void genericCommand(@Validator Player player) {
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.setLore(new ArrayList<>());
|
||||
@ -53,7 +53,7 @@ public class AttributeRemoveCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(description = "ATTRIBUTE_REMOVE_COMMAND_HELP")
|
||||
public void genericCommand(Player player, @Mapper("attribute") String attribute) {
|
||||
public void genericCommand(@Validator Player player, @Mapper("attribute") String attribute) {
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
|
@ -41,7 +41,7 @@ public class AttributesCopyCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
public void genericCommand(@Validator Player player) {
|
||||
Block block = player.getTargetBlockExact(8, FluidCollisionMode.ALWAYS);
|
||||
if (block == null) return;
|
||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.attributescopy;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -40,6 +41,7 @@ public class AttributesPlaceListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
ItemStack itemStack = event.getItemInHand();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) return;
|
||||
|
@ -32,7 +32,7 @@ public class AutoStartCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(description = "AUTOSTART_COMMAND_HELP")
|
||||
public void genericCommand(Player p) {
|
||||
public void genericCommand(@Validator Player p) {
|
||||
SWUtils.giveItemToPlayer(p, AutostartListener.getWandItem(p));
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,6 @@ public class AutoStartGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.MEMBER;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.autostart;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
@ -29,6 +30,7 @@ import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.type.Chest;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -66,6 +68,7 @@ public class AutostartListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getItem(), "autostart")) {
|
||||
return;
|
||||
}
|
||||
@ -75,6 +78,12 @@ public class AutostartListener implements Listener {
|
||||
if (event.getClickedBlock().getBlockData() instanceof Chest) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedBlock().getType() == Material.BEDROCK) {
|
||||
event.getClickedBlock().setType(Material.SLIME_BLOCK);
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
event.getClickedBlock().setType(Material.BEDROCK, false);
|
||||
}, 1);
|
||||
}
|
||||
activate(event.getPlayer());
|
||||
}
|
||||
|
||||
@ -83,6 +92,7 @@ public class AutostartListener implements Listener {
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if(!Permission.BUILD.hasPermission((Player) event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getPlayer().getInventory().getItemInMainHand(), "autostart")) {
|
||||
return;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class BackupCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "create", description = "BACKUP_HELP_CREATE")
|
||||
public void backupCreate(@Validator Player p) {
|
||||
public void backupCreate(@Validator("owner") Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
@ -79,7 +79,7 @@ public class BackupCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "load", description = "BACKUP_HELP_LOAD")
|
||||
public void backupLoad(@Validator Player p, @Mapper("backupName") String backupName) {
|
||||
public void backupLoad(@Validator("owner") Player p, @Mapper("backupName") String backupName) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
@ -130,7 +130,7 @@ public class BackupCommand extends SWCommand {
|
||||
}
|
||||
SWListInv<String> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
|
||||
p.getOpenInventory().close();
|
||||
backupLoad(p, s);
|
||||
p.performCommand("backup load " + s);
|
||||
});
|
||||
swListInv.open();
|
||||
}
|
||||
@ -140,13 +140,6 @@ public class BackupCommand extends SWCommand {
|
||||
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> backupValidator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "BACKUP_NO_PERMS");
|
||||
};
|
||||
}
|
||||
|
||||
private List<String> listBackup(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.bau;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class BauCommand extends SWCommand {
|
||||
|
||||
@LinkedInstance
|
||||
public InfoCommand infoCommand;
|
||||
|
||||
public BauCommand() {
|
||||
super("bau", "b", "gs");
|
||||
}
|
||||
|
||||
@Register(value = "info", description = "BAU_COMMAND_HELP_INFO")
|
||||
public void infoCommand(Player p) {
|
||||
infoCommand.sendBauInfo(p);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.bau;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.techhider.TechHider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class ForceSpectatorCommand extends SWCommand {
|
||||
|
||||
public ForceSpectatorCommand() {
|
||||
super("forcespectator");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void forceSpectator(@Validator("supervisor") Player player, @Mapper("builder") Player other) {
|
||||
Permission.forceOnlySpectator(other);
|
||||
}
|
||||
|
||||
@Mapper("builder")
|
||||
public TypeMapper<Player> spectatorMapper() {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
Player player = Bukkit.getPlayer(s);
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
if (Permission.BUILD.hasPermission(player) && !Permission.SUPERVISOR.hasPermission(player)) {
|
||||
return player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.filter(Permission.BUILD::hasPermission)
|
||||
.filter(player -> !Permission.SUPERVISOR.hasPermission(player))
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package de.steamwar.bausystem.features.bau;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.config.BauServer;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
@ -12,7 +13,7 @@ import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@Linked
|
||||
public class InfoCommand extends SWCommand {
|
||||
@ -24,17 +25,8 @@ public class InfoCommand extends SWCommand {
|
||||
super("bauinfo");
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player p, String... args) {
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_HELP", p);
|
||||
}
|
||||
|
||||
@Register
|
||||
@Register(description = "BAU_INFO_COMMAND_HELP")
|
||||
public void genericCommand(Player p) {
|
||||
sendBauInfo(p);
|
||||
}
|
||||
|
||||
public void sendBauInfo(Player p) {
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.get(bauServer.getOwnerID()).getUserName());
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
for (Flag flag : Flag.getFlags()) {
|
||||
@ -47,18 +39,28 @@ public class InfoCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
List<BauweltMember> members = BauweltMember.getMembers(bauServer.getOwnerID());
|
||||
StringBuilder membermessage = new StringBuilder();
|
||||
membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size()));
|
||||
if (Permission.BUILD.hasPermission(p)) {
|
||||
List<BauweltMember> members = BauweltMember.getMembers(bauServer.getOwnerID());
|
||||
Map<Permission, List<BauweltMember>> memberByPermission = new HashMap<>();
|
||||
members.forEach(member -> {
|
||||
if (Permission.SUPERVISOR.hasPermission(member)) {
|
||||
memberByPermission.computeIfAbsent(Permission.SUPERVISOR, __ -> new ArrayList<>()).add(member);
|
||||
} else if (Permission.BUILD.hasPermission(member)) {
|
||||
memberByPermission.computeIfAbsent(Permission.BUILD, __ -> new ArrayList<>()).add(member);
|
||||
} else {
|
||||
memberByPermission.computeIfAbsent(Permission.MEMBER, __ -> new ArrayList<>()).add(member);
|
||||
}
|
||||
});
|
||||
|
||||
for (BauweltMember member : members) {
|
||||
membermessage.append(BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_INFO", p,
|
||||
SteamwarUser.get(member.getMemberID()).getUserName(),
|
||||
member.isWorldEdit() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_DISALLOW", p),
|
||||
member.isWorld() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_DISALLOW", p)
|
||||
));
|
||||
List<BauweltMember> supervisor = memberByPermission.getOrDefault(Permission.SUPERVISOR, Collections.emptyList());
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§eSupervisor", supervisor.size(), supervisor.isEmpty() ? "§8<none>" : joining(supervisor));
|
||||
|
||||
List<BauweltMember> builder = memberByPermission.getOrDefault(Permission.BUILD, Collections.emptyList());
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§6Builder", builder.size(), builder.isEmpty() ? "§8<none>" : joining(builder));
|
||||
|
||||
List<BauweltMember> spectator = memberByPermission.getOrDefault(Permission.MEMBER, Collections.emptyList());
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§7Spectator", spectator.size(), spectator.isEmpty() ? "§8<none>" : joining(spectator));
|
||||
}
|
||||
p.sendMessage(membermessage.toString());
|
||||
|
||||
StringBuilder tpsMessage = new StringBuilder();
|
||||
tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_TPS", p));
|
||||
@ -69,4 +71,16 @@ public class InfoCommand extends SWCommand {
|
||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES));
|
||||
p.sendMessage(tpsMessage.toString());
|
||||
}
|
||||
|
||||
private String joining(List<BauweltMember> bauweltMembers) {
|
||||
StringBuilder st = new StringBuilder();
|
||||
for (int i = 0; i < bauweltMembers.size(); i++) {
|
||||
if (i != 0) {
|
||||
st.append("§8, ");
|
||||
}
|
||||
st.append("§7");
|
||||
st.append(SteamwarUser.get(bauweltMembers.get(i).getMemberID()).getUserName());
|
||||
}
|
||||
return st.toString();
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,6 @@ public class CountingwandGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLDEDIT;
|
||||
return Permission.MEMBER;
|
||||
}
|
||||
}
|
@ -44,7 +44,8 @@ public class DesignEndStone {
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
private List<REntity> entities = new ArrayList<>();
|
||||
private Set<Location> locations = new HashSet<>();
|
||||
private List<Player> players = new ArrayList<>();
|
||||
private boolean wsOrAs;
|
||||
private double maxBlastResistance;
|
||||
|
||||
public DesignEndStone(Region region) {
|
||||
this.minX = region.getMinPointBuild().getX();
|
||||
@ -53,6 +54,17 @@ public class DesignEndStone {
|
||||
this.maxX = region.getMaxPointBuild().getX();
|
||||
this.maxY = region.getMaxPointBuild().getY();
|
||||
this.maxZ = region.getMaxPointBuild().getZ();
|
||||
wsOrAs = region.getName().startsWith("ws") || region.getName().startsWith("as");
|
||||
maxBlastResistance = wsOrAs ? 6.1 : 9.0;
|
||||
|
||||
entityServer.setCallback((player, rEntity, entityAction) -> {
|
||||
if (entityAction != REntityServer.EntityAction.ATTACK) return;
|
||||
Location location = new Location(WORLD, rEntity.getX(), rEntity.getY(), rEntity.getZ());
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
location.getBlock().breakNaturally();
|
||||
calc();
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
|
||||
public void calc() {
|
||||
@ -64,8 +76,24 @@ public class DesignEndStone {
|
||||
calc(minX, minY, maxZ, maxX, maxY, maxZ, 0, 0, -1, maxZ - minZ);
|
||||
calc(minX, minY, minZ, minX, maxY, maxZ, 1, 0, 0, maxX - minX);
|
||||
calc(maxX, minY, minZ, maxX, maxY, maxZ, -1, 0, 0, maxX - minX);
|
||||
// calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY);
|
||||
calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY);
|
||||
if (wsOrAs) {
|
||||
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
|
||||
} else {
|
||||
int airBlocks = 0;
|
||||
double minAirBlocks = (maxX - minX) * (maxZ - minZ) * 0.1;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
if (WORLD.getBlockAt(x, minY, z).getType().isAir()) {
|
||||
airBlocks++;
|
||||
if (airBlocks > minAirBlocks) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (airBlocks > minAirBlocks) {
|
||||
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
|
||||
}
|
||||
}
|
||||
calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY + 1);
|
||||
}
|
||||
|
||||
private void calc(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dirX, int dirY, int dirZ, int steps) {
|
||||
@ -77,15 +105,16 @@ public class DesignEndStone {
|
||||
int cy = y + step * dirY;
|
||||
int cz = z + step * dirZ;
|
||||
Material material = WORLD.getBlockAt(cx, cy, cz).getType();
|
||||
if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) {
|
||||
|
||||
if (material != Material.WATER && material != Material.LAVA && material.getBlastResistance() >= maxBlastResistance) {
|
||||
Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5);
|
||||
if (locations.contains(location)) break;
|
||||
if (!locations.add(location)) break;
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS);
|
||||
entity.setNoGravity(true);
|
||||
entity.setGlowing(true);
|
||||
entities.add(entity);
|
||||
break;
|
||||
} else if (!material.isAir()) {
|
||||
} else if (!material.isAir() && material != Material.WATER && material != Material.LAVA) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -95,12 +124,10 @@ public class DesignEndStone {
|
||||
}
|
||||
|
||||
public void toggle(Player player) {
|
||||
if (players.contains(player)) {
|
||||
players.remove(player);
|
||||
if (entityServer.getPlayers().contains(player)) {
|
||||
entityServer.removePlayer(player);
|
||||
BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR);
|
||||
} else {
|
||||
players.add(player);
|
||||
entityServer.addPlayer(player);
|
||||
calc();
|
||||
BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR);
|
||||
@ -108,7 +135,7 @@ public class DesignEndStone {
|
||||
}
|
||||
|
||||
public boolean removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
return players.isEmpty();
|
||||
entityServer.removePlayer(player);
|
||||
return entityServer.getPlayers().isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.design.endstone;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Location;
|
||||
@ -33,6 +34,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
@Linked
|
||||
@ -45,7 +47,7 @@ public class DesignEndStoneCommand extends SWCommand implements Listener {
|
||||
private Map<Region, DesignEndStone> designEndStoneMap = new HashMap<>();
|
||||
|
||||
@Register(description = "DESIGN_ENDSTONE_COMMAND_HELP")
|
||||
public void genericCommand(Player player) {
|
||||
public void genericCommand(@Validator Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (!region.hasType(RegionType.BUILD)) {
|
||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
||||
@ -56,14 +58,20 @@ public class DesignEndStoneCommand extends SWCommand implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Region region = Region.getRegion(event.getPlayer().getLocation());
|
||||
DesignEndStone designEndStone = designEndStoneMap.get(region);
|
||||
if (designEndStone == null) {
|
||||
return;
|
||||
}
|
||||
if (designEndStone.removePlayer(event.getPlayer())) {
|
||||
designEndStoneMap.remove(region);
|
||||
}
|
||||
disableDesignEndStone(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(this::disableDesignEndStone);
|
||||
}
|
||||
|
||||
private void disableDesignEndStone(Player player) {
|
||||
new HashSet<>(designEndStoneMap.entrySet()).forEach(regionDesignEndStoneEntry -> {
|
||||
if (regionDesignEndStoneEntry.getValue().removePlayer(player)) {
|
||||
designEndStoneMap.remove(regionDesignEndStoneEntry.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -47,6 +47,6 @@ public class DetonatorBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.MEMBER;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -58,12 +58,12 @@ public class DetonatorCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "wand", description = "DETONATOR_HELP_WAND")
|
||||
public void giveWand(Player p) {
|
||||
public void giveWand(@Validator Player p) {
|
||||
SWUtils.giveItemToPlayer(p, getWAND(p));
|
||||
}
|
||||
|
||||
@Register(value = "click", description = "DETONATOR_HELP_CLICK")
|
||||
public void clickDetonator(Player p) {
|
||||
public void clickDetonator(@Validator Player p) {
|
||||
Detonator.activateDetonator(new ItemStorage(p));
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.detonator;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||
@ -65,6 +66,7 @@ public class DetonatorListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Player p = event.getPlayer();
|
||||
if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) {
|
||||
event.setCancelled(true);
|
||||
@ -75,6 +77,7 @@ public class DetonatorListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!Detonator.isDetonator(event.getItem())) {
|
||||
return;
|
||||
}
|
||||
@ -89,7 +92,7 @@ public class DetonatorListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer()) ||!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
||||
Detonator.hideDetonator(event.getPlayer());
|
||||
}
|
||||
@ -110,6 +113,7 @@ public class DetonatorListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||
HAS_UPDATED.add(event.getPlayer());
|
||||
}
|
||||
@ -117,6 +121,7 @@ public class DetonatorListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem())) {
|
||||
HAS_UPDATED.add(event.getPlayer());
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class BauGUI {
|
||||
}
|
||||
} else {
|
||||
p.closeInventory();
|
||||
BauSystem.MESSAGE.send("GUI_NO_PERMISSION", p);
|
||||
BauSystem.MESSAGE.send("NO_PERMISSION", p);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -108,26 +108,13 @@ public class BauGUI {
|
||||
if (!permission.hasPermission(p)) {
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore == null) {
|
||||
lore = Collections.singletonList(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
||||
lore = Collections.singletonList(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
||||
} else {
|
||||
lore.add(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
||||
lore.add(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static String permissionString(Permission permission) {
|
||||
switch (permission) {
|
||||
case OWNER:
|
||||
return "GUI_NO_OWNER";
|
||||
case WORLD:
|
||||
return "GUI_NO_WORLD";
|
||||
case WORLDEDIT:
|
||||
return "GUI_NO_WORLDEDIT";
|
||||
default:
|
||||
return "GUI_NO_MEMBER";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class HotbarCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
||||
public void loadHotbar(Player p) {
|
||||
public void loadHotbar(@Validator Player p) {
|
||||
DefaultHotbar.setHotbar(p);
|
||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.hotbar;
|
||||
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -30,6 +31,7 @@ public class HotbarListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
||||
DefaultHotbar.setHotbar(event.getPlayer());
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.inventoryfiller;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
@ -38,6 +39,7 @@ public class InventoryFiller implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
||||
if (!event.getPlayer().isSneaking()) return;
|
||||
Block block = event.getPlayer().getTargetBlockExact(5);
|
||||
@ -59,6 +61,7 @@ public class InventoryFiller implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
||||
if (!event.getPlayer().isSneaking()) return;
|
||||
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.killchecker;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
@ -54,7 +55,7 @@ public class KillcheckerCommand extends SWCommand implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE")
|
||||
public void genericCommand(Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) {
|
||||
public void genericCommand(@Validator Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, region1 -> new KillcheckerVisualizer(region1, bossBarService));
|
||||
killcheckerVisualizer.recalc();
|
||||
@ -74,16 +75,22 @@ public class KillcheckerCommand extends SWCommand implements Listener {
|
||||
BauSystem.MESSAGE.send("KILLCHECKER_DISABLE", player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(this::hide);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Set<Region> regions = new HashSet<>();
|
||||
visualizers.forEach((region, visualizer) -> {
|
||||
if (visualizer.disconnect(player)) {
|
||||
regions.add(region);
|
||||
hide(event.getPlayer());
|
||||
}
|
||||
|
||||
private void hide(Player player) {
|
||||
new HashSet<>(visualizers.entrySet()).forEach(regionKillcheckerVisualizerEntry -> {
|
||||
if (regionKillcheckerVisualizerEntry.getValue().hide(player)) {
|
||||
visualizers.remove(regionKillcheckerVisualizerEntry.getKey());
|
||||
}
|
||||
});
|
||||
regions.forEach(visualizers::remove);
|
||||
}
|
||||
|
||||
private void recalc(Block block) {
|
||||
|
@ -34,8 +34,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -45,7 +43,22 @@ import java.util.Set;
|
||||
|
||||
public class KillcheckerVisualizer {
|
||||
|
||||
private static final Material[] MATERIALS = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS};
|
||||
private static final Material[] MATERIALS = new Material[]{
|
||||
Material.LIME_STAINED_GLASS,
|
||||
Material.LIME_CONCRETE,
|
||||
Material.GREEN_STAINED_GLASS,
|
||||
Material.GREEN_CONCRETE,
|
||||
Material.YELLOW_STAINED_GLASS,
|
||||
Material.YELLOW_CONCRETE,
|
||||
Material.ORANGE_STAINED_GLASS,
|
||||
Material.ORANGE_CONCRETE,
|
||||
Material.RED_STAINED_GLASS,
|
||||
Material.RED_CONCRETE,
|
||||
Material.PURPLE_STAINED_GLASS,
|
||||
Material.PURPLE_CONCRETE,
|
||||
Material.BLACK_STAINED_GLASS,
|
||||
Material.BLACK_CONCRETE,
|
||||
};
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static final double SURROUND = 4.5;
|
||||
@ -57,9 +70,6 @@ public class KillcheckerVisualizer {
|
||||
private final int zArea;
|
||||
private final int xArea;
|
||||
|
||||
private final Set<Player> players = new HashSet<>();
|
||||
private final Set<Player> areaPlayers = new HashSet<>();
|
||||
|
||||
private final Region region;
|
||||
private final BossBarService bossBarService;
|
||||
|
||||
@ -261,7 +271,7 @@ public class KillcheckerVisualizer {
|
||||
double zPercent = xCount / (double) zArea;
|
||||
percent = (xPercent + yPercent + zPercent) / 3;
|
||||
kills = zKills + yKills + xKills;
|
||||
players.forEach(this::updateBossBar);
|
||||
outline.getPlayers().forEach(this::updateBossBar);
|
||||
|
||||
Set<Point> pointSet = new HashSet<>(killCount.keySet());
|
||||
Set<Point> outlinePointsCacheLast = new HashSet<>(outlinePointsCache);
|
||||
@ -356,40 +366,21 @@ public class KillcheckerVisualizer {
|
||||
return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public boolean show(Player player, boolean onlyOutline) {
|
||||
public void show(Player player, boolean onlyOutline) {
|
||||
outline.addPlayer(player);
|
||||
if (!onlyOutline) {
|
||||
inner.addPlayer(player);
|
||||
areaPlayers.add(player);
|
||||
} else if (areaPlayers.contains(player)) {
|
||||
} else {
|
||||
inner.removePlayer(player);
|
||||
areaPlayers.remove(player);
|
||||
}
|
||||
updateBossBar(player);
|
||||
return players.add(player);
|
||||
}
|
||||
|
||||
public boolean hide(Player player) {
|
||||
outline.removePlayer(player);
|
||||
if (areaPlayers.contains(player)) {
|
||||
inner.removePlayer(player);
|
||||
}
|
||||
players.remove(player);
|
||||
areaPlayers.remove(player);
|
||||
inner.removePlayer(player);
|
||||
bossBarService.remove(player, region, "killchecker");
|
||||
if (players.isEmpty()) {
|
||||
outline.close();
|
||||
inner.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean disconnect(Player player) {
|
||||
players.remove(player);
|
||||
areaPlayers.remove(player);
|
||||
bossBarService.remove(player, region, "killchecker");
|
||||
if (players.isEmpty()) {
|
||||
if (outline.getPlayers().isEmpty() && inner.getPlayers().isEmpty()) {
|
||||
outline.close();
|
||||
inner.close();
|
||||
return true;
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.loader;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
|
||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT;
|
||||
@ -38,7 +39,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class Loader implements Listener {
|
||||
@ -70,12 +74,17 @@ public class Loader implements Listener {
|
||||
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (stage != Stage.RUNNING) return;
|
||||
if(!Permission.BUILD.hasPermission(p)) return;
|
||||
if (waitTime > 0) {
|
||||
waitTime--;
|
||||
return;
|
||||
}
|
||||
if (currentElement >= elements.size()) {
|
||||
currentElement = 0;
|
||||
if (stage == Stage.SINGLE) {
|
||||
stage = Stage.PAUSE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (currentElement < elements.size()) {
|
||||
@ -90,6 +99,20 @@ public class Loader implements Listener {
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
public void single() {
|
||||
if (stage == Stage.END) return;
|
||||
if (stage == Stage.RUNNING) return;
|
||||
stage = Stage.SINGLE;
|
||||
if (recorder != null) {
|
||||
recorder.stop();
|
||||
recorder = null;
|
||||
}
|
||||
if (elements.isEmpty()) {
|
||||
BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p);
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (stage == Stage.END) return;
|
||||
if (stage == Stage.RUNNING) return;
|
||||
@ -347,6 +370,7 @@ public class Loader implements Listener {
|
||||
public enum Stage implements EnumDisplay {
|
||||
SETUP("LOADER_SETUP"),
|
||||
RUNNING("LOADER_RUNNING"),
|
||||
SINGLE("LOADER_SINGLE"),
|
||||
PAUSE("LOADER_PAUSE"),
|
||||
END("LOADER_END");
|
||||
|
||||
|
@ -20,14 +20,15 @@
|
||||
package de.steamwar.bausystem.features.loader;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@Linked
|
||||
public class LoaderCommand extends SWCommand {
|
||||
public class LoaderCommand extends SWCommand implements Listener {
|
||||
|
||||
public LoaderCommand() {
|
||||
super("loader");
|
||||
@ -102,10 +103,20 @@ public class LoaderCommand extends SWCommand {
|
||||
loader.setTicksBetweenBlocks(delay);
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> loaderValidator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "LOADER_PERMS");
|
||||
};
|
||||
@Register(value = "single", description = "LOADER_HELP_SINGLE")
|
||||
public void singleLoader(@Validator Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) return;
|
||||
loader.single();
|
||||
BauSystem.MESSAGE.send("LOADER_SINGLE_CMD", p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(player -> {
|
||||
Loader loader = Loader.getLoader(player);
|
||||
if (loader == null) return;
|
||||
loader.stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoaderRecorder implements Listener {
|
||||
|
||||
@ -124,53 +126,10 @@ public class LoaderRecorder implements Listener {
|
||||
|
||||
addWaitTime(false);
|
||||
Block block = event.getClickedBlock();
|
||||
Material type = block.getType();
|
||||
switch (type) {
|
||||
case COMPARATOR:
|
||||
loaderElementList.add(new LoaderComparator(block.getLocation()));
|
||||
message("LOADER_BUTTON_COMPARATOR");
|
||||
break;
|
||||
case REPEATER:
|
||||
loaderElementList.add(new LoaderRepeater(block.getLocation()));
|
||||
message("LOADER_BUTTON_REPEATER");
|
||||
break;
|
||||
case NOTE_BLOCK:
|
||||
loaderElementList.add(new LoaderNoteBlock(block.getLocation()));
|
||||
message("LOADER_BUTTON_NOTEBLOCK");
|
||||
break;
|
||||
case LEVER:
|
||||
loaderElementList.add(new LoaderLever(block.getLocation()));
|
||||
message("LOADER_BUTTON_SWITCH");
|
||||
break;
|
||||
case DAYLIGHT_DETECTOR:
|
||||
loaderElementList.add(new LoaderDaylightDetector(block.getLocation()));
|
||||
message("LOADER_BUTTON_DAYLIGHT_DETECTOR");
|
||||
break;
|
||||
case LECTERN:
|
||||
loaderElementList.add(new LoaderLectern(block.getLocation()));
|
||||
message("LOADER_BUTTON_LECTERN");
|
||||
break;
|
||||
case IRON_TRAPDOOR:
|
||||
break;
|
||||
default:
|
||||
if (type.name().endsWith("_TRAPDOOR")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type));
|
||||
message("LOADER_BUTTON_TRAPDOOR");
|
||||
} else if (type.name().endsWith("_DOOR")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type));
|
||||
message("LOADER_BUTTON_DOOR");
|
||||
} else if (type.name().endsWith("FENCE_GATE")) {
|
||||
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type));
|
||||
message("LOADER_BUTTON_FENCEGATE");
|
||||
} else if (type.name().endsWith("STONE_BUTTON")) {
|
||||
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20));
|
||||
message("LOADER_BUTTON_STONE_BUTTON");
|
||||
} else if (type.name().endsWith("BUTTON")) {
|
||||
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30));
|
||||
message("LOADER_BUTTON_WOOD_BUTTON");
|
||||
}
|
||||
break;
|
||||
}
|
||||
getLoaderInteractionElement(block, (loaderInteractionElement, s) -> {
|
||||
loaderElementList.add(loaderInteractionElement);
|
||||
message(s);
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Location, Long> blockSet = new HashMap<>();
|
||||
@ -226,6 +185,46 @@ public class LoaderRecorder implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void getLoaderInteractionElement(Block block, BiConsumer<LoaderInteractionElement<?>, String> consumer) {
|
||||
Material type = block.getType();
|
||||
switch (type) {
|
||||
case COMPARATOR:
|
||||
consumer.accept(new LoaderComparator(block.getLocation()), "LOADER_BUTTON_COMPARATOR");
|
||||
break;
|
||||
case REPEATER:
|
||||
consumer.accept(new LoaderRepeater(block.getLocation()), "LOADER_BUTTON_REPEATER");
|
||||
break;
|
||||
case NOTE_BLOCK:
|
||||
consumer.accept(new LoaderNoteBlock(block.getLocation()), "LOADER_BUTTON_NOTEBLOCK");
|
||||
break;
|
||||
case LEVER:
|
||||
consumer.accept(new LoaderLever(block.getLocation()), "LOADER_BUTTON_SWITCH");
|
||||
break;
|
||||
case DAYLIGHT_DETECTOR:
|
||||
consumer.accept(new LoaderDaylightDetector(block.getLocation()), "LOADER_BUTTON_DAYLIGHT_DETECTOR");
|
||||
break;
|
||||
case LECTERN:
|
||||
consumer.accept(new LoaderLectern(block.getLocation()), "LOADER_BUTTON_LECTERN");
|
||||
break;
|
||||
case IRON_TRAPDOOR:
|
||||
case IRON_DOOR:
|
||||
break;
|
||||
default:
|
||||
if (type.name().endsWith("_TRAPDOOR")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type), "LOADER_BUTTON_TRAPDOOR");
|
||||
} else if (type.name().endsWith("_DOOR")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type), "LOADER_BUTTON_DOOR");
|
||||
} else if (type.name().endsWith("FENCE_GATE")) {
|
||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type), "LOADER_BUTTON_FENCEGATE");
|
||||
} else if (type.name().endsWith("STONE_BUTTON")) {
|
||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20), "LOADER_BUTTON_STONE_BUTTON");
|
||||
} else if (type.name().endsWith("BUTTON")) {
|
||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30), "LOADER_BUTTON_WOOD_BUTTON");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void message(String type) {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size()));
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.loader;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.linkage.Linked;
|
||||
@ -40,6 +41,7 @@ public class LoaderScoreboardElement implements ScoreboardElement {
|
||||
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
if(!Permission.BUILD.hasPermission(p)) return null;
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loader == null) return null;
|
||||
if (loader.getStage() == Loader.Stage.RUNNING) {
|
||||
|
@ -32,12 +32,12 @@ public class LoadtimerCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "start", description = "LOADTIMER_HELP_START_1")
|
||||
public void start(Player p) {
|
||||
public void start(@Validator Player p) {
|
||||
start(p, TimerMode.HALF);
|
||||
}
|
||||
|
||||
@Register(value = "start", description = {"LOADTIMER_HELP_START_2", "LOADTIMER_HELP_START_3"})
|
||||
public void start(Player p, TimerMode mode) {
|
||||
public void start(@Validator Player p, TimerMode mode) {
|
||||
Region r = Region.getRegion(p.getLocation());
|
||||
if (r.isGlobal()) return;
|
||||
if (!Loadtimer.hasTimer(r))
|
||||
@ -45,7 +45,7 @@ public class LoadtimerCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "stop", description = "LOADTIMER_HELP_STOP")
|
||||
public void stop(Player p) {
|
||||
public void stop(@Validator Player p) {
|
||||
Region r = Region.getRegion(p.getLocation());
|
||||
if (r.isGlobal()) return;
|
||||
if (Loadtimer.hasTimer(r))
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.observer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,13 +47,13 @@ public class ObserverTracerCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "delete", description = "OBSERVER_HELP_DELETE")
|
||||
public void delete(Player p) {
|
||||
public void delete(@Validator Player p) {
|
||||
ObserverTracerListener.observerTracerMap.remove(p);
|
||||
BauSystem.MESSAGE.send("OBSERVER_DELETE", p);
|
||||
}
|
||||
|
||||
@Register(value = "retrace", description = "OBSERVER_HELP_RETRACE")
|
||||
public void retrace(Player p) {
|
||||
public void retrace(@Validator Player p) {
|
||||
if (ObserverTracerListener.observerTracerMap.containsKey(p)) {
|
||||
BauSystem.MESSAGE.send("OBSERVER_RETRACE_NO_TRACE", p);
|
||||
return;
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bausystem.features.observer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@ -55,6 +57,7 @@ public class ObserverTracerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!enabled.contains(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
@ -87,6 +90,11 @@ public class ObserverTracerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(observerTracerMap::remove);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
enabled.add(event.getPlayer());
|
||||
|
@ -85,7 +85,7 @@ public class ColorCommand extends SWCommand {
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!bauServer.getOwner().equals(player.getUniqueId()), "REGION_COLOR_NO_PERMS");
|
||||
return !messageSender.send(!bauServer.getOwner().equals(player.getUniqueId()), "NO_PERMISSION");
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,6 @@ public class FireCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private String getNoPermMessage() {
|
||||
return "REGION_FIRE_NO_PERMS";
|
||||
}
|
||||
|
||||
private String getEnableMessage() {
|
||||
return "REGION_FIRE_ENABLED";
|
||||
}
|
||||
@ -69,11 +65,4 @@ public class FireCommand extends SWCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ public class FreezeCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private String getNoPermMessage() {
|
||||
return "REGION_FREEZE_NO_PERMS";
|
||||
}
|
||||
|
||||
private String getEnableMessage(){
|
||||
return "REGION_FREEZE_ENABLED";
|
||||
}
|
||||
@ -69,11 +65,4 @@ public class FreezeCommand extends SWCommand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,6 @@ public class ItemsCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private String getNoPermMessage() {
|
||||
return "REGION_ITEMS_NO_PERMS";
|
||||
}
|
||||
|
||||
private String getEnableMessage(){
|
||||
return "REGION_ITEMS_ENABLED";
|
||||
}
|
||||
@ -72,11 +68,4 @@ public class ItemsCommand extends SWCommand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.region;
|
||||
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class NoGravityCommand extends SWCommand {
|
||||
|
||||
public NoGravityCommand() {
|
||||
super("nogravity");
|
||||
}
|
||||
|
||||
@Register(description = "REGION_NO_GRAVITY_HELP")
|
||||
public void toggleCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (toggle(region)) {
|
||||
RegionUtils.actionBar(region, getEnableMessage());
|
||||
} else {
|
||||
RegionUtils.actionBar(region, getDisableMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getEnableMessage() {
|
||||
return "REGION_NO_GRAVITY_ENABLED";
|
||||
}
|
||||
|
||||
private String getDisableMessage() {
|
||||
return "REGION_NO_GRAVITY_DISABLED";
|
||||
}
|
||||
|
||||
private boolean toggle(Region region) {
|
||||
switch (region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class)) {
|
||||
case ACTIVE:
|
||||
region.set(Flag.NO_GRAVITY, NoGravityMode.INACTIVE);
|
||||
return false;
|
||||
default:
|
||||
case INACTIVE:
|
||||
region.set(Flag.NO_GRAVITY, NoGravityMode.ACTIVE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.region;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
@Linked
|
||||
public class NoGravityListener implements Listener, ScoreboardElement {
|
||||
|
||||
private static NoGravityMode getMode(Region region) {
|
||||
return region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||
if (event.getEntityType() == EntityType.PLAYER) return;
|
||||
if (getMode(Region.getRegion(event.getLocation())) == NoGravityMode.ACTIVE) {
|
||||
event.getEntity().setGravity(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.REGION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
if (region.get(Flag.NO_GRAVITY) == Flag.NO_GRAVITY.getDefaultValue()) return null;
|
||||
return "§e" + BauSystem.MESSAGE.parse(Flag.NO_GRAVITY.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.NO_GRAVITY).getChatValue(), p);
|
||||
}
|
||||
}
|
@ -54,13 +54,6 @@ public class ProtectCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_PROTECT_NO_PERMS");
|
||||
};
|
||||
}
|
||||
|
||||
private Region regionCheck(Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region.getFloorLevel() == 0) {
|
||||
|
@ -19,31 +19,39 @@
|
||||
|
||||
package de.steamwar.bausystem.features.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.util.SelectCommand;
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
@ -71,7 +79,7 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "undo", description = "REGION_REGION_HELP_UNDO")
|
||||
public void undoCommand(@Validator("WORLD_EDIT") Player p) {
|
||||
public void undoCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) return;
|
||||
|
||||
@ -83,7 +91,7 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "redo", description = "REGION_REGION_HELP_REDO")
|
||||
public void redoCommand(@Validator("WORLD_EDIT") Player p) {
|
||||
public void redoCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
@ -97,7 +105,7 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "restore", description = "REGION_REGION_HELP_RESTORE")
|
||||
public void genericRestoreCommand(@Validator("WORLD_EDIT") Player p) {
|
||||
public void genericRestoreCommand(@Validator Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if(checkGlobalRegion(region, p)) return;
|
||||
|
||||
@ -114,7 +122,7 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "restore", description = "REGION_REGION_HELP_RESTORE_SCHEMATIC")
|
||||
public void schematicRestoreCommand(@Validator("WORLD_EDIT") Player p, SchematicNode node) {
|
||||
public void schematicRestoreCommand(@Validator Player p, SchematicNode node) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) return;
|
||||
|
||||
@ -164,36 +172,6 @@ public class RegionCommand extends SWCommand {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p);
|
||||
}
|
||||
|
||||
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE_INFO")
|
||||
@Register("type")
|
||||
public void changeTypeCommand(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName());
|
||||
}
|
||||
|
||||
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE")
|
||||
@Register("type")
|
||||
public void changeTypeCommand(@Validator("WORLD") Player p, @Mapper("regionTypeMapper") String s) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
Prototype prototype = Prototype.getByDisplayName(s);
|
||||
if (prototype == null) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p);
|
||||
} else {
|
||||
if (region.setPrototype(prototype)) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s);
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset"));
|
||||
} else {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO")
|
||||
@Register("skin")
|
||||
public void changeSkinCommand(Player p) {
|
||||
@ -210,7 +188,7 @@ public class RegionCommand extends SWCommand {
|
||||
|
||||
@Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN")
|
||||
@Register("skin")
|
||||
public void changeSkinCommand(@Validator("WORLD") Player p, @Mapper("skinTypeMapper") String s) {
|
||||
public void changeSkinCommand(@Validator Player p, @Mapper("skinTypeMapper") String s) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
@ -227,26 +205,106 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Mapper(value = "regionTypeMapper", local = true)
|
||||
private TypeMapper<String> regionTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
Player p = (Player) commandSender;
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList());
|
||||
}
|
||||
@Register(value = "copy", description = "REGION_REGION_HELP_COPY")
|
||||
public void copyCommand(@Validator Player p, @OptionalValue("") @StaticValue(value = {"", "-e", "-s"}, allowISE = true) int option) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
if (!region.hasType(RegionType.BUILD)) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_NO_BUILD", p);
|
||||
return;
|
||||
}
|
||||
if (region.getCopyPoint() == null) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_TP_UNKNOWN", p);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
return s.replace('_', ' ');
|
||||
}
|
||||
};
|
||||
Point minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
||||
Point maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
||||
switch (option) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.EXTENSION);
|
||||
maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.EXTENSION);
|
||||
break;
|
||||
case 2:
|
||||
Pair<Location, Location> selection = WorldEditUtils.getSelection(p);
|
||||
minPoint = Point.fromLocation(selection.getKey());
|
||||
maxPoint = Point.fromLocation(selection.getValue());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Clipboard clipboard = FlatteningWrapper.impl.copy(minPoint, maxPoint, region.getCopyPoint());
|
||||
WorldEdit.getInstance()
|
||||
.getSessionManager()
|
||||
.get(BukkitAdapter.adapt(p))
|
||||
.setClipboard(new ClipboardHolder(clipboard));
|
||||
BauSystem.MESSAGE.send("REGION_REGION_COPY_DONE", p);
|
||||
}
|
||||
|
||||
@Register(value = "paste", description = "REGION_REGION_HELP_PASTE")
|
||||
public void pasteCommand(@Validator Player p, @OptionalValue("") @StaticValue(value = {"", "-a", "-s", "-as", "-sa"}, allowISE = true) int options) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
if (!region.hasType(RegionType.BUILD)) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_NO_BUILD", p);
|
||||
return;
|
||||
}
|
||||
if (region.getCopyPoint() == null) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_TP_UNKNOWN", p);
|
||||
return;
|
||||
}
|
||||
|
||||
ClipboardHolder clipboardHolder = WorldEdit.getInstance()
|
||||
.getSessionManager()
|
||||
.get(BukkitAdapter.adapt(p))
|
||||
.getClipboard();
|
||||
|
||||
boolean selectPasted = false;
|
||||
boolean ignoreAir = false;
|
||||
switch (options) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
ignoreAir = true;
|
||||
break;
|
||||
case 2:
|
||||
selectPasted = true;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
selectPasted = true;
|
||||
ignoreAir = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
try (EditSession e = WorldEditUtils.getEditSession(p)) {
|
||||
Operations.completeBlindly(clipboardHolder.createPaste(e).ignoreAirBlocks(ignoreAir).to(toBlockVector3(region.getCopyPoint())).build());
|
||||
WorldEditUtils.addToPlayer(p, e);
|
||||
|
||||
if (selectPasted) {
|
||||
Clipboard clipboard = clipboardHolder.getClipboards().get(0);
|
||||
BlockVector3 minPointSelection = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(toBlockVector3(region.getCopyPoint()));
|
||||
BlockVector3 maxPointSelection = clipboard.getRegion().getMaximumPoint().subtract(clipboard.getOrigin()).add(toBlockVector3(region.getCopyPoint()));
|
||||
FlatteningWrapper.impl.setSelection(p, Point.fromBlockVector3(minPointSelection), Point.fromBlockVector3(maxPointSelection));
|
||||
}
|
||||
BauSystem.MESSAGE.send("REGION_REGION_PASTE_DONE", p);
|
||||
}
|
||||
}
|
||||
|
||||
private BlockVector3 toBlockVector3(Point point) {
|
||||
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
|
||||
}
|
||||
|
||||
|
||||
@Mapper(value = "skinTypeMapper", local = true)
|
||||
private TypeMapper<String> skinTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@ -266,18 +324,4 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Validator(value = "WORLD", local = true)
|
||||
public TypeValidator<Player> worldValidator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_REGION_NO_PERMS");
|
||||
};
|
||||
}
|
||||
|
||||
@Validator(value = "WORLD_EDIT", local = true)
|
||||
public TypeValidator<Player> worldEditValidator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_REGION_NO_PERMS");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -97,13 +97,6 @@ public class ResetCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_RESET_NO_PERMS");
|
||||
};
|
||||
}
|
||||
|
||||
private Region regionCheck(Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region == GlobalRegion.getInstance()) {
|
||||
|
@ -157,11 +157,4 @@ public class TNTCommand extends SWCommand {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TNT_NO_PERMS");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -157,11 +157,6 @@ public class TestblockCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "REGION_TB_NO_PERMS");
|
||||
}
|
||||
|
||||
private Region regionCheck(Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (!region.hasType(RegionType.TESTBLOCK)) {
|
||||
|
@ -57,6 +57,6 @@ public class FireBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLD;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class FreezeBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLD;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ public class ProtectBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLDEDIT;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,6 @@ public class ResetBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLDEDIT;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,6 @@ public class TestblockBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLDEDIT;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,6 @@ public class TntBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.WORLD;
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class ScriptCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
public void genericCommand(@Validator Player player) {
|
||||
ScriptGUI.open(player);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.bausystem.features.script;
|
||||
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -42,6 +44,8 @@ public class ScriptListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) {
|
||||
return;
|
||||
@ -68,6 +72,13 @@ public class ScriptListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
ScriptRunner.updateGlobalScript(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(ScriptRunner::remove);
|
||||
event.getNewBuilder().forEach(ScriptRunner::updateGlobalScript);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.script.event;
|
||||
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -41,6 +42,7 @@ public class CommandListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
String[] split = event.getMessage().split(" ");
|
||||
if (calledCommands.getOrDefault(event.getPlayer(), new HashSet<>()).contains(split[0])) {
|
||||
return;
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.script.event;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||
import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin;
|
||||
import de.steamwar.bausystem.features.script.lua.libs.StorageLib;
|
||||
@ -64,17 +65,20 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL, event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
StorageLib.removePlayer(event.getPlayer());
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (LAST_FS.containsKey(event.getPlayer())) {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DoubleSwap, LuaValue.NIL, event);
|
||||
@ -86,6 +90,7 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
LuaTable table = new LuaTable();
|
||||
table.set("x", event.getBlock().getX());
|
||||
table.set("y", event.getBlock().getY());
|
||||
@ -96,6 +101,7 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
LuaTable table = new LuaTable();
|
||||
table.set("x", event.getBlock().getX());
|
||||
table.set("y", event.getBlock().getY());
|
||||
@ -108,6 +114,7 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (ignore.remove(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
@ -125,6 +132,7 @@ public class EventListener implements Listener {
|
||||
table.set("blockY", event.getClickedBlock().getY());
|
||||
table.set("blockZ", event.getClickedBlock().getZ());
|
||||
table.set("blockFace", event.getBlockFace().name());
|
||||
table.set("blockType", event.getClickedBlock().getType().name());
|
||||
} else {
|
||||
table.set("hasBlock", LuaValue.valueOf(false));
|
||||
}
|
||||
@ -144,6 +152,7 @@ public class EventListener implements Listener {
|
||||
Region tntRegion = Region.getRegion(event.getLocation());
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL, event);
|
||||
}
|
||||
@ -165,6 +174,7 @@ public class EventListener implements Listener {
|
||||
boolean inBuild = event.blockList().stream().anyMatch(block -> tntRegion.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION));
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||
if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table, event);
|
||||
if (inBuild) {
|
||||
@ -176,6 +186,7 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
ignore.add(event.getPlayer());
|
||||
LuaTable table = new LuaTable();
|
||||
table.set("type", event.getItemDrop().getItemStack().getType().name());
|
||||
@ -185,6 +196,7 @@ public class EventListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(!Permission.BUILD.hasPermission(player)) continue;
|
||||
LuaTable table = new LuaTable();
|
||||
table.set("type", event.getEntityType().name());
|
||||
ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table, event);
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.script.event;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Plain;
|
||||
@ -36,6 +37,7 @@ public class HotkeyListener implements PluginMessageListener, Plain {
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if(!Permission.BUILD.hasPermission(player)) return;
|
||||
if (!channel.equals("sw:hotkeys")) return;
|
||||
if (message.length < 5) return;
|
||||
int action = message[4] & 0xFF;
|
||||
|
@ -22,14 +22,19 @@ package de.steamwar.bausystem.features.script.lua;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.script.ScriptRunner;
|
||||
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
|
||||
import de.steamwar.bausystem.features.world.WorldEditListener;
|
||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -40,11 +45,10 @@ import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.OneArgFunction;
|
||||
import org.luaj.vm2.lib.ThreeArgFunction;
|
||||
import org.luaj.vm2.lib.TwoArgFunction;
|
||||
import org.luaj.vm2.lib.VarArgFunction;
|
||||
import org.luaj.vm2.lib.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -103,14 +107,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||
double x = arg1.checkdouble();
|
||||
double y = arg2.checkdouble();
|
||||
double z = arg3.checkdouble();
|
||||
|
||||
Location loc = new Location(player.getWorld(), x, y, z);
|
||||
|
||||
return tableOf(new LuaValue[] {
|
||||
valueOf("x"), valueOf(loc.getBlockX()),
|
||||
valueOf("y"), valueOf(loc.getBlockY()),
|
||||
valueOf("z"), valueOf(loc.getBlockZ())
|
||||
});
|
||||
return pos(x, y, z);
|
||||
}
|
||||
});
|
||||
env.set("exec", new VarArgFunction() {
|
||||
@ -123,6 +120,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||
return LuaValue.NIL;
|
||||
}
|
||||
|
||||
command = preprocessEvent.getMessage().substring(1);
|
||||
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
|
||||
String[] commandSplit = command.split(" ");
|
||||
if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) {
|
||||
@ -167,11 +165,86 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
|
||||
env.set("rawget", NIL);
|
||||
env.set("rawlen", NIL);
|
||||
env.set("rawset", NIL);
|
||||
env.set("setmetatable", NIL);
|
||||
env.set("xpcall", NIL);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LuaTable pos(double x, double y, double z) {
|
||||
LuaTable position = new LuaTable();
|
||||
position.set("x", x);
|
||||
position.set("y", y);
|
||||
position.set("z", z);
|
||||
|
||||
position.set("add", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
LuaTable table = luaValue.checktable();
|
||||
double dx = table.get("x").checkdouble();
|
||||
double dy = table.get("y").checkdouble();
|
||||
double dz = table.get("z").checkdouble();
|
||||
return pos(x + dx, y + dy, z + dz);
|
||||
}
|
||||
});
|
||||
|
||||
position.set("subtract", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
LuaTable table = luaValue.checktable();
|
||||
double dx = table.get("x").checkdouble();
|
||||
double dy = table.get("y").checkdouble();
|
||||
double dz = table.get("z").checkdouble();
|
||||
return pos(x - dx, y - dy, z - dz);
|
||||
}
|
||||
});
|
||||
|
||||
position.set("addX", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x + luaValue.checkdouble(), y, z);
|
||||
}
|
||||
});
|
||||
position.set("subtractX", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x - luaValue.checkdouble(), y, z);
|
||||
}
|
||||
});
|
||||
position.set("addY", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y + luaValue.checkdouble(), z);
|
||||
}
|
||||
});
|
||||
position.set("subtractY", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y - luaValue.checkdouble(), z);
|
||||
}
|
||||
});
|
||||
position.set("addZ", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y, z + luaValue.checkdouble());
|
||||
}
|
||||
});
|
||||
position.set("subtractZ", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue luaValue) {
|
||||
return pos(x, y, z - luaValue.checkdouble());
|
||||
}
|
||||
});
|
||||
|
||||
position.set("blockPos", new ZeroArgFunction() {
|
||||
@Override
|
||||
public LuaValue call() {
|
||||
Location location = new Location(Bukkit.getWorlds().get(0), x, y, z);
|
||||
return pos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
});
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static String varArgsToString(Varargs args) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 1; i <= args.narg(); i++) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -44,6 +45,12 @@ public class PlayerLib implements LuaLib {
|
||||
table.set("chat", new Print(player));
|
||||
table.set("actionbar", new SendActionbar(player));
|
||||
|
||||
table.set("pos", getter(() -> {
|
||||
return SteamWarLuaPlugin.pos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
|
||||
}));
|
||||
table.set("blockPos", getter(() -> {
|
||||
return SteamWarLuaPlugin.pos(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
}));
|
||||
table.set("x", getterAndSetter("x", () -> player.getLocation().getX(), x -> {
|
||||
Location location = player.getLocation();
|
||||
location.setX(x);
|
||||
|
@ -20,9 +20,6 @@
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.features.loader.Loader;
|
||||
import de.steamwar.bausystem.features.tracer.record.ActiveTracer;
|
||||
import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder;
|
||||
import de.steamwar.bausystem.features.tracer.record.Recorder;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
@ -71,13 +68,13 @@ public class RegionLib implements LuaLib {
|
||||
table.set("freeze", getter(() -> region.get().getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE));
|
||||
table.set("protect", getter(() -> region.get().getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE));
|
||||
|
||||
LuaValue traceLib = LuaValue.tableOf();
|
||||
traceLib.set("active", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof ActiveTracer));
|
||||
traceLib.set("auto", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof AutoTraceRecorder));
|
||||
traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region.get()).scriptState()));
|
||||
traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region.get()).scriptTime()));
|
||||
//LuaValue traceLib = LuaValue.tableOf();
|
||||
//traceLib.set("active", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof ActiveTracer));
|
||||
//traceLib.set("auto", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof AutoTraceRecorder));
|
||||
//traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region.get()).scriptState()));
|
||||
//traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region.get()).scriptTime()));
|
||||
|
||||
table.set("trace", traceLib);
|
||||
//table.set("trace", traceLib);
|
||||
|
||||
Loader loader = Loader.getLoader(player);
|
||||
table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name()));
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.features.world.BauScoreboard;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.TwoArgFunction;
|
||||
import org.luaj.vm2.lib.VarArgFunction;
|
||||
|
||||
@Linked
|
||||
public class ScoreboardLib implements LuaLib {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "scoreboard";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuaTable get(Player player) {
|
||||
LuaTable luaTable = new LuaTable();
|
||||
|
||||
LuaTable groups = new LuaTable();
|
||||
for (ScoreboardElement.ScoreboardGroup group : ScoreboardElement.ScoreboardGroup.values()) {
|
||||
groups.set(group.name(), group.ordinal());
|
||||
}
|
||||
luaTable.set("group", groups);
|
||||
|
||||
luaTable.set("element", new VarArgFunction() {
|
||||
@Override
|
||||
public Varargs invoke(Varargs varargs) {
|
||||
if (varargs.narg() < 2) {
|
||||
return NIL;
|
||||
}
|
||||
String elementKey = varargs.arg(1).checkjstring();
|
||||
ScoreboardElement.ScoreboardGroup elementGroup = ScoreboardElement.ScoreboardGroup.values()[varargs.arg(2).checkint()];
|
||||
int priority = varargs.narg() > 2 ? varargs.arg(2).checkint() : Integer.MAX_VALUE;
|
||||
|
||||
return new VarArgFunction() {
|
||||
@Override
|
||||
public Varargs invoke(Varargs args) {
|
||||
if (args.narg() == 0) {
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, null);
|
||||
} else {
|
||||
BauScoreboard.setAdditionalElement(player, elementKey, elementGroup, priority, args.arg1().checkjstring());
|
||||
}
|
||||
return NIL;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
return luaTable;
|
||||
}
|
||||
}
|
@ -20,11 +20,15 @@
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.loader.Loader;
|
||||
import de.steamwar.bausystem.features.loader.LoaderRecorder;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
@ -46,10 +50,14 @@ public class ServerLib implements LuaLib {
|
||||
public LuaTable get(Player player) {
|
||||
LuaTable serverLib = LuaValue.tableOf();
|
||||
serverLib.set("time", getter(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime())));
|
||||
serverLib.set("onlinePlayerCount", getter(Bukkit.getOnlinePlayers()::size));
|
||||
serverLib.set("ticks", getter(TPSUtils.currentTick));
|
||||
serverLib.set("getBlockAt", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg1) {
|
||||
if (!Permission.SUPERVISOR.hasPermission(player)) {
|
||||
return LuaValue.NIL;
|
||||
}
|
||||
LuaTable pos = arg1.checktable();
|
||||
return valueOf(player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).getType().name());
|
||||
}
|
||||
@ -57,6 +65,9 @@ public class ServerLib implements LuaLib {
|
||||
serverLib.set("setBlockAt", new TwoArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||
if (!Permission.SUPERVISOR.hasPermission(player)) {
|
||||
return LuaValue.NIL;
|
||||
}
|
||||
LuaTable pos = arg1.checktable();
|
||||
LuaString material = arg2.checkstring();
|
||||
Material mat = SWItem.getMaterial(material.tojstring());
|
||||
@ -67,17 +78,19 @@ public class ServerLib implements LuaLib {
|
||||
return NIL;
|
||||
}
|
||||
});
|
||||
|
||||
LuaValue tpsLib = LuaValue.tableOf();
|
||||
tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND)));
|
||||
tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS)));
|
||||
tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)));
|
||||
tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)));
|
||||
tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)));
|
||||
tpsLib.set("current", getter(TPSWatcher::getTPS));
|
||||
// tpsLib.set("limit", getter(TPSLimitUtils::getCurrentTPSLimit));
|
||||
|
||||
serverLib.set("tps", tpsLib);
|
||||
serverLib.set("interactAt", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg1) {
|
||||
LuaTable pos = arg1.checktable();
|
||||
Block block = player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint());
|
||||
LoaderRecorder.getLoaderInteractionElement(block, (loaderInteractionElement, s) -> {
|
||||
loaderInteractionElement.execute(aLong -> {
|
||||
// Ignore
|
||||
});
|
||||
});
|
||||
return NIL;
|
||||
}
|
||||
});
|
||||
return serverLib;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import com.google.gson.*;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Disable;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
@ -54,6 +55,7 @@ public class StorageLib implements LuaLib, Enable, Disable {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (Core.getVersion() <= 15) return;
|
||||
if (!storageDirectory.exists()) storageDirectory.mkdirs();
|
||||
|
||||
try {
|
||||
@ -129,6 +131,7 @@ public class StorageLib implements LuaLib, Enable, Disable {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (Core.getVersion() <= 15) return;
|
||||
if (!storageDirectory.exists()) storageDirectory.mkdirs();
|
||||
try {
|
||||
FileWriter fileWriter = new FileWriter(new File(storageDirectory, "global.json"));
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.script.lua.libs;
|
||||
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSSystem;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
|
||||
@Linked
|
||||
public class TpsLib implements LuaLib {
|
||||
|
||||
@LinkedInstance
|
||||
public TPSSystem tpsSystem;
|
||||
|
||||
@Override
|
||||
public Class<? extends LuaLib> parent() {
|
||||
return ServerLib.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "tps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuaTable get(Player player) {
|
||||
LuaTable tpsLib = new LuaTable();
|
||||
tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND)));
|
||||
tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS)));
|
||||
tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)));
|
||||
tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)));
|
||||
tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)));
|
||||
tpsLib.set("current", getter(TPSWatcher::getTPS));
|
||||
tpsLib.set("limit", getter(tpsSystem::getCurrentTPSLimit));
|
||||
return tpsLib;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.shieldprinting;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.shieldprinting.impl.*;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
@ -47,7 +48,6 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -259,18 +259,14 @@ public class ShieldPrinting implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) return;
|
||||
if (event.getItem() == null) return;
|
||||
if (Region.getRegion(event.getClickedBlock().getLocation()) != region) return;
|
||||
Vector vector = event.getClickedBlock().getLocation().toVector();
|
||||
if (!shieldMap.containsKey(vector)) return;
|
||||
event.getClickedBlock().setType(Material.AIR);
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
updateBossbar(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
updateBossbar(event.getPlayer());
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getNewSpectator().forEach(player -> BossBarService.instance.remove(player, region, "shieldprinting"));
|
||||
event.getNewBuilder().forEach(this::updateBossbar);
|
||||
}
|
||||
|
||||
private void updateBossbars() {
|
||||
|
@ -26,9 +26,7 @@ import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -108,8 +106,8 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||
messageSender.send("SHIELD_PRINTING_DISALLOWED", player);
|
||||
if (!Permission.BUILD.hasPermission(player)) {
|
||||
messageSender.send("NO_PERMISSION", player);
|
||||
return false;
|
||||
}
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
@ -120,20 +118,4 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) {
|
||||
return;
|
||||
}
|
||||
Region region = Region.getRegion(event.getClickedBlock().getLocation());
|
||||
if (region.isGlobal()) {
|
||||
return;
|
||||
}
|
||||
ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region);
|
||||
if (shieldPrinting == null) {
|
||||
return;
|
||||
}
|
||||
shieldPrinting.onPlayerInteract(event);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@Linked
|
||||
public class SimulatorBauGuiItem extends BauGuiItem {
|
||||
|
||||
public SimulatorBauGuiItem() {
|
||||
super(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(Player player) {
|
||||
ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_GUI_ITEM_NAME", player)).getItemStack();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.setCustomModelData(1);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean click(ClickType click, Player p) {
|
||||
p.closeInventory();
|
||||
p.performCommand("sim");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission permission() {
|
||||
return Permission.BUILD;
|
||||
}
|
||||
}
|
@ -102,11 +102,4 @@ public class SimulatorCommand extends SWCommand {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "SIMULATOR_NO_PERMS");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,13 @@ package de.steamwar.bausystem.features.simulator;
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
@ -34,6 +37,7 @@ import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.entity.REntity;
|
||||
@ -58,10 +62,7 @@ import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -77,6 +78,7 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
||||
private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
|
||||
private final Set<Player> calculating = new HashSet<>();
|
||||
|
||||
public static boolean isSimulatorItem(ItemStack itemStack) {
|
||||
return ItemUtils.isItem(itemStack, "simulator");
|
||||
@ -94,6 +96,7 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 0);
|
||||
@ -101,20 +104,30 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
calcCursor(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getChanged().forEach(this::calcCursor);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
cursorType.remove(event.getPlayer());
|
||||
cursors.remove(event.getPlayer());
|
||||
synchronized (calculating) {
|
||||
calculating.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<Player, Long> LAST_SNEAKS = new HashMap<>();
|
||||
@ -141,11 +154,18 @@ public class SimulatorCursor implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void calcCursor(Player player) {
|
||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
||||
public void calcCursor(Player player) {
|
||||
synchronized (calculating) {
|
||||
if (calculating.contains(player)) return;
|
||||
calculating.add(player);
|
||||
}
|
||||
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Simulator simulator = SimulatorStorage.getSimulator(player);
|
||||
@ -160,10 +180,16 @@ public class SimulatorCursor implements Listener {
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eOpen Simulator");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
showCursor(player, rayTraceResult, simulator != null);
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean removeCursor(Player player) {
|
||||
@ -216,7 +242,7 @@ public class SimulatorCursor implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
public static Vector getPosFree(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
@ -256,7 +282,7 @@ public class SimulatorCursor implements Listener {
|
||||
return pos;
|
||||
}
|
||||
|
||||
private static Vector getPosRedstoneBlock(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
private static Vector getPosBlockAligned(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
@ -295,8 +321,9 @@ public class SimulatorCursor implements Listener {
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CursorType {
|
||||
TNT(Material.TNT, SimulatorCursor::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||
TNT(Material.TNT, SimulatorCursor::getPosFree, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosBlockAligned, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||
OBSERVER(Material.OBSERVER, SimulatorCursor::getPosBlockAligned, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())),
|
||||
;
|
||||
|
||||
private Material material;
|
||||
@ -308,12 +335,16 @@ public class SimulatorCursor implements Listener {
|
||||
if (this == TNT) {
|
||||
return REDSTONE_BLOCK;
|
||||
}
|
||||
if (this == REDSTONE_BLOCK) {
|
||||
return OBSERVER;
|
||||
}
|
||||
return TNT;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||
return;
|
||||
}
|
||||
|
@ -84,7 +84,9 @@ public class SimulatorStorage implements Enable {
|
||||
SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader();
|
||||
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
|
||||
|
||||
for (File file : simulatorsDir.listFiles()) {
|
||||
File[] files = simulatorsDir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
try {
|
||||
List<Simulator> simulators = simFormatSimulatorLoader.load(file)
|
||||
.orElse(null);
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.data;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class SimulatorBlockAlignedElement<T extends SimulatorPhase> extends SimulatorElement<T> {
|
||||
|
||||
protected SimulatorBlockAlignedElement(Material material, Vector position) {
|
||||
super(material, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canBeInGroup(SimulatorGroup simulatorGroup) {
|
||||
return simulatorGroup.getElements().stream().allMatch(SimulatorBlockAlignedElement.class::isInstance);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.data.observer;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorObserverGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public final class ObserverElement extends SimulatorBlockAlignedElement<ObserverPhase> {
|
||||
|
||||
public ObserverElement(Vector position) {
|
||||
super(Material.OBSERVER, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Player player) {
|
||||
return "Observer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getWorldMaterial() {
|
||||
return Material.OBSERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getWorldDisabledMaterial() {
|
||||
return Material.GRAY_STAINED_GLASS;
|
||||
}
|
||||
|
||||
public void toSimulatorActions(BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||
if (disabled) return;
|
||||
phases.forEach(phase -> {
|
||||
phase.toSimulatorActions(position.clone(), tickStart, tickEnd);
|
||||
});
|
||||
|
||||
int end = phases.stream().mapToInt(SimulatorPhase::getTickOffset).max().orElse(0) + 4;
|
||||
AtomicReference<BlockState> blockState = new AtomicReference<>();
|
||||
tickStart.accept(0, new SimulatorAction(-100, 1) {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
blockState.set(block.getState());
|
||||
block.setType(Material.OBSERVER, false);
|
||||
}
|
||||
});
|
||||
tickEnd.accept(end, new SimulatorAction(0, 1) {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
BlockState oldState = blockState.get();
|
||||
if (oldState != null) {
|
||||
oldState.update(true, true);
|
||||
} else {
|
||||
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) {
|
||||
new SimulatorObserverGui(player, simulator, group, this, back).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Observer";
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.data.observer;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.type.Observer;
|
||||
import org.bukkit.util.Vector;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@NoArgsConstructor
|
||||
public final class ObserverPhase extends SimulatorPhase {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private BlockFace orientation = BlockFace.UP;
|
||||
|
||||
public ObserverPhase(int tickOffset) {
|
||||
this.tickOffset = tickOffset;
|
||||
}
|
||||
|
||||
{
|
||||
this.lifetime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||
Observer observer = (Observer) Material.OBSERVER.createBlockData();
|
||||
observer.setFacing(orientation.getOppositeFace());
|
||||
observer.setPowered(true);
|
||||
|
||||
tickStart.accept(tickOffset, new SimulatorAction(order, 1) {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
Block updateBlock = block.getRelative(orientation);
|
||||
BlockState state = updateBlock.getState();
|
||||
updateBlock.setType(Material.SPONGE, true);
|
||||
block.setBlockData(observer, true);
|
||||
state.update(true, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveExtra(YAPIONObject phaseObject) {
|
||||
phaseObject.add("orientation", orientation.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtra(YAPIONObject phaseObject) {
|
||||
orientation = BlockFace.valueOf(phaseObject.getPlainValue("orientation"));
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@
|
||||
package de.steamwar.bausystem.features.simulator.data.redstone;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorBlockAlignedElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorRedstoneGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
@ -28,7 +28,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class RedstoneElement extends SimulatorElement<RedstonePhase> {
|
||||
public final class RedstoneElement extends SimulatorBlockAlignedElement<RedstonePhase> {
|
||||
|
||||
public RedstoneElement(Vector position) {
|
||||
super(Material.REDSTONE_BLOCK, position);
|
||||
@ -49,11 +49,6 @@ public final class RedstoneElement extends SimulatorElement<RedstonePhase> {
|
||||
return Material.WHITE_STAINED_GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeInGroup(SimulatorGroup simulatorGroup) {
|
||||
return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getWorldPos() {
|
||||
return position.clone().add(new Vector(0.5, 0, 0.5));
|
||||
|
@ -54,7 +54,7 @@ public final class RedstonePhase extends SimulatorPhase {
|
||||
block.setType(Material.REDSTONE_BLOCK);
|
||||
}
|
||||
});
|
||||
tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) {
|
||||
tickStart.accept(tickOffset + lifetime, new SimulatorAction(ORDER_LIMIT + 1, 1) {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
BlockState state = blockState.get();
|
||||
|
@ -26,12 +26,18 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.inventory.InvCallback;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
public final class TNTElement extends SimulatorElement<TNTPhase> {
|
||||
|
||||
public static final double SUB_PIXEL = 0.00999999046326;
|
||||
@Getter
|
||||
private final Vector alignment = new Vector();
|
||||
|
||||
public TNTElement(Vector position) {
|
||||
super(Material.TNT, position);
|
||||
}
|
||||
@ -47,26 +53,16 @@ public final class TNTElement extends SimulatorElement<TNTPhase> {
|
||||
position.setZ(position.getZ() + z);
|
||||
}
|
||||
|
||||
public void align(Vector offset) {
|
||||
if (offset.getX() != 0) {
|
||||
if (position.getX() - (int) position.getX() == 0.49) {
|
||||
position.setX(position.getX() + 0.02);
|
||||
}
|
||||
if (position.getX() - (int) position.getX() == -0.49) {
|
||||
position.setX(position.getX() - 0.02);
|
||||
}
|
||||
position.setX(position.getBlockX() + offset.getX());
|
||||
}
|
||||
public void alignX(int direction) {
|
||||
position.setX(position.getX() - SUB_PIXEL * alignment.getX());
|
||||
alignment.setX(direction);
|
||||
position.setX(position.getX() + SUB_PIXEL * alignment.getX());
|
||||
}
|
||||
|
||||
if (offset.getZ() != 0) {
|
||||
if (position.getZ() - (int) position.getZ() == 0.49) {
|
||||
position.setZ(position.getZ() + 0.02);
|
||||
}
|
||||
if (position.getZ() - (int) position.getZ() == -0.49) {
|
||||
position.setZ(position.getZ() - 0.02);
|
||||
}
|
||||
position.setZ(position.getBlockZ() + offset.getZ());
|
||||
}
|
||||
public void alignZ(int direction) {
|
||||
position.setZ(position.getZ() - SUB_PIXEL * alignment.getZ());
|
||||
alignment.setZ(direction);
|
||||
position.setZ(position.getZ() + SUB_PIXEL * alignment.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,4 +98,16 @@ public final class TNTElement extends SimulatorElement<TNTPhase> {
|
||||
public String getType() {
|
||||
return "TNT";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveExtra(YAPIONObject elementObject) {
|
||||
elementObject.add("alignmentX", alignment.getX());
|
||||
elementObject.add("alignmentZ", alignment.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtra(YAPIONObject elementObject) {
|
||||
alignment.setX(elementObject.getDoubleOrSetDefault("alignmentX", 0));
|
||||
alignment.setZ(elementObject.getDoubleOrSetDefault("alignmentZ", 0));
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,13 @@ package de.steamwar.bausystem.features.simulator.data.tnt;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -59,7 +63,9 @@ public final class TNTPhase extends SimulatorPhase {
|
||||
tickStart.accept(tickOffset, new SimulatorAction(order, count) {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class);
|
||||
Location location = position.toLocation(world);
|
||||
if (Region.getRegion(location).get(Flag.FREEZE) == FreezeMode.ACTIVE) return;
|
||||
TNTPrimed tnt = world.spawn(location, TNTPrimed.class);
|
||||
if (!xJump) tnt.setVelocity(tnt.getVelocity().setX(0));
|
||||
if (!yJump) tnt.setVelocity(tnt.getVelocity().setY(0));
|
||||
if (!zJump) tnt.setVelocity(tnt.getVelocity().setZ(0));
|
||||
|
@ -23,8 +23,7 @@ import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.features.tracer.record.Recorder;
|
||||
import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder;
|
||||
import de.steamwar.bausystem.features.tracer.TraceRecorder;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.TickEndEvent;
|
||||
import de.steamwar.bausystem.utils.TickStartEvent;
|
||||
@ -69,6 +68,20 @@ public class SimulatorExecutor implements Listener {
|
||||
@Override
|
||||
public void accept(World world) {
|
||||
currentlyRunning.remove(simulator);
|
||||
|
||||
if (simulator.isAutoTrace()) {
|
||||
simulator.getGroups()
|
||||
.stream()
|
||||
.map(SimulatorGroup::getElements)
|
||||
.flatMap(List::stream)
|
||||
.map(SimulatorElement::getPosition)
|
||||
.map(pos -> pos.toLocation(WORLD))
|
||||
.map(Region::getRegion)
|
||||
.distinct()
|
||||
.forEach(region -> {
|
||||
TraceRecorder.instance.stopRecording(region);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -82,9 +95,7 @@ public class SimulatorExecutor implements Listener {
|
||||
.map(Region::getRegion)
|
||||
.distinct()
|
||||
.forEach(region -> {
|
||||
if (Recorder.INSTANCE.isDisabled(region)) {
|
||||
Recorder.INSTANCE.set(region, new SingleTraceRecorder(region));
|
||||
}
|
||||
TraceRecorder.instance.startRecording(region);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
@ -97,41 +97,69 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
if (allTNT) {
|
||||
// Subpixel Alignment
|
||||
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||
tnt.align(new Vector(0.5, 0, 0.5));
|
||||
});
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
tntElement.alignX(0);
|
||||
tntElement.alignZ(0);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
// Z
|
||||
inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||
tnt.align(new Vector(0, 0, 0.49));
|
||||
});
|
||||
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != -1) tntElement.alignZ(-1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
negativZItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == -1));
|
||||
inventory.setItem(20, negativZItem);
|
||||
|
||||
inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||
tnt.align(new Vector(0, 0, 0.51));
|
||||
});
|
||||
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != 1) tntElement.alignZ(1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
positivZItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == 1));
|
||||
inventory.setItem(22, positivZItem);
|
||||
|
||||
// X
|
||||
inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||
tnt.align(new Vector(0.49, 0, 0));
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != -1) tntElement.alignX(-1);
|
||||
});
|
||||
|
||||
inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||
tnt.align(new Vector(0.51, 0, 0));
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
negativXItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
inventory.setItem(12, negativXItem);
|
||||
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != 1) tntElement.alignX(1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
positivXItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
inventory.setItem(30, positivXItem);
|
||||
}
|
||||
|
||||
//Pos X
|
||||
@ -140,6 +168,14 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(number, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0);
|
||||
@ -152,6 +188,14 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(0, number, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0);
|
||||
@ -164,6 +208,14 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(0, 0, number);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1);
|
||||
|
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.gui;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
|
||||
private final SimulatorGroup parent;
|
||||
private final ObserverElement observer;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorObserverGui(Player player, Simulator simulator, SimulatorGroup parent, ObserverElement observer, SimulatorBaseGui back) {
|
||||
super(player, simulator, 6 * 9, observer.getPhases());
|
||||
this.parent = parent;
|
||||
this.observer = observer;
|
||||
this.back = back;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String baseTitle() {
|
||||
return "Observer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headerAndFooter() {
|
||||
if (observer.getPhases().isEmpty()) {
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
return;
|
||||
}
|
||||
|
||||
observer.sort();
|
||||
|
||||
// Back Arrow
|
||||
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
|
||||
if (parent.getElements().contains(observer)) {
|
||||
back.open();
|
||||
} else {
|
||||
SimulatorGroup newParent = observer.getGroup(simulator);
|
||||
if (newParent == null) {
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
if (newParent.getElements().size() == 1) {
|
||||
simulatorGui.open();
|
||||
} else {
|
||||
new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
observer.getPhases().clear();
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
// Material Chooser
|
||||
inventory.setItem(4, observer.toItem(player, clickType -> {
|
||||
new SimulatorMaterialGui(player, simulator, observer::getMaterial, observer::setMaterial, this).open();
|
||||
}));
|
||||
|
||||
// Settings
|
||||
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
new SimulatorObserverSettingsGui(player, simulator, observer, this).open();
|
||||
}));
|
||||
|
||||
// Enable/Disable
|
||||
inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
observer.setDisabled(!observer.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
// Group chooser
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, observer, observer.getGroup(simulator), this).open();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWItem[] column(ObserverPhase observerPhase, int index) {
|
||||
int min;
|
||||
if (index > 0) {
|
||||
min = data.get(index - 1).getTickOffset() + 4;
|
||||
} else {
|
||||
min = 0;
|
||||
}
|
||||
|
||||
int max;
|
||||
if (index < data.size() - 1) {
|
||||
max = data.get(index + 1).getTickOffset() - 4;
|
||||
} else {
|
||||
max = Integer.MAX_VALUE - 4;
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7Time§8:§e " + observerPhase.getTickOffset());
|
||||
lore.add("§7Order§8:§e " + observerPhase.getOrder());
|
||||
lore.add("");
|
||||
lore.add("§7Orientation§8:§e " + observerPhase.getOrientation().name());
|
||||
lore.add("");
|
||||
lore.add("§7Click§8:§e Edit");
|
||||
lore.add("§7Middle-Click§8:§e Remove");
|
||||
SWItem observer = new SWItem(Material.OBSERVER, "§eObserver", lore, false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.observer.getPhases().remove(observerPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
} else {
|
||||
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
|
||||
}
|
||||
});
|
||||
observer.getItemStack().setAmount(Math.min(Math.max(observerPhase.getTickOffset(), 1), 64));
|
||||
|
||||
Supplier<Integer> getter = observerPhase::getTickOffset;
|
||||
Consumer<Integer> setter = observerPhase::setTickOffset;
|
||||
return new SWItem[] {
|
||||
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}),
|
||||
observer,
|
||||
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
||||
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}),
|
||||
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWItem[] lastColumn() {
|
||||
return new SWItem[]{
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}),
|
||||
new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}),
|
||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private void addNewPhase(boolean shift) {
|
||||
ObserverPhase lastElement = observer.getPhases().get(observer.getPhases().size() - 1);
|
||||
ObserverPhase newPhase = new ObserverPhase(lastElement.getTickOffset() + 4);
|
||||
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||
scroll += 2;
|
||||
observer.add(newPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.gui;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
private final ObserverElement observerElement;
|
||||
private final ObserverPhase observer;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer, SimulatorBaseGui back) {
|
||||
super(player, simulator, 5 * 9);
|
||||
this.observerElement = observerElement;
|
||||
this.observer = observer;
|
||||
this.back = back;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String title() {
|
||||
return "Observer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate() {
|
||||
if (!observerElement.getPhases().contains(observer)) {
|
||||
back.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Back Arrow
|
||||
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
|
||||
back.open();
|
||||
}));
|
||||
|
||||
// Material Chooser
|
||||
inventory.setItem(4, observerElement.toItem(player, clickType -> {
|
||||
new SimulatorMaterialGui(player, simulator, observerElement::getMaterial, observerElement::setMaterial, this).open();
|
||||
}));
|
||||
|
||||
// Delete
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
observerElement.getPhases().remove(observer);
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
int index = observerElement.getPhases().indexOf(observer);
|
||||
int min;
|
||||
if (index > 0) {
|
||||
ObserverPhase previous = observerElement.getPhases().get(index - 1);
|
||||
min = previous.getTickOffset() + 4;
|
||||
} else {
|
||||
min = 0;
|
||||
}
|
||||
|
||||
int max;
|
||||
if (index < observerElement.getPhases().size() - 1) {
|
||||
ObserverPhase next = observerElement.getPhases().get(index + 1);
|
||||
max = next.getTickOffset() - 4;
|
||||
} else {
|
||||
max = Integer.MAX_VALUE - 4;
|
||||
}
|
||||
|
||||
//Tick Offset
|
||||
int offset = observer.getTickOffset();
|
||||
inventory.setItem(10, SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
observer.setTickOffset(Math.min(Math.max(integer, min), max));
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64)));
|
||||
inventory.setItem(19, offsetItem);
|
||||
|
||||
inventory.setItem(28, SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
//Order
|
||||
int order = observer.getOrder();
|
||||
inventory.setItem(13, SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
|
||||
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> {
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT) return false;
|
||||
observer.setOrder(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
|
||||
});
|
||||
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
|
||||
inventory.setItem(22, orderItem);
|
||||
|
||||
inventory.setItem(31, SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
// Update orientation
|
||||
inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> {
|
||||
}));
|
||||
inventory.setItem(15, new SWItem(observer.getOrientation() == BlockFace.UP ? Material.LIME_CONCRETE : Material.GRAY_CONCRETE, "§eUp", clickType -> {
|
||||
observer.setOrientation(BlockFace.UP);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(observer.getOrientation() == BlockFace.DOWN ? Material.RED_CONCRETE : Material.GRAY_CONCRETE, "§eDown", clickType -> {
|
||||
observer.setOrientation(BlockFace.DOWN);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(16, new SWItem(observer.getOrientation() == BlockFace.NORTH ? Material.LIME_WOOL : Material.GRAY_WOOL, "§eNorth", clickType -> {
|
||||
observer.setOrientation(BlockFace.NORTH);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(observer.getOrientation() == BlockFace.SOUTH ? Material.RED_WOOL : Material.GRAY_WOOL, "§eSouth", clickType -> {
|
||||
observer.setOrientation(BlockFace.SOUTH);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(24, new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> {
|
||||
observer.setOrientation(BlockFace.EAST);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(26, new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> {
|
||||
observer.setOrientation(BlockFace.WEST);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.simulator.gui;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimulatorObserverSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
private final ObserverElement observer;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorObserverSettingsGui(Player player, Simulator simulator, ObserverElement observer, SimulatorBaseGui back) {
|
||||
super(player, simulator, 5 * 9);
|
||||
this.observer = observer;
|
||||
this.back = back;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String title() {
|
||||
return "Observer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate() {
|
||||
if (observer.getPhases().isEmpty()) {
|
||||
back.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Back Arrow
|
||||
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
|
||||
back.open();
|
||||
}));
|
||||
|
||||
// Material Chooser
|
||||
inventory.setItem(4, observer.toItem(player, clickType -> {
|
||||
new SimulatorMaterialGui(player, simulator, observer::getMaterial, observer::setMaterial, this).open();
|
||||
}));
|
||||
|
||||
// Base Tick
|
||||
int baseTicks = observer.getBaseTick();
|
||||
inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
observer.changeBaseTicks(integer - baseTicks);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64)));
|
||||
inventory.setItem(18, baseTick);
|
||||
inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
|
||||
observer.changeBaseTicks(-baseTicks);
|
||||
} else {
|
||||
observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
//Pos X
|
||||
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setX(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
//Pos Y
|
||||
inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(0, clickType.isShiftClick() ? 5 : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setY(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(0, clickType.isShiftClick() ? -5 : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
|
||||
//Pos Z
|
||||
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(0, 0, clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setZ(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(0, 0, clickType.isShiftClick() ? -5 : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
}
|
||||
}
|
@ -101,20 +101,20 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
|
||||
}));
|
||||
|
||||
// Settings
|
||||
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open();
|
||||
}));
|
||||
|
||||
// Group chooser
|
||||
inventory.setItem(49, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open();
|
||||
}));
|
||||
|
||||
// Enable/Disable
|
||||
inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
redstone.setDisabled(!redstone.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
// Group chooser
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +93,9 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
|
||||
}));
|
||||
inventory.setItem(48, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open();
|
||||
inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
tnt.setDisabled(!tnt.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(50, new SWItem(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> {
|
||||
TNTElement tntElement = new TNTElement(tnt.getPosition().clone());
|
||||
@ -103,9 +104,8 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(51, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
tnt.setDisabled(!tnt.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open();
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 1) return false;
|
||||
tnt.setCount(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
return true;
|
||||
|
@ -99,31 +99,40 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
// Subpixel Alignment
|
||||
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
|
||||
tnt.align(new Vector(0.5, 0, 0.5));
|
||||
tnt.alignX(0);
|
||||
tnt.alignZ(0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
|
||||
// Z
|
||||
inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
tnt.align(new Vector(0, 0, 0.49));
|
||||
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
if (tnt.getAlignment().getZ() != -1) tnt.alignZ(-1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
negativZItem.setEnchanted(tnt.getAlignment().getZ() == -1);
|
||||
inventory.setItem(20, negativZItem);
|
||||
|
||||
inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
tnt.align(new Vector(0, 0, 0.51));
|
||||
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
if (tnt.getAlignment().getZ() != 1) tnt.alignZ(1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
positivZItem.setEnchanted(tnt.getAlignment().getZ() == 1);
|
||||
inventory.setItem(22, positivZItem);
|
||||
|
||||
// X
|
||||
inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
tnt.align(new Vector(0.49, 0, 0));
|
||||
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
if (tnt.getAlignment().getX() != -1) tnt.alignX(-1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
negativXItem.setEnchanted(tnt.getAlignment().getX() == -1);
|
||||
inventory.setItem(12, negativXItem);
|
||||
|
||||
inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
tnt.align(new Vector(0.51, 0, 0));
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
if(tnt.getAlignment().getX() != 1) tnt.alignX(1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
});
|
||||
positivXItem.setEnchanted(tnt.getAlignment().getX() == 1);
|
||||
inventory.setItem(30, positivXItem);
|
||||
|
||||
// Pos X
|
||||
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
|
||||
|
@ -62,6 +62,10 @@ public abstract class SimulatorBaseGui {
|
||||
player.getOpenInventory().setTitle(title());
|
||||
}
|
||||
populate();
|
||||
if (player.getOpenInventory().getTopInventory() == inv) {
|
||||
inventory.open();
|
||||
SimulatorWatcher.watch(player, simulator, this::open);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,9 +80,9 @@ public abstract class SimulatorBaseGui {
|
||||
SimulatorWatcher.watch(player, null, null);
|
||||
});
|
||||
|
||||
inventory.open();
|
||||
SimulatorWatcher.watch(player, simulator, this::open);
|
||||
populate();
|
||||
inventory.open();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
|
@ -23,6 +23,8 @@ import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
@ -94,6 +96,10 @@ public class SimFormatSimulatorLoader implements SimulatorLoader {
|
||||
element = new RedstoneElement(position);
|
||||
phaseConstructor = RedstonePhase::new;
|
||||
break;
|
||||
case "Observer":
|
||||
element = new ObserverElement(position);
|
||||
phaseConstructor = ObserverPhase::new;
|
||||
break;
|
||||
default:
|
||||
element = null;
|
||||
phaseConstructor = null;
|
||||
|
@ -32,6 +32,10 @@ import java.io.IOException;
|
||||
public class SimulatorSaver {
|
||||
|
||||
public void saveSimulator(File directory, Simulator simulator) {
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
|
||||
YAPIONObject simulatorObject = new YAPIONObject();
|
||||
simulatorObject.add("material", simulator.getMaterial().name());
|
||||
simulatorObject.add("autoTrace", simulator.isAutoTrace());
|
||||
|
@ -20,9 +20,7 @@
|
||||
package de.steamwar.bausystem.features.slaves.laufbau;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.states.FilteringTracesState;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.states.LaufbauState;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.states.CreatingLaufState;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.states.ProcessingTracesState;
|
||||
import de.steamwar.bausystem.utils.WorldEditUtils;
|
||||
import lombok.Getter;
|
||||
@ -40,9 +38,7 @@ public class Laufbau {
|
||||
private Location pos1;
|
||||
private Location pos2;
|
||||
|
||||
private FilteringTracesState filteringTracesState = null;
|
||||
private ProcessingTracesState processingTracesState = null;
|
||||
private CreatingLaufState creatingLaufState = null;
|
||||
private LaufbauState active;
|
||||
|
||||
private List<BlockBoundingBox> elements;
|
||||
|
||||
@ -62,8 +58,6 @@ public class Laufbau {
|
||||
int zFactor = (int) (Math.abs(selectionSize.getZ()) / 9.875);
|
||||
factor = Math.max(Math.max(xFactor, Math.max(yFactor, zFactor)), 8);
|
||||
|
||||
filteringTracesState = new FilteringTracesState(world, this::inRegion);
|
||||
|
||||
editSession = WorldEditUtils.getEditSession(player);
|
||||
|
||||
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
|
||||
@ -86,49 +80,32 @@ public class Laufbau {
|
||||
return -Double.compare(o1.blockData.getMaterial().getBlastResistance(), o2.blockData.getMaterial().getBlastResistance());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private LaufbauState getActive() {
|
||||
if (creatingLaufState != null) {
|
||||
return creatingLaufState;
|
||||
}
|
||||
if (processingTracesState != null) {
|
||||
return processingTracesState;
|
||||
}
|
||||
return filteringTracesState;
|
||||
active = new ProcessingTracesState(world, this::inRegion, editSession, elements, factor);
|
||||
}
|
||||
|
||||
private void createNextState() {
|
||||
if (creatingLaufState != null) {
|
||||
return;
|
||||
}
|
||||
if (processingTracesState != null) {
|
||||
creatingLaufState = new CreatingLaufState(processingTracesState.getBlocks(), processingTracesState.getCuboidIntersectionCache(), world, editSession, elements, factor);
|
||||
return;
|
||||
}
|
||||
processingTracesState = new ProcessingTracesState(filteringTracesState.getTntPositions(), this::inRegion, factor);
|
||||
if (active == null) return;
|
||||
active = active.getNextState();
|
||||
}
|
||||
|
||||
public String actionBarMessage(Player p) {
|
||||
return getActive().actionBarMessage(p);
|
||||
return active.actionBarMessage(p);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return getActive().hasNext();
|
||||
if (active == null) return false;
|
||||
return active.hasNext();
|
||||
}
|
||||
|
||||
public void next() {
|
||||
LaufbauState state = getActive();
|
||||
LaufbauState state = active;
|
||||
state.next();
|
||||
if (!state.hasNext()) {
|
||||
createNextState();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inRegion(Location location, int expansion) {
|
||||
return inRegion(location.toVector(), expansion);
|
||||
}
|
||||
|
||||
private boolean inRegion(Vector location, int expansion) {
|
||||
if (location.getBlockX() >= pos1.getBlockX() - expansion) {
|
||||
if (location.getBlockY() >= pos1.getBlockY() - expansion) {
|
||||
|
@ -78,11 +78,4 @@ public class LaufbauCommand extends SWCommand {
|
||||
public void laufbauSettings(@Validator Player player) {
|
||||
new LaufbauSettings(player);
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "LAUFBAU_NO_PERM");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -196,4 +196,9 @@ public class CreatingLaufState implements LaufbauState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaufbauState getNextState() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.slaves.laufbau.states;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
||||
import de.steamwar.bausystem.features.tracer.show.Record;
|
||||
import de.steamwar.bausystem.features.tracer.show.StoredRecords;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class FilteringTracesState implements LaufbauState {
|
||||
|
||||
private long start = System.currentTimeMillis();
|
||||
|
||||
private World world;
|
||||
private BiPredicate<Location, Integer> inRegionCheck;
|
||||
|
||||
private int totalRecord;
|
||||
private List<Record> recordList;
|
||||
private List<Record.TNTRecord> tntRecords = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<TNTPosition> tntPositions = new ArrayList<>();
|
||||
|
||||
public FilteringTracesState(World world, BiPredicate<Location, Integer> inRegionCheck) {
|
||||
recordList = new ArrayList<>(StoredRecords.getRecords());
|
||||
totalRecord = recordList.size();
|
||||
|
||||
this.world = world;
|
||||
this.inRegionCheck = inRegionCheck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String actionBarMessage(Player p) {
|
||||
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_FILTERING_TRACES", p), totalRecord - recordList.size(), totalRecord, eta(p, start, totalRecord - recordList.size(), totalRecord));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return !recordList.isEmpty() || !tntRecords.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
if (tntRecords.isEmpty()) {
|
||||
Record record = recordList.remove(0);
|
||||
tntRecords.addAll(record.getTnt());
|
||||
}
|
||||
if (tntRecords.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Record.TNTRecord tntRecord = tntRecords.remove(0);
|
||||
tntRecord.getPositions().forEach(tntPosition -> {
|
||||
if (FlatteningWrapper.impl.inWater(world, tntPosition.getLocation())) {
|
||||
return;
|
||||
}
|
||||
if (inRegionCheck.test(tntPosition.getLocation().toLocation(world), 1)) {
|
||||
tntPositions.add(tntPosition);
|
||||
}
|
||||
if (tntPosition.getPreviousLocation() != null && inRegionCheck.test(tntPosition.getPreviousLocation().toLocation(world), 1)) {
|
||||
tntPositions.add(tntPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -45,4 +45,6 @@ public interface LaufbauState {
|
||||
}
|
||||
return LocalTime.ofNanoOfDay(eta).format(DateTimeFormatter.ofPattern(BauSystem.MESSAGE.parse("TIME", p)));
|
||||
}
|
||||
|
||||
LaufbauState getNextState();
|
||||
}
|
||||
|
@ -1,115 +1,127 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.slaves.laufbau.states;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import lombok.Getter;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProcessingTracesState implements LaufbauState {
|
||||
|
||||
private long start = System.currentTimeMillis();
|
||||
private final long start = System.currentTimeMillis();
|
||||
private final World world;
|
||||
private final BiPredicate<Vector, Integer> inRegionCheck;
|
||||
private final EditSession editSession;
|
||||
private final List<BlockBoundingBox> elements;
|
||||
private final int factor;
|
||||
|
||||
private int totalCuboids;
|
||||
private List<TNTPosition> tntPositionList;
|
||||
private BiPredicate<Vector, Integer> inRegionCheck;
|
||||
private int factor;
|
||||
private final List<TNTPoint> TNTPoints;
|
||||
private final int totalTntRecords;
|
||||
|
||||
private List<Cuboid> toExpand = new ArrayList<>();
|
||||
private final Set<Point> affectedBlocks = new HashSet<>();
|
||||
private final Map<Point, Set<Cuboid>> cuboidsPerChunk = new HashMap<>();
|
||||
|
||||
private int cuboidsDone = 0;
|
||||
|
||||
@Getter
|
||||
private Set<Point> blocks = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
private Map<Point, Set<Cuboid>> cuboidIntersectionCache = new HashMap<>();
|
||||
|
||||
public ProcessingTracesState(List<TNTPosition> tntPositionList, BiPredicate<Vector, Integer> inRegionCheck, int factor) {
|
||||
this.tntPositionList = tntPositionList;
|
||||
this.totalCuboids = tntPositionList.stream().mapToInt(tntPosition -> tntPosition.getPreviousLocation() == null ? 1 : 3).sum();
|
||||
public ProcessingTracesState(World world, BiPredicate<Vector, Integer> inRegionCheck, EditSession editSession, List<BlockBoundingBox> elements, int factor) {
|
||||
this.world = world;
|
||||
this.inRegionCheck = inRegionCheck;
|
||||
this.editSession = editSession;
|
||||
this.elements = elements;
|
||||
this.factor = factor;
|
||||
|
||||
// TODO: Optimize only retrieving traces inside of the affected regions!
|
||||
TNTPoints = TraceManager.instance.getAll()
|
||||
.stream()
|
||||
.flatMap(trace -> trace.getHistories().stream())
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
totalTntRecords = TNTPoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String actionBarMessage(Player p) {
|
||||
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), cuboidsDone, totalCuboids, eta(p, start, cuboidsDone, totalCuboids));
|
||||
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTntRecords - TNTPoints.size(), totalTntRecords, eta(p, start, totalTntRecords - TNTPoints.size(), totalTntRecords));
|
||||
}
|
||||
|
||||
private boolean inRegion(Vector location, int expansion) {
|
||||
return inRegionCheck.test(location, expansion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return !tntPositionList.isEmpty() || !toExpand.isEmpty();
|
||||
return !TNTPoints.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
if (!toExpand.isEmpty()) {
|
||||
Cuboid cuboid = toExpand.remove(0);
|
||||
expandCuboid(cuboid);
|
||||
} else {
|
||||
TNTPosition tntPosition = tntPositionList.remove(0);
|
||||
createCuboid(tntPosition);
|
||||
}
|
||||
}
|
||||
TNTPoint current = TNTPoints.remove(0);
|
||||
if (FlatteningWrapper.impl.inWater(world, current.getLocation().toVector())) return;
|
||||
if (!(inRegion(current.getLocation().toVector(), 1) || (current.getPrevious().isPresent() && inRegion(current.getPrevious().get().getLocation().toVector(), 1))))
|
||||
return;
|
||||
|
||||
private void createCuboid(TNTPosition tntPosition) {
|
||||
Vector location = tntPosition.getLocation();
|
||||
Vector previousLocation = tntPosition.getPreviousLocation();
|
||||
|
||||
if (previousLocation == null) {
|
||||
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98));
|
||||
} else {
|
||||
Vector movement = location.clone().subtract(previousLocation);
|
||||
toExpand.add(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
|
||||
if (Math.abs(tntPosition.getUpdateVelocity().getX()) >= Math.abs(tntPosition.getUpdateVelocity().getZ())) {
|
||||
toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
|
||||
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
|
||||
Location location = current.getLocation();
|
||||
if (current.getPrevious().isPresent()) {
|
||||
Location previousLocation = current.getPrevious().get().getLocation();
|
||||
Location movement = location.clone().subtract(previousLocation);
|
||||
calculateCuboid(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
|
||||
if (movement.getX() >= movement.getZ()) {
|
||||
calculateCuboid(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
|
||||
calculateCuboid(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
|
||||
} else {
|
||||
toExpand.add(new Cuboid(previousLocation.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
|
||||
toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), location.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
|
||||
calculateCuboid(new Cuboid(previousLocation.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
|
||||
calculateCuboid(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), location.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
|
||||
}
|
||||
} else {
|
||||
calculateCuboid(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98));
|
||||
}
|
||||
}
|
||||
|
||||
private void expandCuboid(Cuboid cuboid) {
|
||||
cuboidsDone++;
|
||||
private void calculateCuboid(Cuboid cuboid) {
|
||||
for (double x = cuboid.getX() - 2; x < cuboid.getX() + cuboid.getDx() + 2; x++) {
|
||||
for (double y = cuboid.getY() - 2; y < cuboid.getY() + cuboid.getDy() + 2; y++) {
|
||||
for (double z = cuboid.getZ() - 2; z < cuboid.getZ() + cuboid.getDz() + 2; z++) {
|
||||
Vector location = new Vector(x, y, z);
|
||||
if (inRegionCheck.test(location, 0)) {
|
||||
Point point = new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
blocks.add(point);
|
||||
cuboidIntersectionCache.computeIfAbsent(point.divide(factor), __ -> new HashSet<>())
|
||||
if (inRegion(location, 0)) {
|
||||
affectedBlocks.add(new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
cuboidsPerChunk.computeIfAbsent(new Point(location.getBlockX() / factor, location.getBlockY() / factor, location.getBlockZ() / factor), __ -> new HashSet<>())
|
||||
.add(cuboid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaufbauState getNextState() {
|
||||
return new CreatingLaufState(affectedBlocks, cuboidsPerChunk, world, editSession, elements, factor);
|
||||
}
|
||||
}
|
||||
|
@ -91,13 +91,6 @@ public class PanzernCommand extends SWCommand {
|
||||
}.runTaskTimer(BauSystem.getInstance(), 1, 1);
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public TypeValidator<Player> validator() {
|
||||
return (commandSender, player, messageSender) -> {
|
||||
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "PANZERN_NO_PERM");
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper(value = "block", local = true)
|
||||
private TypeMapper<Material> blockMapper() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
@ -130,7 +123,7 @@ public class PanzernCommand extends SWCommand {
|
||||
if (!material.isBlock()) {
|
||||
continue;
|
||||
}
|
||||
if (material.name().contains("STAIRS") || material.name().contains("SLAB")) {
|
||||
if (material.name().contains("STAIRS") || material.name().contains("SLAB") || material.name().contains("GLASS")) {
|
||||
strings.add(material.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
In neuem Issue referenzieren
Einen Benutzer sperren