Plex-FAWE/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
4.5 KiB
Java
Raw Normal View History

/*
2014-04-04 22:03:18 +00:00
* 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/>.
2014-04-04 22:03:18 +00:00
*/
package com.sk89q.worldedit.bukkit;
2019-11-18 09:50:52 +00:00
import com.sk89q.worldedit.WorldEdit;
2019-08-06 15:28:12 +00:00
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
2019-03-26 17:27:09 +00:00
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;
2019-08-06 15:28:12 +00:00
import org.bukkit.command.CommandSender;
2019-08-29 12:57:03 +00:00
import org.bukkit.entity.Entity;
2019-08-06 15:28:12 +00:00
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
2019-08-06 15:28:12 +00:00
public class BukkitCommandSender extends AbstractNonPlayerActor {
/**
* One time generated ID.
*/
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");
private final CommandSender sender;
private final 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
@Deprecated
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage(part);
}
}
2020-03-05 21:07:20 +00:00
@Override
@Deprecated
2020-03-05 21:07:20 +00:00
public void print(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("§d" + part);
2020-03-05 21:07:20 +00:00
}
}
@Override
@Deprecated
2020-03-05 21:07:20 +00:00
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("§7" + part);
2020-03-05 21:07:20 +00:00
}
}
@Override
@Deprecated
2020-03-05 21:07:20 +00:00
public void printError(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("§c" + part);
2020-03-05 21:07:20 +00:00
}
}
@Override
public void print(Component component) {
2021-04-04 17:56:57 +00:00
TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale()));
}
@Override
public String[] getGroups() {
return new String[0];
}
@Override
public boolean hasPermission(String perm) {
return true;
}
//FAWE start
@Override
public void setPermission(String permission, boolean value) {
2019-06-30 18:56:32 +00:00
}
//FAWE end
2019-06-30 18:56:32 +00:00
@Override
public void checkPermission(String permission) throws AuthorizationException {
}
@Override
public Locale getLocale() {
2019-11-18 09:50:52 +00:00
return WorldEdit.getInstance().getConfiguration().defaultLocale;
}
public CommandSender getSender() {
return this.sender;
}
@Override
public SessionKey getSessionKey() {
return new SessionKey() {
@Nullable
@Override
public String getName() {
2019-08-06 15:28:12 +00:00
return sender.getName();
}
@Override
public boolean isActive() {
//FAWE start - check if sender instanceof Entity, before returning true
2019-08-29 12:57:03 +00:00
if (sender instanceof Entity) {
Entity entity = (Entity) sender;
2020-03-05 21:07:20 +00:00
return entity.isValid() && !entity.isDead();
2019-08-29 12:57:03 +00:00
}
//FAWE end
2019-08-06 15:28:12 +00:00
return true;
}
@Override
public boolean isPersistent() {
2019-08-06 15:28:12 +00:00
return true;
}
@Override
public UUID getUniqueId() {
return DEFAULT_ID;
}
};
}
}