mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-07-05 16:40:04 +00:00
96dcb95b7c
Javadoc and Formatting fixes. Also, extremely minor code changes which have been tested. This commit is only part one of two commits that aim to fix problems with formatting in our project. In part two I will modify the Google Java Style Guide (since it closely matches our code style) for our project so there is guidance on how to format and document. * Updated PlotSquared URL * Removed plugin acronyms * Fixed a typo * Fixed grammar * Use modern block id's * Update YouTube video URL
190 lines
5.5 KiB
Java
190 lines
5.5 KiB
Java
/*
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
* Copyright (C) WorldEdit team and contributors
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
|
|
import com.sk89q.worldedit.extension.platform.Locatable;
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
import com.sk89q.worldedit.session.SessionKey;
|
|
import com.sk89q.worldedit.util.Location;
|
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
|
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
|
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.command.BlockCommandSender;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Locale;
|
|
import java.util.UUID;
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements Locatable {
|
|
|
|
private static final String UUID_PREFIX = "CMD";
|
|
|
|
private final BlockCommandSender sender;
|
|
private final WorldEditPlugin plugin;
|
|
private final Location location;
|
|
private final UUID uuid;
|
|
|
|
public BukkitBlockCommandSender(WorldEditPlugin plugin, BlockCommandSender sender) {
|
|
checkNotNull(plugin);
|
|
checkNotNull(sender);
|
|
|
|
this.plugin = plugin;
|
|
this.sender = sender;
|
|
this.location = BukkitAdapter.adapt(sender.getBlock().getLocation());
|
|
this.uuid = UUID.nameUUIDFromBytes((UUID_PREFIX + sender.getName()).getBytes(StandardCharsets.UTF_8));
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return sender.getName();
|
|
}
|
|
|
|
@Override
|
|
public void printRaw(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
sender.sendMessage(part);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void print(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
print(TextComponent.of(part, TextColor.LIGHT_PURPLE));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void printDebug(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
print(TextComponent.of(part, TextColor.GRAY));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void printError(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
print(TextComponent.of(part, TextColor.RED));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void print(Component component) {
|
|
TextAdapter.sendComponent(sender, WorldEditText.format(component, getLocale()));
|
|
}
|
|
|
|
@Override
|
|
public Locale getLocale() {
|
|
return WorldEdit.getInstance().getConfiguration().defaultLocale;
|
|
}
|
|
|
|
@Override
|
|
public Location getLocation() {
|
|
return this.location;
|
|
}
|
|
|
|
@Override
|
|
public boolean setLocation(Location location) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Extent getExtent() {
|
|
return this.location.getExtent();
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return uuid;
|
|
}
|
|
|
|
@Override
|
|
public String[] getGroups() {
|
|
return new String[0];
|
|
}
|
|
|
|
@Override
|
|
public void checkPermission(String permission) throws AuthorizationException {
|
|
if (!hasPermission(permission)) {
|
|
throw new AuthorizationException();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPermission(String permission) {
|
|
return sender.hasPermission(permission);
|
|
}
|
|
|
|
@Override
|
|
public boolean togglePermission(String permission) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void setPermission(String permission, boolean value) {
|
|
}
|
|
|
|
public BlockCommandSender getSender() {
|
|
return this.sender;
|
|
}
|
|
|
|
@Override
|
|
public SessionKey getSessionKey() {
|
|
return new SessionKey() {
|
|
@Override
|
|
public String getName() {
|
|
return sender.getName();
|
|
}
|
|
|
|
@Override
|
|
public boolean isActive() {
|
|
@NotNull Block block = sender.getBlock();
|
|
@NotNull World world = block.getWorld();
|
|
if (world.isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
|
|
return sender.getBlock().getType() == Material.COMMAND_BLOCK
|
|
|| sender.getBlock().getType() == Material.CHAIN_COMMAND_BLOCK
|
|
|| sender.getBlock().getType() == Material.REPEATING_COMMAND_BLOCK;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isPersistent() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return uuid;
|
|
}
|
|
};
|
|
}
|
|
}
|