mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-07-05 16:40:04 +00:00
b292416496
Note: Maybe this doesn't compile, ij is broken af smh, let's give it a try...
138 lines
3.9 KiB
Java
138 lines
3.9 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 Lesser 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 Lesser General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
import static com.google.common.base.Preconditions.checkArgument;
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
|
|
import com.sk89q.worldedit.session.SessionKey;
|
|
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.adapter.bukkit.TextAdapter;
|
|
import java.util.UUID;
|
|
|
|
import java.util.Locale;
|
|
import javax.annotation.Nullable;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Entity;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class BukkitCommandSender extends AbstractNonPlayerActor {
|
|
|
|
/**
|
|
* One time generated ID.
|
|
*/
|
|
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");
|
|
|
|
private CommandSender sender;
|
|
private WorldEditPlugin plugin;
|
|
|
|
public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
|
|
checkNotNull(plugin);
|
|
checkNotNull(sender);
|
|
checkArgument(!(sender instanceof Player), "Cannot wrap a player");
|
|
|
|
this.plugin = plugin;
|
|
this.sender = sender;
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return DEFAULT_ID;
|
|
}
|
|
|
|
@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(Component component) {
|
|
TextAdapter.sendComponent(sender, WorldEditText.format(component, getLocale()));
|
|
}
|
|
|
|
@Override
|
|
public String[] getGroups() {
|
|
return new String[0];
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPermission(String perm) {
|
|
return true;
|
|
}
|
|
|
|
@Override public void setPermission(String permission, boolean value) {
|
|
}
|
|
|
|
@Override
|
|
public void checkPermission(String permission) throws AuthorizationException {
|
|
}
|
|
|
|
@Override
|
|
public Locale getLocale() {
|
|
return WorldEdit.getInstance().getConfiguration().defaultLocale;
|
|
}
|
|
|
|
public CommandSender getSender() {
|
|
return this.sender;
|
|
}
|
|
|
|
@Override
|
|
public SessionKey getSessionKey() {
|
|
return new SessionKey() {
|
|
@Nullable
|
|
@Override
|
|
public String getName() {
|
|
return sender.getName();
|
|
}
|
|
|
|
@Override
|
|
public boolean isActive() {
|
|
if (sender instanceof Entity) {
|
|
Entity entity = (Entity) sender;
|
|
return (entity.isValid() && !entity.isDead());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isPersistent() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return DEFAULT_ID;
|
|
}
|
|
};
|
|
}
|
|
}
|