Merge branch 'master' into Tracer-entity
Dieser Commit ist enthalten in:
Commit
3cc70f1f71
31
BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java
Normale Datei
31
BauSystem_12/src/de/steamwar/bausystem/world/ScriptListener_12.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 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.world;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
class ScriptListener_12 {
|
||||
private ScriptListener_12(){}
|
||||
|
||||
static boolean isNoBook(ItemStack item){
|
||||
return item.getType() != Material.BOOK_AND_QUILL && item.getType() != Material.WRITTEN_BOOK;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
|
||||
@ -100,12 +101,12 @@ public class Region_15 {
|
||||
for(int Z = v.getBlockZ(); Z < v.getBlockZ() + dimensions.getBlockZ(); Z++){
|
||||
BlockPosition blockPos = new BlockPosition(X, Y, Z);
|
||||
BaseBlock fullBlock = clipboard.getFullBlock(BlockVector3.at(X, Y, Z).subtract(v).add(clipboard.getRegion().getMinimumPoint()));
|
||||
Material replaceTo = BukkitAdapter.adapt(fullBlock.getBlockType());
|
||||
BlockData replaceTo = BukkitAdapter.adapt(fullBlock);
|
||||
world.removeTileEntity(blockPos);
|
||||
if(replaceTo == null)
|
||||
world.setTypeAndData(blockPos, ((CraftBlockData)Material.AIR.createBlockData()).getState(), 1042);
|
||||
else
|
||||
world.setTypeAndData(new BlockPosition(X, Y, Z), ((CraftBlockData)replaceTo.createBlockData()).getState(), 1042);
|
||||
world.setTypeAndData(new BlockPosition(X, Y, Z), ((CraftBlockData)replaceTo).getState(), 1042);
|
||||
|
||||
world.getChunkProvider().flagDirty(blockPos);
|
||||
}
|
||||
|
31
BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java
Normale Datei
31
BauSystem_15/src/de/steamwar/bausystem/world/ScriptListener_15.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 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.world;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
class ScriptListener_15 {
|
||||
private ScriptListener_15(){}
|
||||
|
||||
static boolean isNoBook(ItemStack item){
|
||||
return item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK;
|
||||
}
|
||||
}
|
@ -82,6 +82,6 @@ public class Detoloader {
|
||||
public static final int STONE_BUTTON = 20;
|
||||
public static final int WOODEN_BUTTON = 30;
|
||||
public static final int PRESSURE_PLATE = 20;
|
||||
public static final int NOTE_BLOCK = 20;
|
||||
public static final int NOTE_BLOCK = 1;
|
||||
public static final int TRIPWIRE = 10;
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
@ -117,20 +116,9 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
getCommand("detonator").setExecutor(new CommandDetonator());
|
||||
getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter());
|
||||
|
||||
new ChainedCommand("/1", "/pos1");
|
||||
new ChainedCommand("/2", "/pos2");
|
||||
new ChainedCommand("/90", "/rotate 90");
|
||||
new ChainedCommand("/-90", "/rotate -90");
|
||||
new ChainedCommand("/180", "/rotate 180");
|
||||
new ChainedCommand("/c", "/copy");
|
||||
new ChainedCommand("/p", Arrays.asList("-a", "-b", "-e", "-n", "-o", "-s", "-m"), "/paste {}");
|
||||
new ChainedCommand("/flopy", "/copy", "/flip");
|
||||
new ChainedCommand("/flopyp", Arrays.asList("-a", "-b", "-e", "-n", "-o", "-s", "-m"), "/copy", "/flip", "/paste {}");
|
||||
new ChainedCommand("/u", "/undo {}");
|
||||
new ChainedCommand("/r", "/redo {}");
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ExplodeListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 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.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChainedCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private String[] commands;
|
||||
private List<String> tabCompletes;
|
||||
|
||||
public ChainedCommand(String command, final List<String> tabCompletes, final String... commands) {
|
||||
BauSystem.getPlugin().getCommand(command).setExecutor(this);
|
||||
BauSystem.getPlugin().getCommand(command).setTabCompleter(this);
|
||||
|
||||
this.commands = commands;
|
||||
this.tabCompletes = tabCompletes;
|
||||
if (tabCompletes == null) {
|
||||
this.tabCompletes = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public ChainedCommand(String command, final String... commands) {
|
||||
this(command, null, commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
String argsString = "";
|
||||
if (args.length != 0) argsString = String.join(" ", args);
|
||||
|
||||
for (String cmd : commands) {
|
||||
if (!player.performCommand(cmd.replace("{}", argsString))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] args) {
|
||||
return tabCompletes;
|
||||
}
|
||||
|
||||
}
|
@ -119,8 +119,8 @@ public class AutoLoader extends IAutoLoader implements Listener {
|
||||
}
|
||||
|
||||
public void wait(int time){
|
||||
if(time < 0){
|
||||
print("§cNegative Wartezeit", false);
|
||||
if(time < 1){
|
||||
print("§cDie Wartezeit ist zu klein", false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -129,8 +129,8 @@ public class AutoLoader extends IAutoLoader implements Listener {
|
||||
}
|
||||
|
||||
public void blockWait(int time){
|
||||
if(time < 0){
|
||||
print("§cNegative Wartezeit", false);
|
||||
if(time < 1){
|
||||
print("§cDie Wartezeit ist zu klein", false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,23 @@ package de.steamwar.bausystem.world;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class RegionListener implements Listener {
|
||||
|
||||
@ -78,12 +86,19 @@ public class RegionListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"};
|
||||
|
||||
private boolean isWorldEditCommand(String command) {
|
||||
for(String shortcut : shortcutCommands)
|
||||
if(command.startsWith(shortcut))
|
||||
return true;
|
||||
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
return RegionListener_15.isWorldEditCommand(command);
|
||||
default:
|
||||
case 12:
|
||||
return RegionListener_12.isWorldEditCommand(command);
|
||||
case 15:
|
||||
default:
|
||||
return RegionListener_15.isWorldEditCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,4 +112,5 @@ public class RegionListener implements Listener {
|
||||
event.setLine(i, line);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
144
BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java
Normale Datei
144
BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java
Normale Datei
@ -0,0 +1,144 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 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.world;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ScriptListener implements Listener {
|
||||
|
||||
private Set<Player> playerSet = new HashSet<>();
|
||||
|
||||
public ScriptListener() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), playerSet::clear, 5, 5);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null || isNoBook(item) || item.getItemMeta() == null)
|
||||
return;
|
||||
|
||||
if (event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
playerSet.add(event.getPlayer());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (playerSet.remove(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer());
|
||||
}
|
||||
|
||||
private boolean isNoBook(ItemStack item){
|
||||
switch(Core.getVersion()){
|
||||
case 12:
|
||||
return ScriptListener_12.isNoBook(item);
|
||||
case 15:
|
||||
default:
|
||||
return ScriptListener_15.isNoBook(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ScriptExecutor {
|
||||
|
||||
private final Player player;
|
||||
private final List<String> commands = new ArrayList<>();
|
||||
private int index = 0;
|
||||
|
||||
public ScriptExecutor(BookMeta bookMeta, Player player) {
|
||||
this.player = player;
|
||||
|
||||
for(String page : bookMeta.getPages()) {
|
||||
for (String command : page.split("\n")) {
|
||||
if (command.startsWith("#") || command.trim().isEmpty()) continue;
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
if (commands.isEmpty()) return;
|
||||
resume();
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
if (!player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (index < commands.size()) {
|
||||
String command = commands.get(index++);
|
||||
|
||||
if (command.toLowerCase().startsWith("sleep")) {
|
||||
ScriptListener.sleepCommand(this, generateArgumentArray("sleep", command));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
|
||||
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
|
||||
if (preprocessEvent.isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
|
||||
Bukkit.getServer().dispatchCommand(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String[] generateArgumentArray(String command, String fullCommand) {
|
||||
return fullCommand.substring(command.length()).trim().split(" ");
|
||||
}
|
||||
|
||||
private static void sleepCommand(ScriptExecutor scriptExecutor, String[] args) {
|
||||
int sleepTime = 1;
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
sleepTime = Integer.parseInt(args[0]);
|
||||
if (sleepTime <= 0) {
|
||||
scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie Zeit muss eine Zahl großer 0 sein.");
|
||||
sleepTime = 1;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie Zeit darf nur aus Zahlen bestehen.");
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), scriptExecutor::resume, sleepTime);
|
||||
}
|
||||
|
||||
}
|
@ -33,15 +33,3 @@ commands:
|
||||
lockschem:
|
||||
detonator:
|
||||
aliases: dt
|
||||
|
||||
/1:
|
||||
/2:
|
||||
/180:
|
||||
/90:
|
||||
/-90:
|
||||
/p:
|
||||
/c:
|
||||
/flopy:
|
||||
/flopyp:
|
||||
/u:
|
||||
/r:
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren