Add GetMaterial
Add SetMaterial Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
f0e38afb8e
Commit
dd2ba662d5
@ -22,18 +22,29 @@ package de.steamwar.bausystem.features.script;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.core.VersionedCallable;
|
import de.steamwar.core.VersionedCallable;
|
||||||
|
import net.minecraft.server.v1_15_R1.PacketPlayOutCommands;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class CustomCommandListener implements Listener {
|
public class CustomCommandListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
private Map<Player, Map<String, BookMeta>> playerMap = new HashMap<>();
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
|
||||||
for (ItemStack item : e.getPlayer().getInventory().getContents()) {
|
private void updateInventory(Player p) {
|
||||||
|
playerMap.remove(p);
|
||||||
|
for (ItemStack item : p.getInventory().getContents()) {
|
||||||
if (item == null || isNoBook(item) || item.getItemMeta() == null) {
|
if (item == null || isNoBook(item) || item.getItemMeta() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -49,12 +60,39 @@ public class CustomCommandListener implements Listener {
|
|||||||
if (!s.startsWith("#!CMD ")) {
|
if (!s.startsWith("#!CMD ")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (s.substring(6).equals(e.getMessage())) {
|
playerMap.computeIfAbsent(p, player -> new HashMap<>()).put(s.substring(6), bookMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
updateInventory(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
|
playerMap.remove(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClose(InventoryCloseEvent e) {
|
||||||
|
if (e.getPlayer() instanceof Player) {
|
||||||
|
updateInventory((Player) e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
|
||||||
|
Map<String, BookMeta> bookMetaMap = playerMap.get(e.getPlayer());
|
||||||
|
if (bookMetaMap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BookMeta bookMeta = bookMetaMap.get(e.getMessage());
|
||||||
|
if (bookMeta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
new ScriptExecutor(bookMeta, e.getPlayer());
|
new ScriptExecutor(bookMeta, e.getPlayer());
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNoBook(ItemStack item) {
|
private boolean isNoBook(ItemStack item) {
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* 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.script.command.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||||
|
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||||
|
import de.steamwar.bausystem.features.script.variables.Value;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||||
|
public class GetMaterial implements SpecialCommand {
|
||||||
|
|
||||||
|
private final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] description() {
|
||||||
|
return new String[]{
|
||||||
|
"§egetmaterial §8<§7Variable§8> §8<§7Value§8(§7s§8)§8> §8<§7Value§8(§7s§8)§8> §8[§7Value§8(§7s§8)§8]",
|
||||||
|
"",
|
||||||
|
"Schreibt das material von einem Block in der Welt in die Variable."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String command() {
|
||||||
|
return "getmaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||||
|
if (command.length <= 1) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 2) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 3) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 4) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong();
|
||||||
|
int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong();
|
||||||
|
int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong();
|
||||||
|
scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(world.getBlockAt(x, y, z).getType().name()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* 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.script.command.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||||
|
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||||
|
public class SetMaterial implements SpecialCommand {
|
||||||
|
|
||||||
|
private final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] description() {
|
||||||
|
return new String[]{
|
||||||
|
"§esetmaterial §8<§7Variable§8> §8<§7Value§8(§7s§8)§8> §8<§7Value§8(§7s§8)§8> §8[§7Value§8(§7s§8)§8]",
|
||||||
|
"",
|
||||||
|
"Setzt an einem Block in der Welt das Material der ersten Variable."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String command() {
|
||||||
|
return "setmaterial";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||||
|
if (command.length <= 1) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 2) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 3) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 4) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong();
|
||||||
|
int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong();
|
||||||
|
int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong();
|
||||||
|
try {
|
||||||
|
world.getBlockAt(x, y, z).setType(Material.valueOf(scriptExecutor.getOrItself(command[1])));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren