use of org.bukkit.plugin.java.JavaPlugin in project NoCheatPlus by NoCheatPlus.
the class CommandUtil method getCommands.
/**
* Get all Command instances, that NCP can get hold of. Attempt to get a SimpleCommandMap instance from the server to get the actually registered commands, but also get commands from JavaPlugin instances.
* @return
*/
public static Collection<Command> getCommands() {
final Collection<Command> commands = new LinkedHashSet<Command>(500);
// All (?) commands from the SimpleCommandMap of the server, if available.
final CommandMap commandMap = getCommandMap();
if (commandMap != null && commandMap instanceof SimpleCommandMap) {
commands.addAll(((SimpleCommandMap) commandMap).getCommands());
}
// Fall-back: plugin commands.
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin instanceof JavaPlugin) {
final JavaPlugin javaPlugin = (JavaPlugin) plugin;
final Map<String, Map<String, Object>> map = javaPlugin.getDescription().getCommands();
if (map != null) {
for (String label : map.keySet()) {
Command command = javaPlugin.getCommand(label);
if (command != null) {
commands.add(command);
}
}
}
}
}
return commands;
}
use of org.bukkit.plugin.java.JavaPlugin in project BKCommonLib by bergerhealer.
the class MapWidgetAnvil method setWindowOpen.
private void setWindowOpen(boolean enabled) {
if (this._isWindowOpen == enabled) {
return;
}
this._isWindowOpen = enabled;
// Close all old views first (to be sure), both when enabling and disabling
for (InventoryView view : this._openInventories) {
view.close();
}
this._openInventories.clear();
if (enabled) {
// Start listening
JavaPlugin plugin = this.getDisplay().getPlugin();
Bukkit.getPluginManager().registerEvents(this._listener, plugin);
// Reset text
this._text = "";
// Open windows for all viewing players
for (Player player : (_openFor.isEmpty() ? this.display.getViewers() : _openFor)) {
if (_openFor.isEmpty() && !this.display.isControlling(player)) {
continue;
}
final InventoryView view = EntityPlayerHandle.fromBukkit(player).openAnvilWindow(null);
// Required for handling text changes < MC 1.9
if (!CommonCapabilities.HAS_PREPARE_ANVIL_EVENT) {
ContainerAnvilHandle container = ContainerAnvilHandle.fromBukkit(view);
LegacyContainerAnvilHook hook = ClassHook.get(container.getRaw(), LegacyContainerAnvilHook.class);
hook.textChangeCallback = () -> handleTextChange(view);
}
this._openInventories.add(view);
this.refreshButtons(view);
}
// If it couldn't be opened for anyone, close itself
if (this._openInventories.isEmpty()) {
setWindowOpen(false);
}
} else {
// Unregister event listener
CommonUtil.unregisterListener(this._listener);
// Deactivate the widget (to be sure)
deactivate();
// Event
onClose();
}
}
use of org.bukkit.plugin.java.JavaPlugin in project BKCommonLib by bergerhealer.
the class CommonMapController method handleMapShowEvent.
@SuppressWarnings("deprecation")
protected synchronized void handleMapShowEvent(MapShowEvent event) {
// Check if there are other map displays that should be shown to the player automatically
// This uses the 'isGlobal()' property of the display
MapDisplayInfo info = CommonMapController.this.getInfo(event.getMapUUID());
boolean hasDisplay = false;
if (info != null) {
for (MapSession session : info.getSessions()) {
if (session.display.isGlobal()) {
session.display.addOwner(event.getPlayer());
hasDisplay = true;
break;
}
}
}
// When defined in the NBT of the item, construct the Map Display automatically
// Do not do this when one was already assigned (global, or during event handling)
// We initialize the display the next tick using the plugin owner's task to avoid
// BKCommonLib showing up in timings when onAttached() is slow.
MapDisplayProperties properties = MapDisplayProperties.of(event.getMapItem());
if (!hasDisplay && !event.hasDisplay() && properties != null) {
Class<? extends MapDisplay> displayClass = properties.getMapDisplayClass();
if (displayClass != null) {
Plugin plugin = properties.getPlugin();
if (plugin instanceof JavaPlugin) {
try {
MapDisplay display = displayClass.newInstance();
event.setDisplay((JavaPlugin) plugin, display);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
CommonUtil.callEvent(event);
}
use of org.bukkit.plugin.java.JavaPlugin in project MyMaid2 by jaoafa.
the class Messenger method LoadMessenger.
/**
* メッセンジャーをロードする。
* @return 実行できたかどうか
* @author mine_book000
* @throws Exception 何かしらのExceptionが発生したときに発生(FileNotFoundException, IOException)
*/
public static boolean LoadMessenger() throws Exception {
Messages.clear();
JSONParser parser = new JSONParser();
String json = "";
try {
JavaPlugin plugin = JavaPlugin();
File file = new File(plugin.getDataFolder() + File.separator + "messenger.json");
BufferedReader br = new BufferedReader(new FileReader(file));
String separator = System.getProperty("line.separator");
String str;
while ((str = br.readLine()) != null) {
json += str + separator;
}
br.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
throw new FileNotFoundException(e1.getMessage());
} catch (IOException e1) {
e1.printStackTrace();
throw new IOException(e1.getMessage());
}
JSONArray array;
try {
array = (JSONArray) parser.parse(json);
} catch (ParseException e1) {
array = new JSONArray();
}
for (Object obj : array) {
String message = obj.toString();
Messages.add(message);
}
return true;
}
use of org.bukkit.plugin.java.JavaPlugin in project MyMaid2 by jaoafa.
the class Messenger method SaveMessenger.
/**
* メッセンジャーをセーブする。
* @return 実行できたかどうか
* @author mine_book000
* @throws Exception IOExceptionの発生時に発生
*/
@SuppressWarnings("unchecked")
public static boolean SaveMessenger() throws Exception {
JSONArray array = new JSONArray();
for (String message : Messages) {
array.add(message);
}
try {
JavaPlugin plugin = JavaPlugin();
File file = new File(plugin.getDataFolder() + File.separator + "messenger.json");
FileWriter filewriter = new FileWriter(file);
filewriter.write(array.toJSONString());
filewriter.close();
} catch (IOException e) {
e.printStackTrace();
throw new Exception("IOException");
}
return true;
}
Aggregations