SteamWar/BauSystem
Archiviert
13
0

Merge branch 'master' into ScriptComments

# Conflicts:
#	BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java
Dieser Commit ist enthalten in:
jojo 2020-12-12 16:35:26 +01:00
Commit 571e5a22ec
3 geänderte Dateien mit 81 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,31 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.world;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
class ScriptListener_12 {
private ScriptListener_12(){}
static boolean isNoBook(ItemStack item){
return item.getType() != Material.BOOK_AND_QUILL && item.getType() != Material.WRITTEN_BOOK;
}
}

Datei anzeigen

@ -0,0 +1,31 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.world;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
class ScriptListener_15 {
private ScriptListener_15(){}
static boolean isNoBook(ItemStack item){
return item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK;
}
}

Datei anzeigen

@ -19,12 +19,13 @@
package de.steamwar.bausystem.world;
import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
@ -39,7 +40,7 @@ public class ScriptListener implements Listener {
return;
ItemStack item = event.getItem();
if(item == null || (item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK) || item.getItemMeta() == null)
if(item == null || isNoBook(item) || item.getItemMeta() == null)
return;
event.setCancelled(true);
@ -48,10 +49,26 @@ public class ScriptListener implements Listener {
for(String page : meta.getPages()){
for(String command : page.split("\n")){
if (command.startsWith("#")) continue;
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
if(preprocessEvent.isCancelled())
continue;
Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command);
Bukkit.getServer().dispatchCommand(player, command);
}
}
}
private boolean isNoBook(ItemStack item){
switch(Core.getVersion()){
case 12:
return ScriptListener_12.isNoBook(item);
case 15:
default:
return ScriptListener_15.isNoBook(item);
}
}
}