SteamWar/BauSystem2.0
Archiviert
12
0

Add SmartPlaceCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-08-28 15:09:40 +02:00
Ursprung 9279f885cb
Commit b143df939a
3 geänderte Dateien mit 117 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -199,6 +199,13 @@ GUI_EDITOR_ITEM_TRASH=§cTrashcan
GUI_EDITOR_ITEM_TRASH_LORE=§7Item hier rein Legen GUI_EDITOR_ITEM_TRASH_LORE=§7Item hier rein Legen
GUI_EDITOR_ITEM_MORE=§eMehr Items GUI_EDITOR_ITEM_MORE=§eMehr Items
GUI_EDITOR_TITLE_MORE=Item auswählen GUI_EDITOR_TITLE_MORE=Item auswählen
# SmartPlace
SMART_PLACE_HELP = §8/§esmartplace §8-§7 Toggled SmartPlace
SMART_PLACE_INFO = §7Plaziert rotierbare Blöcke beim §esneaken§7 von dir §eweg§7.
SMART_PLACE_ENABLE = §aSmartPlace aktiviert
SMART_PLACE_DISABLE = §cSmartPlace deaktiviert
# Trace # Trace
TRACE_RECORD=§aan TRACE_RECORD=§aan
TRACE_RECORD-AUTO=§aan TRACE_RECORD-AUTO=§aan

Datei anzeigen

@ -0,0 +1,55 @@
/*
* 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.smartplace;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@Linked(LinkageType.COMMAND)
public class SmartPlaceCommand extends SWCommand {
public SmartPlaceCommand() {
super("smartplace", "sp");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", p, "Smart Place");
BauSystem.MESSAGE.sendPrefixless("SMART_PLACE_HELP", p);
BauSystem.MESSAGE.sendPrefixless("SMART_PLACE_INFO", p);
}
@Register
public void genericToggle(Player p) {
boolean smartPlace = Config.getInstance().get(p).getPlainValueOrDefault("smartPlace", false);
Config.getInstance().get(p).put("smartPlace", !smartPlace);
if (!smartPlace) {
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("SMART_PLACE_ENABLE", p));
BauSystem.MESSAGE.send("SMART_PLACE_INFO", p);
} else {
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("SMART_PLACE_DISABLE", p));
}
}
}

Datei anzeigen

@ -0,0 +1,55 @@
/*
* 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.smartplace;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Rotatable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
@Linked(LinkageType.LISTENER)
public class SmartPlaceListener implements Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer().isSneaking() && Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) {
Block block = event.getBlockPlaced();
BlockData blockData = block.getBlockData();
if (blockData instanceof Directional) {
Directional directional = (Directional) blockData;
BlockFace blockFace = directional.getFacing().getOppositeFace();
if (directional.getFaces().contains(blockFace)) {
directional.setFacing(blockFace);
}
} else if (blockData instanceof Rotatable) {
Rotatable rotatable = (Rotatable) blockData;
rotatable.setRotation(rotatable.getRotation());
}
block.setBlockData(blockData);
}
}
}