Complete rewrite beginning:
- removed any old implementation - basic modul setup - using new hook system
This commit is contained in:
parent
2501aed96a
commit
f80a88174c
71 changed files with 513 additions and 4784 deletions
|
@ -1,69 +0,0 @@
|
|||
basic:
|
||||
loaded:
|
||||
worldguard: Erfolgreich mit WorldGuard-Integration geladen
|
||||
no_worldguard: Erfolgreich geladen (ohne WorldGuard)
|
||||
feature:
|
||||
store: Getrennte Inventare
|
||||
limit: Kreativ-Einschränkungen
|
||||
region: Kreativ-Regionen
|
||||
conflict: Wegen eines Konfliktes mit {0} ist die Funktion {1} deaktiviert
|
||||
warning:
|
||||
worldguard_not_found: WorldGuard wurd enicht gefunde, dahier ist die Funktion {0} deaktiviert
|
||||
# double single-quote '' because of MessageFormater to insert {0}
|
||||
command:
|
||||
player: Spieler
|
||||
switch:
|
||||
survival: ÿndert den Spiel-Modus des Charakters zu ÿberleben
|
||||
creative: ÿndert den Spiel-Modus des Charakters zu Kreativ
|
||||
adventure: ÿndert den Spiel-Modus des Charakters zu Abenteuer
|
||||
config:
|
||||
overview: "[Einstellung] - liste durch weglassen"
|
||||
settings: "Verfügbare Einstellungen: "
|
||||
reload: Lädt das Plugin neu (funktioniert nur teilweise)
|
||||
gamemode:
|
||||
changed: "{0}'s Spiel-Modus wurde geändert"
|
||||
no_change: Bereits in diesem Spiel-Modus
|
||||
option:
|
||||
done: Option geändert.
|
||||
worldguard:
|
||||
alias: Alias für den //region-Befehl
|
||||
unknown_flag: Unbekanntes Attribut
|
||||
available_flags: Verfügbare Attribute
|
||||
region_not_found: Keine Region mit dieser ID gefunden
|
||||
world_not_found: Es konnte keine Welt mit diesem Namen gefunden werden
|
||||
no_flag_given: Es muss ein Attribut angegeben werden, dass gesetzt werden soll
|
||||
no_integration: Der worldguard-Befehl ist nicht verfügbar, da WorldGuard nicht gefunden wurde
|
||||
flag_set: "Das Attribut {0} wurde gesetzt"
|
||||
additional_flags: Zusätzliche Attribute
|
||||
cmdblock:
|
||||
blocked: Dieser Befehl ist im Kreativ-Modus blockiert.
|
||||
exception:
|
||||
command:
|
||||
lackingpermission: Kein Zugriff auf diesen Befehl
|
||||
toomuchparameter: Zuviele Argumente angegeben
|
||||
missingparameter: Nicht genügen Argumente angegeben
|
||||
playernotfound: Spieler nicht gefunden
|
||||
invalidoption: Unbkeannte Option
|
||||
config:
|
||||
savefail: Die Konfiguration konnte nicht gespeichert werden
|
||||
material_not_found: (Konfiguration) Material mit Name/ID "{0}" wurde nicht gefunden.
|
||||
storage:
|
||||
load: Fehler beim Laden des Inventars. Bitte einen Admin die Option "UnsafeStorege" in LimitedCreative zu aktivieren um ungültig verzauberte Gegenstände zu erlauben
|
||||
region:
|
||||
not_optional: "In dieser Region kannst du nicht im folgenden Modus sein: {0}"
|
||||
blocked:
|
||||
chest: Zugriff auf Truhen ist im Kreativ-Modus nicht erlaubt
|
||||
sign: Im Kreativ-Modus kann nicht mit Schildern interagiert werden
|
||||
button: Im Kreativ-Modus kann nicht mit Buttons interagiert werden
|
||||
lever: Im Kreativ-Modus kann nicht mit Schaltern interagiert werden
|
||||
survival_flying: Du solltest auf dem Boden stehen wenn du Kreativ-Regionen verlässt
|
||||
outside_place: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen setzen
|
||||
outside_break: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen zerstören
|
||||
inside_place: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen setzen
|
||||
inside_break: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen zerstören
|
||||
use: Du darfst diese Art von Gegenständen im Kreativ-Modus verwenden
|
||||
place: Du darfst diese Art von Blöcken im Kreativ-Modus nicht setzen
|
||||
break: Du darfst diese Art von Blöcken im Kreativ-Modus nicht zerstören
|
||||
piston: Verschieben von Block {0} aus einer Spiel-Modus-Region bei {1} wurde blockiert
|
||||
piston_in: Verschieben von Block {0} in eine Spiel-Modus-Region bei {1} wurde blockiert
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
basic:
|
||||
loaded:
|
||||
worldguard: Successfully loaded with WorldGuard-Integration
|
||||
no_worldguard: Successfully loaded (without WorldGuard)
|
||||
feature:
|
||||
store: separated inventories
|
||||
limit: creative restrictions
|
||||
region: creative regions
|
||||
conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
|
||||
warning:
|
||||
worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled
|
||||
# double single-quote '' because of MessageFormater to insert {0}
|
||||
command:
|
||||
player: player
|
||||
switch:
|
||||
survival: Changes the game mode of a player to survival
|
||||
creative: Changes the game mode of a player to creative
|
||||
adventure: Changes the game mode of a player to adventure
|
||||
config:
|
||||
overview: "[setting] - empty for list of settings"
|
||||
settings: "Available Settings: "
|
||||
reload: Reloads plugin (doesn't work on update!)
|
||||
gamemode:
|
||||
changed: "{0}'s game mode has been changed"
|
||||
no_change: Already in that game mode.
|
||||
option:
|
||||
done: Option changed.
|
||||
worldguard:
|
||||
alias: Alias for //region-command
|
||||
unknown_flag: Unknown flag specified
|
||||
available_flags: Available flags
|
||||
region_not_found: Could not find a region by that ID
|
||||
world_not_found: Could not find a world by that name
|
||||
no_flag_given: You need to specify a flag to set
|
||||
no_integration: The worldguard-commands are not available, because worldguard wasn't found
|
||||
flag_set: "The flag {0} was set"
|
||||
additional_flags: Additional flags
|
||||
cmdblock:
|
||||
blocked: This command is blocked while in creative mode.
|
||||
exception:
|
||||
command:
|
||||
lackingpermission: You do not have access to this command
|
||||
toomuchparameter: Too much arguments given
|
||||
missingparameter: Not enough arguments given
|
||||
playernotfound: Player not found
|
||||
invalidoption: Unknown option
|
||||
config:
|
||||
savefail: Failed to write modified configuration to disk
|
||||
material_not_found: (Config) Material with name/id "{0}" was not found.
|
||||
storage:
|
||||
load: Failed to load your Inventory. Ask your Admin to enable "UnsafeStorage" for LimitedCreative to allow invalid enchants on items
|
||||
region:
|
||||
not_optional: You can not be {0} in that area
|
||||
blocked:
|
||||
chest: Access to chests is not allowed in creative mode
|
||||
sign: To interact with signs is not allowed in creative mode
|
||||
button: To interact with buttons is not allowed in creative mode
|
||||
lever: To interact with levers is not allowed in creative mode
|
||||
survival_flying: You should stay on ground, when leaving a creative-area
|
||||
outside_place: You can not place blocks outside of the gamemode-area
|
||||
outside_break: You can not destroy blocks outside of the gamemode-area
|
||||
inside_place: You can not place blocks inside of the gamemode-area
|
||||
inside_break: You can not destroy blocks inside of the gamemode-area
|
||||
use: You are not allowed to use this type of item
|
||||
place: You are not allowed to place this type of block
|
||||
break: You are not allowed to break this type of block
|
||||
piston: Moving {0} block out of creative area was blocked at {1}
|
||||
piston_in: Moving {0} block into creative area was blocked at {1}
|
55
lang/messages.properties
Normal file
55
lang/messages.properties
Normal file
|
@ -0,0 +1,55 @@
|
|||
basic.loaded.worldguard: Successfully loaded with WorldGuard-Integration
|
||||
basic.loaded.no_worldguard: Successfully loaded (without WorldGuard)
|
||||
basic.feature.store: separated inventories
|
||||
basic.feature.limit: creative restrictions
|
||||
basic.feature.region: creative regions
|
||||
basic.conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
|
||||
basic.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled
|
||||
# double single-quote '' because of MessageFormater to insert {0}
|
||||
|
||||
command.player: player
|
||||
command.switch.survival: Changes the game mode of a player to survival
|
||||
command.switch.creative: Changes the game mode of a player to creative
|
||||
command.switch.adventure: Changes the game mode of a player to adventure
|
||||
command.config.overview: [setting] - empty for list of settings
|
||||
command.config.settings: Available Settings:
|
||||
command.config.reload: Reloads plugin (doesn't work on update!)
|
||||
command.gamemode.changed: {0}'s game mode has been changed
|
||||
command.gamemode.no_change: Already in that game mode.
|
||||
command.option.done: Option changed.
|
||||
command.worldguard.alias: Alias for //region-command
|
||||
command.worldguard.unknown_flag: Unknown flag specified
|
||||
command.worldguard.available_flags: Available flags
|
||||
command.worldguard.region_not_found: Could not find a region by that ID
|
||||
command.worldguard.world_not_found: Could not find a world by that name
|
||||
command.worldguard.no_flag_given: You need to specify a flag to set
|
||||
command.worldguard.no_integration: The worldguard-commands are not available, because worldguard wasn't found
|
||||
command.worldguard.flag_set: "The flag {0} was set"
|
||||
command.worldguard.additional_flags: Additional flags
|
||||
|
||||
cmdblock.blocked: This command is blocked while in creative mode.
|
||||
|
||||
exception.command.lackingpermission: You do not have access to this command
|
||||
exception.command.toomuchparameter: Too much arguments given
|
||||
exception.command.missingparameter: Not enough arguments given
|
||||
exception.command.playernotfound: Player not found
|
||||
exception.command.invalidoption: Unknown option
|
||||
exception.config.savefail: Failed to write modified configuration to disk
|
||||
exception.config.material_not_found: (Config) Material with name/id "{0}" was not found.
|
||||
exception.storage.load: Failed to load your Inventory. Ask your Admin to enable "UnsafeStorage" for LimitedCreative to allow invalid enchants on items
|
||||
exception.region.not_optional: You can not be {0} in that area
|
||||
|
||||
blocked.chest: Access to chests is not allowed in creative mode
|
||||
blocked.sign: To interact with signs is not allowed in creative mode
|
||||
blocked.button: To interact with buttons is not allowed in creative mode
|
||||
blocked.lever: To interact with levers is not allowed in creative mode
|
||||
blocked.survival_flying: You should stay on ground, when leaving a creative-area
|
||||
blocked.outside_place: You can not place blocks outside of the gamemode-area
|
||||
blocked.outside_break: You can not destroy blocks outside of the gamemode-area
|
||||
blocked.inside_place: You can not place blocks inside of the gamemode-area
|
||||
blocked.inside_break: You can not destroy blocks inside of the gamemode-area
|
||||
blocked.use: You are not allowed to use this type of item
|
||||
blocked.place: You are not allowed to place this type of block
|
||||
blocked.break: You are not allowed to break this type of block
|
||||
blocked.piston: Moving {0} block out of creative area was blocked at {1}
|
||||
blocked.piston_in: Moving {0} block into creative area was blocked at {1}
|
5
pom.xml
5
pom.xml
|
@ -123,6 +123,7 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<!-- plugin.yml -->
|
||||
<mainClass>de.jaschastarke.minecraft.limitedcreative.LimitedCreative</mainClass>
|
||||
<softdepend>
|
||||
<param>WorldGuard</param>
|
||||
<param>WorldEdit</param>
|
||||
|
@ -132,7 +133,8 @@
|
|||
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
|
||||
</custom>
|
||||
<registeredPermissions>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.Perms:Root</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.Permissions</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions</param>
|
||||
</registeredPermissions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -149,6 +151,7 @@
|
|||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>de.jaschastarke:plib</include>
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
|
||||
//import org.bukkit.event.EventHandler;
|
||||
//import org.bukkit.event.Listener;
|
||||
/*import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;*/
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
abstract public class AbstractCommunicator /*implements Listener*/ {
|
||||
private JavaPlugin plugin;
|
||||
//private Map<Class<?>, CommunicationBridge> bridges = new HashMap<Class<?>, CommunicationBridge>();
|
||||
|
||||
public AbstractCommunicator(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
//plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
protected boolean isPluginEnabled(String plugin) {
|
||||
return this.plugin.getServer().getPluginManager().isPluginEnabled(plugin);
|
||||
}
|
||||
/*@SuppressWarnings("unchecked")
|
||||
protected <T extends CommunicationBridge> T getBridge(Class<T> cls) {
|
||||
if (!bridges.containsKey(cls)) {
|
||||
try {
|
||||
bridges.put(cls, cls.newInstance());
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return (T) bridges.get(cls);
|
||||
}*/
|
||||
|
||||
/*@EventHandler
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
|
||||
}
|
||||
@EventHandler
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
|
||||
}
|
||||
protected <T extends CommunicationBridge> boolean isPluginEnabled(String plugin, Class<T> cls) {
|
||||
if (!bridges.containsKey(plugin)) {
|
||||
if (this.plugin.getServer().getPluginManager().isPluginEnabled(plugin)) {
|
||||
|
||||
} else {
|
||||
bridges.put(plugin, null);
|
||||
}
|
||||
}
|
||||
return bridges.get(plugin) != null;
|
||||
}
|
||||
protected
|
||||
protected <T extends CommunicationBridge> T whenPluginEnabled(String plugin, Class<T> cls) {
|
||||
if (isPluginEnabled(plugin)) {
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.org.whoami.authme.cache.auth.PlayerCache;
|
||||
import uk.org.whoami.authme.cache.limbo.LimboCache;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class AuthMe implements CommunicationBridge {
|
||||
public static boolean isLoggedIn(Player player) {
|
||||
boolean li = PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase());
|
||||
Core.debug("AuthMe: "+player.getName()+": logged in: "+li);
|
||||
return li;
|
||||
}
|
||||
public static boolean isLoggedInComplete(Player player) {
|
||||
boolean li = isLoggedIn(player) && LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()) == null;
|
||||
Core.debug("AuthMe: "+player.getName()+": logged in complete: "+li);
|
||||
return li;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
public interface CommunicationBridge {
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class Communicator extends AbstractCommunicator {
|
||||
public Communicator(JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
public boolean isLoggedIn(Player player) {
|
||||
if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player))
|
||||
return false;
|
||||
if (isPluginEnabled("xAuth") && !xAuth.isLoggedInNotGuest(player))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCreative(World world) {
|
||||
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
|
||||
if (isMultiVerse()) {
|
||||
GameMode tmp = MultiVerse.getGameMode(world);
|
||||
if (tmp != null)
|
||||
creative = tmp == GameMode.CREATIVE;
|
||||
}
|
||||
Core.debug("com: "+world.getName()+": is creative: "+creative);
|
||||
return creative;
|
||||
}
|
||||
public GameMode getDefaultGameMode(World world) {
|
||||
GameMode def = Bukkit.getServer().getDefaultGameMode();
|
||||
if (isMultiVerse()) {
|
||||
GameMode tmp = MultiVerse.getGameMode(world);
|
||||
if (tmp != null)
|
||||
def = tmp;
|
||||
}
|
||||
Core.debug("com: "+world.getName()+": game mode: "+def);
|
||||
return def;
|
||||
}
|
||||
|
||||
public boolean isMultiVerse() {
|
||||
return isPluginEnabled("Multiverse-Core");
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class MultiVerse implements CommunicationBridge {
|
||||
public static GameMode getGameMode(World world) {
|
||||
MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world);
|
||||
if (mvWorld == null)
|
||||
return null;
|
||||
GameMode gm = mvWorld.getGameMode();
|
||||
Core.debug("Multiverse: "+world.getName()+": game mode: "+gm);
|
||||
return gm;
|
||||
}
|
||||
|
||||
private static MultiverseCore getMV() {
|
||||
return (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.integration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class xAuth implements CommunicationBridge {
|
||||
public static boolean isLoggedInNotGuest(Player player) {
|
||||
xAuthPlayer xpl = getAuth().getPlayerManager().getPlayer(player);
|
||||
boolean li = true;
|
||||
if (!xpl.isAuthenticated())
|
||||
li = false;
|
||||
else if (xpl.isGuest())
|
||||
li = false;
|
||||
Core.debug("xAuth: "+player.getName()+": logged in not guest: "+li);
|
||||
return li;
|
||||
}
|
||||
|
||||
private static com.cypherx.xauth.xAuth getAuth() {
|
||||
return (com.cypherx.xauth.xAuth) Bukkit.getServer().getPluginManager().getPlugin("xAuth");
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
abstract public class BlackList {
|
||||
|
||||
abstract public boolean matches(Block b);
|
||||
abstract public boolean matches(ItemStack item);
|
||||
|
||||
public static boolean isBlackListed(List<BlackList> list, Block block) {
|
||||
for (BlackList bl : list) {
|
||||
if (bl.matches(block))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean isBlackListed(List<BlackList> list, ItemStack item) {
|
||||
for (BlackList bl : list) {
|
||||
if (bl.matches(item))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Some extends BlackList {
|
||||
private Material mat;
|
||||
private int data = -1;
|
||||
public Some(Material material, int data) {
|
||||
mat = material;
|
||||
this.data = data;
|
||||
}
|
||||
public Some(Material material) {
|
||||
mat = material;
|
||||
}
|
||||
public Some(MaterialData md) {
|
||||
mat = md.getItemType();
|
||||
if (md.getData() != 0)
|
||||
this.data = md.getData();
|
||||
}
|
||||
public boolean matches(Block block) {
|
||||
if (this.mat == null)
|
||||
return true;
|
||||
if (this.mat != block.getType())
|
||||
return false;
|
||||
if (this.data != -1 && this.data != block.getData())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public boolean matches(ItemStack item) {
|
||||
if (this.mat == null)
|
||||
return true;
|
||||
if (this.mat != item.getType())
|
||||
return false;
|
||||
if (this.data != -1) {
|
||||
if (this.mat == Material.MONSTER_EGG) {
|
||||
if (this.data != item.getDurability())
|
||||
return false;
|
||||
} else {
|
||||
if (this.data != item.getData().getData())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class All extends BlackList {
|
||||
public boolean matches(Block b) {
|
||||
return true;
|
||||
}
|
||||
public boolean matches(ItemStack item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
import static de.jaschastarke.bukkit.lib.permissions.PermissionManager.hasPermission;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.utils.StringUtil;
|
||||
|
||||
public class Commands {
|
||||
private static Core plugin;
|
||||
public static class MainCommandExecutor implements CommandExecutor {
|
||||
|
||||
public enum Action {
|
||||
C, CREATIVE,
|
||||
S, SURVIVAL,
|
||||
A, ADVENTURE,
|
||||
E, ENABLE,
|
||||
D, DISABLE,
|
||||
R, REGION,
|
||||
RELOAD
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Core.debug(sender.getName() + ": /" + label + " " + StringUtil.join(args));
|
||||
if (args.length > 0) {
|
||||
Action act = null;
|
||||
try {
|
||||
act = Action.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {}
|
||||
if (act != null) {
|
||||
try {
|
||||
switch (act) {
|
||||
case C:
|
||||
case CREATIVE:
|
||||
this.setGameMode(GameMode.CREATIVE, sender, args);
|
||||
return true;
|
||||
case S:
|
||||
case SURVIVAL:
|
||||
this.setGameMode(GameMode.SURVIVAL, sender, args);
|
||||
return true;
|
||||
case A:
|
||||
case ADVENTURE:
|
||||
this.setGameMode(GameMode.ADVENTURE, sender, args);
|
||||
return true;
|
||||
case E:
|
||||
case ENABLE:
|
||||
this.setOption(sender, args, true);
|
||||
return true;
|
||||
case D:
|
||||
case DISABLE:
|
||||
this.setOption(sender, args, false);
|
||||
return true;
|
||||
case R:
|
||||
case REGION:
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
plugin.getCommand("/region").execute(sender, "/region", args);
|
||||
return true;
|
||||
case RELOAD:
|
||||
//plugin.getServer().getPluginManager().disablePlugin(plugin); // disable removes classloader, so re-enabling causes problems
|
||||
//plugin.getServer().getPluginManager().enablePlugin(plugin);
|
||||
plugin.reload();
|
||||
return true;
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
Core.debug("CommandException: "+e.getMessage());
|
||||
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String c = label;
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n");
|
||||
message.append("/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n");
|
||||
message.append("/"+c+" a[dventure] ["+L("command.player")+"] - "+L("command.switch.adventure")+"\n");
|
||||
if (hasPermission(sender, Perms.CONFIG)) {
|
||||
message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n");
|
||||
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
|
||||
message.append("/"+c+" reload "+L("command.config.reload")+"\n");
|
||||
}
|
||||
if (hasPermission(sender, Perms.REGIONS))
|
||||
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
|
||||
if (message.length() > 0) {
|
||||
sender.sendMessage("Usage:");
|
||||
for (String m : message.toString().split("\n")) {
|
||||
sender.sendMessage(m);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
|
||||
if (sender instanceof Player && !hasPermission(sender, Perms.CONFIG)) {
|
||||
throw new LackingPermissionException();
|
||||
}
|
||||
if (args.length > 2)
|
||||
throw new InvalidCommandException("exception.command.tomuchparameter");
|
||||
if (args.length < 2) {
|
||||
StringBuilder str = new StringBuilder(L("command.config.settings"));
|
||||
List<Configuration.Option> options = Configuration.Option.getAvailableOptions();
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
str.append(options.get(i).name().toLowerCase());
|
||||
if (i < options.size() - 1)
|
||||
str.append(", ");
|
||||
if ((i - 1) % 4 == 0) {
|
||||
sender.sendMessage(str.toString());
|
||||
str = new StringBuilder();
|
||||
}
|
||||
}
|
||||
if (str.length() > 0)
|
||||
sender.sendMessage(str.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
Configuration.Option opt = null;
|
||||
try {
|
||||
opt = Configuration.Option.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidCommandException("exception.command.invalidoption");
|
||||
}
|
||||
|
||||
plugin.config.set(opt, b);
|
||||
sender.sendMessage(L("command.option.done"));
|
||||
}
|
||||
|
||||
private void setGameMode(GameMode gm, CommandSender sender, String[] args) throws CommandException {
|
||||
Player target = null;
|
||||
if (args.length > 2)
|
||||
throw new InvalidCommandException("exception.command.tomuchparameter");
|
||||
if (args.length == 2)
|
||||
target = plugin.getServer().getPlayer(args[1]);
|
||||
else if (sender instanceof Player)
|
||||
target = (Player) sender;
|
||||
|
||||
if (target == null) {
|
||||
throw new InvalidCommandException("exception.command.playernotfound");
|
||||
} else if (sender instanceof Player && sender != target && !hasPermission(sender, Perms.GM_OTHER)) {
|
||||
throw new LackingPermissionException();
|
||||
} else if (target.getGameMode() != gm) {
|
||||
if ((hasPermission(sender, Perms.GM)) ||
|
||||
Players.get(target).isGameModeAllowed(gm) ||
|
||||
(gm == plugin.com.getDefaultGameMode(target.getWorld()) && hasPermission(sender, Perms.GM_BACKONLY)) ||
|
||||
(gm == GameMode.CREATIVE && hasPermission(sender, Perms.GM_CREATIVE)) ||
|
||||
(gm == GameMode.SURVIVAL && hasPermission(sender, Perms.GM_SURVIVAL)) ||
|
||||
(gm == GameMode.ADVENTURE && hasPermission(sender, Perms.GM_ADVENTURE))) {
|
||||
target.setGameMode(gm);
|
||||
} else {
|
||||
throw new LackingPermissionException();
|
||||
}
|
||||
if (target != sender) {
|
||||
sender.sendMessage(L("command.gamemode.changed", target.getName()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(L("command.gamemode.no_change"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NotAvailableCommandExecutor implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.no_integration"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void register(Core pplugin) {
|
||||
plugin = pplugin;
|
||||
plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor());
|
||||
if (plugin.worldguard == null) {
|
||||
plugin.getCommand("/region").setExecutor(new NotAvailableCommandExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
abstract static public class CommandException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CommandException(String s) {super(s);}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return L(super.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public static class InvalidCommandException extends CommandException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidCommandException(String s) {super(s);}
|
||||
}
|
||||
public static class LackingPermissionException extends CommandException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LackingPermissionException() {super("exception.command.lackingpermission");}
|
||||
}
|
||||
}
|
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
import static de.jaschastarke.utils.StringUtil.copyFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.cmdblock.ICmdBlockEntry;
|
||||
import de.jaschastarke.minecraft.limitedcreative.cmdblock.RegexpBlockEntry;
|
||||
import de.jaschastarke.minecraft.limitedcreative.cmdblock.StringBlockEntry;
|
||||
import de.jaschastarke.minecraft.limitedcreative.store.InvYamlStorage;
|
||||
import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage;
|
||||
|
||||
public class Configuration {
|
||||
private FileConfiguration c;
|
||||
private File file;
|
||||
public static Core plugin;
|
||||
|
||||
public enum Option {
|
||||
STORECREATIVE("store.creative", true),
|
||||
CREATIVEARMOR("store.armor.enabled", true),
|
||||
ADVENTUREINV("store.adventure", false),
|
||||
REGION_OPTIONAL("region.optional", true),
|
||||
REGION_REMEMBER("region.remember", false),
|
||||
BLOCKPICKUP("limit.pickup", true),
|
||||
BLOCKSIGN("limit.sign", true),
|
||||
BLOCKBUTTON("limit.button", false),
|
||||
BLOCKDAMAGEMOB("limit.damagemob", false),
|
||||
BLOCKBENCHES("limit.workbench", false),
|
||||
REMOVEDROP("limit.remove_drops", true),
|
||||
REMOVEPICKUP("limit.remove_pickup", false),
|
||||
PERM_WEPIF("permissions.wepif", true),
|
||||
CMDBLOCKER("cmdblocker.enabled", true),
|
||||
DEBUG("debug", false);
|
||||
|
||||
private String key;
|
||||
private boolean _default;
|
||||
private Option(String key, boolean def) {
|
||||
this.key = key;
|
||||
this._default = def;
|
||||
}
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public boolean getDefault() {
|
||||
return _default;
|
||||
}
|
||||
public static List<Option> getAvailableOptions() {
|
||||
List<Option> ret = new ArrayList<Option>(Arrays.asList(Option.values()));
|
||||
ret.remove(Option.DEBUG); // keep it undocumented ;)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration(Core pplugin) {
|
||||
plugin = pplugin;
|
||||
|
||||
file = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!file.exists())
|
||||
//plugin.saveDefaultConfig();
|
||||
copyFile(plugin.getResource("config.yml"), file);
|
||||
|
||||
c = plugin.getConfig();
|
||||
}
|
||||
|
||||
public void set(Option opt, boolean value) {
|
||||
/*if (!opt.isSetAble())
|
||||
throw new IllegalArgumentException("Setting this option is not allowed");*/
|
||||
this.reload();
|
||||
c.set(opt.getKey(), value);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public boolean getBoolean(Option opt) {
|
||||
return c.getBoolean(opt.getKey(), opt.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended to be undocumented ;)
|
||||
*/
|
||||
public boolean getDebug() {
|
||||
return this.getBoolean(Option.DEBUG);
|
||||
}
|
||||
|
||||
public boolean getStoreEnabled() {
|
||||
return getTempStoreEnabled() && c.getBoolean("store.enabled", true);
|
||||
}
|
||||
public boolean getLimitEnabled() {
|
||||
return c.getBoolean("limit.enabled", true);
|
||||
}
|
||||
public boolean getRegionEnabled() {
|
||||
return c.getBoolean("region.enabled", true);
|
||||
}
|
||||
|
||||
public boolean getStoreCreative() {
|
||||
return this.getBoolean(Option.STORECREATIVE);
|
||||
}
|
||||
public boolean getUnsafeStorage() {
|
||||
return c.getBoolean("store.unsafe", false);
|
||||
}
|
||||
public String getInventoryFolder() {
|
||||
return c.getString("store.folder", "inventories");
|
||||
}
|
||||
public boolean getAdventureInv() {
|
||||
return this.getBoolean(Option.ADVENTUREINV);
|
||||
}
|
||||
public boolean getBlockPickupInCreative() {
|
||||
return this.getBoolean(Option.BLOCKPICKUP);
|
||||
}
|
||||
public boolean getSignBlock() {
|
||||
return this.getBoolean(Option.BLOCKSIGN);
|
||||
}
|
||||
public boolean getBenchBlock() {
|
||||
return this.getBoolean(Option.BLOCKBENCHES);
|
||||
}
|
||||
public boolean getButtonBlock() {
|
||||
return this.getBoolean(Option.BLOCKBUTTON);
|
||||
}
|
||||
public boolean getRemoveDrop() {
|
||||
return this.getBoolean(Option.REMOVEDROP);
|
||||
}
|
||||
public boolean getRemovePickup() {
|
||||
return this.getBoolean(Option.REMOVEPICKUP);
|
||||
}
|
||||
public boolean getMobDamageBlock() {
|
||||
return this.getBoolean(Option.BLOCKDAMAGEMOB);
|
||||
}
|
||||
|
||||
public boolean getWEPIFEnabled() {
|
||||
return this.getBoolean(Option.PERM_WEPIF);
|
||||
}
|
||||
public boolean getRegionOptional() {
|
||||
return this.getBoolean(Option.REGION_OPTIONAL);
|
||||
}
|
||||
public boolean getRegionRememberOptional() {
|
||||
return this.getRegionOptional() && this.getBoolean(Option.REGION_REMEMBER);
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
if (c.contains("locale") && c.getString("locale") != "none")
|
||||
return c.getString("locale");
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void reload() {
|
||||
_block_break = null;
|
||||
_block_use = null;
|
||||
plugin.reloadConfig();
|
||||
c = plugin.getConfig();
|
||||
}
|
||||
protected void save() {
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private List<BlackList> _block_break = null;
|
||||
private List<BlackList> _block_use = null;
|
||||
|
||||
public List<BlackList> getBlockedBreaks() {
|
||||
if (_block_break == null)
|
||||
_block_break = parseMaterialList(c.getStringList("limit.break"));
|
||||
return _block_break;
|
||||
}
|
||||
|
||||
public List<BlackList> getBlockedUse() {
|
||||
if (_block_use == null)
|
||||
_block_use = parseMaterialList(c.getStringList("limit.use"));
|
||||
return _block_use;
|
||||
}
|
||||
|
||||
private List<BlackList> parseMaterialList(List<String> s) {
|
||||
List<BlackList> list = new ArrayList<BlackList>();
|
||||
if (s != null) {
|
||||
for (String m : s) {
|
||||
if (m.equals("*")) {
|
||||
list.clear();
|
||||
list.add(new BlackList.All());
|
||||
break;
|
||||
} else {
|
||||
MaterialData md = parseMaterial(m);
|
||||
if (md != null)
|
||||
list.add(new BlackList.Some(md));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private MaterialData parseMaterial(String m) {
|
||||
int d = -1;
|
||||
if (m.contains(":")) {
|
||||
String[] t = m.split(":");
|
||||
m = t[0];
|
||||
try {
|
||||
d = Integer.parseInt(t[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
// TODO: try to find the data value by
|
||||
if (d == -1)
|
||||
plugin.warn(L("exception.config.materiak_data_not_found", t[1]));
|
||||
}
|
||||
}
|
||||
Material e = null;
|
||||
try {
|
||||
e = Material.getMaterial(Integer.parseInt(m));
|
||||
} catch (NumberFormatException ex) {
|
||||
e = Material.matchMaterial(m);
|
||||
}
|
||||
if (e == null) {
|
||||
plugin.warn(L("exception.config.material_not_found", m));
|
||||
return null;
|
||||
}
|
||||
if (d != -1)
|
||||
return new MaterialData(e, (byte) d);
|
||||
else
|
||||
return new MaterialData(e);
|
||||
}
|
||||
|
||||
private boolean _store_enabled = true;
|
||||
public void setTempStoreEnabled(boolean b) {
|
||||
_store_enabled = b;
|
||||
}
|
||||
public boolean getTempStoreEnabled() {
|
||||
return _store_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Milliseconds
|
||||
*/
|
||||
public long getRepeatingMessageTimeout() {
|
||||
return 10000; // 10 sec. limit
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum height a player may fall down by leaving creative gamemode
|
||||
* @return Block-Height
|
||||
*/
|
||||
public int getMaximumFloatingHeight() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public PlayerInventoryStorage getInvetoryStorage() {
|
||||
return new InvYamlStorage(new File(plugin.getDataFolder(), getInventoryFolder()));
|
||||
}
|
||||
|
||||
public Map<String, MaterialData> getCreativeArmor() {
|
||||
if (c.contains("store.armor") && c.isConfigurationSection("store.armor")) {
|
||||
ConfigurationSection sect = c.getConfigurationSection("store.armor");
|
||||
if (sect.getBoolean("enabled")) {
|
||||
Map<String, MaterialData> armor = new HashMap<String, MaterialData>();
|
||||
for (Map.Entry<String, Object> entry : sect.getValues(false).entrySet()) {
|
||||
if (!entry.getKey().equals("enabled")) {
|
||||
MaterialData md = parseMaterial((String) entry.getValue());
|
||||
if (md != null)
|
||||
armor.put(entry.getKey(), md);
|
||||
}
|
||||
}
|
||||
return armor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getCommandBlockerEnabled() {
|
||||
return this.getBoolean(Option.CMDBLOCKER);
|
||||
}
|
||||
|
||||
private List<ICmdBlockEntry> _blocklist = null;
|
||||
public List<ICmdBlockEntry> getCommandBlockList() {
|
||||
if (_blocklist == null) {
|
||||
_blocklist = new ArrayList<ICmdBlockEntry>();
|
||||
for (String cmd : c.getStringList("cmdblock.commands")) {
|
||||
if (cmd.startsWith("^")) {
|
||||
_blocklist.add(new RegexpBlockEntry(cmd));
|
||||
} else {
|
||||
_blocklist.add(new StringBlockEntry(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
return _blocklist;
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.locale.PluginLang;
|
||||
import de.jaschastarke.minecraft.integration.Communicator;
|
||||
import de.jaschastarke.minecraft.limitedcreative.cmdblock.CommandBlocker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.LimitListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||
import de.jaschastarke.minecraft.utils.Permissions;
|
||||
|
||||
public class Core extends de.jaschastarke.bukkit.lib.Core {
|
||||
public Configuration config;
|
||||
public Permissions perm;
|
||||
public WorldGuardIntegration worldguard;
|
||||
public Communicator com;
|
||||
public static Core plugin;
|
||||
public NoBlockItemSpawn spawnblock;
|
||||
public CommandBlocker cmdblock;
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
plugin.getServer().getScheduler().cancelTasks(this);
|
||||
if (worldguard != null)
|
||||
worldguard.unload();
|
||||
|
||||
plugin = null;
|
||||
worldguard = null;
|
||||
config = null;
|
||||
spawnblock = null;
|
||||
com = null;
|
||||
cmdblock = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
config = new Configuration(this);
|
||||
perm = new Permissions(this);
|
||||
com = new Communicator(this);
|
||||
|
||||
new PluginLang(this, config.getLocale());
|
||||
|
||||
spawnblock = new NoBlockItemSpawn();
|
||||
|
||||
// 1st Feature: Separated Inventories Storage
|
||||
if (config.getStoreEnabled() && getServer().getPluginManager().isPluginEnabled("MultiInv")) {
|
||||
warn(L("basic.conflict", "MultiInv", L("basic.feature.store")));
|
||||
config.setTempStoreEnabled(false);
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new MainListener(this), this);
|
||||
|
||||
// 2nd Feature: Creative Limitations (Restrictions)
|
||||
if (config.getLimitEnabled())
|
||||
getServer().getPluginManager().registerEvents(new LimitListener(this), this);
|
||||
|
||||
// 3rd Feature: WorldGuard Region-Support
|
||||
if (config.getRegionEnabled() && getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
worldguard = new WorldGuardIntegration(this);
|
||||
} else if(config.getRegionEnabled()) {
|
||||
warn(L("basic.warning.worldguard_not_found", L("basic.feature.region")));
|
||||
}
|
||||
|
||||
// 4th Feature: Command Blocker
|
||||
if (config.getCommandBlockerEnabled())
|
||||
cmdblock = new CommandBlocker(this);
|
||||
|
||||
debug("Store: " + config.getStoreEnabled());
|
||||
debug("Limit: " + config.getLimitEnabled());
|
||||
debug("Region: " + (worldguard != null));
|
||||
debug("CmdBlock: " + config.getCommandBlockerEnabled());
|
||||
|
||||
Commands.register(this);
|
||||
|
||||
/*plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Players.cleanUp();
|
||||
}
|
||||
}, Players.CLEANUP_TIMEOUT / 50L, Players.CLEANUP_TIMEOUT / 50L); // 50 = 1000ms / 20ticks*/
|
||||
|
||||
PluginDescriptionFile df = this.getDescription();
|
||||
if (worldguard != null)
|
||||
getLog().info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.worldguard"));
|
||||
else
|
||||
getLog().info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.no_worldguard"));
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
getServer().getServicesManager().unregisterAll(this);
|
||||
HandlerList.unregisterAll(this);
|
||||
setEnabled(false);
|
||||
setEnabled(true);
|
||||
}
|
||||
public void info(String s) {
|
||||
getLog().info("["+this.getDescription().getName()+"] " + s);
|
||||
}
|
||||
public void warn(String s) {
|
||||
getLog().warning("["+this.getDescription().getName()+"] " + s);
|
||||
}
|
||||
public void error(String s) {
|
||||
getLog().severe("["+this.getDescription().getName()+"] " + s);
|
||||
}
|
||||
/**
|
||||
* Static localization-access only works for first locale instance. if used by another plugin, you need to
|
||||
* access the Locale-Instance get-Method
|
||||
*/
|
||||
public static String L(String msg, Object... objects) {
|
||||
return (plugin.getTranslation() != null) ? plugin.getTranslation().get(msg, objects) : msg;
|
||||
}
|
||||
|
||||
public static void debug(String s) {
|
||||
if (isDebug())
|
||||
plugin.info("DEBUG: " + s);
|
||||
}
|
||||
public static boolean isDebug() {
|
||||
return plugin.config.getDebug();
|
||||
}
|
||||
}
|
|
@ -1,20 +1,3 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -25,14 +8,20 @@ import org.bukkit.Location;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
|
||||
/**
|
||||
* The "Block" means a Minecraft-Block, not "blocking". So this Class is used to prevent ItemSpawn which are Drops from
|
||||
* specified Blocks.
|
||||
*/
|
||||
public class NoBlockItemSpawn {
|
||||
public class FeatureBlockItemSpawn extends CoreModule implements Listener {
|
||||
public FeatureBlockItemSpawn(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
public final static long TIME_OFFSET = 250;
|
||||
|
||||
private List<BlockItemDrop> list = new ArrayList<BlockItemDrop>();
|
||||
|
@ -40,7 +29,7 @@ public class NoBlockItemSpawn {
|
|||
public boolean isBlocked(Location l, Material type) {
|
||||
cleanup();
|
||||
for (BlockItemDrop block : list) {
|
||||
if (block.getLocation().equals(l) && block.getType().equals(type))
|
||||
if (block.getLocation().equals(l) && (block.getType() == null || block.getType().equals(type)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -74,12 +63,12 @@ public class NoBlockItemSpawn {
|
|||
}
|
||||
}
|
||||
|
||||
public void block(Block block, LCPlayer player) {
|
||||
if (player.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
public void block(Block block, Player player) {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
block(block.getLocation(), block.getType());
|
||||
} else {
|
||||
// doesn't include silktouch
|
||||
for (ItemStack i : block.getDrops(player.getPlayer().getItemInHand())) {
|
||||
for (ItemStack i : block.getDrops(player.getItemInHand())) {
|
||||
block(block.getLocation(), i.getType());
|
||||
}
|
||||
}
|
||||
|
@ -91,4 +80,15 @@ public class NoBlockItemSpawn {
|
|||
public void block(Location l, Material type) {
|
||||
list.add(new BlockItemDrop(l, type));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
src/de/jaschastarke/minecraft/limitedcreative/Hooks.java
Normal file
36
src/de/jaschastarke/minecraft/limitedcreative/Hooks.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import de.jaschastarke.hooking.BooleanHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks;
|
||||
|
||||
public final class Hooks {
|
||||
public static PlayerCheckHooker IsLoggedIn = new PlayerCheckHooker(true);
|
||||
public static WorldTypeHooker DefaultWorldGameMode = new WorldTypeHooker();
|
||||
public static BooleanHooker IsMultiVerse = new BooleanHooker(false);
|
||||
|
||||
public static boolean isPluginEnabled(String pluginName) {
|
||||
return Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName);
|
||||
}
|
||||
|
||||
public static void inizializeHooks(LimitedCreative plugin) {
|
||||
IsLoggedIn.clearHooks();
|
||||
DefaultWorldGameMode.clearHooks();
|
||||
IsMultiVerse.clearHooks();
|
||||
|
||||
if (isPluginEnabled("AuthMe")) {
|
||||
new AuthMeHooks(plugin);
|
||||
}
|
||||
if (isPluginEnabled("xAuth")) {
|
||||
new xAuthHooks(plugin);
|
||||
}
|
||||
if (isPluginEnabled("Multiverse-Core")) {
|
||||
new MultiVerseHooks(plugin);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage;
|
||||
|
||||
public class Inventory {
|
||||
private static PlayerInventoryStorage storage = Core.plugin.config.getInvetoryStorage();
|
||||
//private static InvMemStorage tempinvs = new InvMemStorage();
|
||||
|
||||
protected LCPlayer player;
|
||||
|
||||
public enum Target {
|
||||
SURVIVAL,
|
||||
CREATIVE,
|
||||
ADVENTURE;
|
||||
|
||||
public static Target getTarget(GameMode gm) {
|
||||
return Target.valueOf(gm.name());
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory(LCPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
public LCPlayer getLCPlayer() {
|
||||
return player;
|
||||
}
|
||||
public Player getPlayer() {
|
||||
return player.getPlayer();
|
||||
}
|
||||
|
||||
private PlayerInventory inv() {
|
||||
return player.getPlayer().getInventory();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
Core.debug(getPlayer().getName()+": store inventory: "+getPlayer().getGameMode());
|
||||
storage.store(this, Target.getTarget(getPlayer().getGameMode()));
|
||||
}
|
||||
public void save(GameMode gm) {
|
||||
Core.debug(getPlayer().getName()+": store inventory: "+gm);
|
||||
storage.store(this, Target.getTarget(gm));
|
||||
}
|
||||
|
||||
public void load() {
|
||||
load(getPlayer().getGameMode());
|
||||
}
|
||||
|
||||
public boolean isStored(GameMode gm) {
|
||||
return storage.contains(this, Target.getTarget(gm));
|
||||
}
|
||||
|
||||
public void load(GameMode gm) {
|
||||
Core.debug(getPlayer().getName()+": load inventory: "+gm);
|
||||
try {
|
||||
storage.load(this, Target.getTarget(gm));
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (Core.plugin.config.getUnsafeStorage()) {
|
||||
throw e;
|
||||
} else {
|
||||
getPlayer().sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public void storeTemp() {
|
||||
Core.debug(getPlayer().getName()+": temp store inventory");
|
||||
tempinvs.store(this);
|
||||
}
|
||||
public void restoreTemp() {
|
||||
Core.debug(getPlayer().getName()+": temp restore inventory");
|
||||
tempinvs.load(this);
|
||||
}
|
||||
public void clearTemp() {
|
||||
Core.debug(getPlayer().getName()+": temp clear inventory");
|
||||
tempinvs.remove(this);
|
||||
}*/
|
||||
|
||||
public void clear() {
|
||||
inv().setArmorContents(new ItemStack[0]);
|
||||
inv().clear();
|
||||
}
|
||||
}
|
|
@ -1,524 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Lever;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.NoLimitPerms;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerAreaEvent;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
|
||||
|
||||
public class LCPlayer {
|
||||
private static Core plugin = Core.plugin;
|
||||
|
||||
private Player player;
|
||||
//private String name;
|
||||
private Inventory _inv;
|
||||
private GameMode _permanent_gamemode = null;
|
||||
//private long _timestamp;
|
||||
|
||||
public LCPlayer(Player player) {
|
||||
this.player = player;
|
||||
//name = player.getName();
|
||||
//touch();
|
||||
|
||||
if (!this.isActiveRegionGameMode(player.getGameMode())) {
|
||||
setInPermanentGameMode(player.getGameMode());
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
//return plugin.getServer().getPlayerExact(name); (doesn't work will revive)
|
||||
}
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
public Inventory getInv() {
|
||||
if (_inv == null)
|
||||
_inv = new Inventory(this);
|
||||
return _inv;
|
||||
}
|
||||
|
||||
/*public void touch() {
|
||||
_timestamp = System.currentTimeMillis();
|
||||
}
|
||||
public boolean isOutdated() {
|
||||
return (getPlayer() == null || !getPlayer().isOnline()) &&
|
||||
_timestamp < (System.currentTimeMillis() - Players.CLEANUP_TIMEOUT);
|
||||
}*/
|
||||
|
||||
private Map<String, Object> options = new HashMap<String, Object>();
|
||||
public void storeActiveRegionGameMode(final GameMode gm) {
|
||||
options.remove("region");
|
||||
Core.debug(getName()+": set region game mode: " + gm);
|
||||
Players.getOptions().setRegionGameMode(getName(), gm);
|
||||
}
|
||||
|
||||
public GameMode getActiveRegionGameMode() {
|
||||
if (!options.containsKey("region")) {
|
||||
options.put("region", Players.getOptions().getRegionGameMode(getName()));
|
||||
}
|
||||
Core.debug(getName()+": get region game mode: " + options.get("region"));
|
||||
return (GameMode) options.get("region");
|
||||
}
|
||||
public boolean isActiveRegionGameMode(final GameMode gm) {
|
||||
return gm.equals(getActiveRegionGameMode());
|
||||
}
|
||||
public boolean isActiveRegionGameMode() {
|
||||
return getActiveRegionGameMode() != null;
|
||||
}
|
||||
|
||||
public boolean isOptionalRegionGameMode() {
|
||||
return getOptionalRegionGameMode() != null;
|
||||
}
|
||||
public boolean isOptionalRegionGameMode(final GameMode gm) {
|
||||
return gm.equals(getOptionalRegionGameMode());
|
||||
}
|
||||
public boolean isOptionalRegionGameMode(final String region, final GameMode gm) {
|
||||
return gm.equals(getOptionalRegionGameMode(region));
|
||||
}
|
||||
private GameMode getOptionalRegionGameMode() {
|
||||
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
|
||||
return getOptionalRegionGameMode(region);
|
||||
}
|
||||
private GameMode getOptionalRegionGameMode(String region) {
|
||||
if (!plugin.config.getRegionRememberOptional())
|
||||
return null;
|
||||
if (!options.containsKey("region_opt#"+region)) {
|
||||
options.put("region_opt#"+region, Players.getOptions().getOptionalRegionGameMode(getName(), region));
|
||||
}
|
||||
Core.debug(getName()+": get optional region game mode: "+region+" - " + options.get("region_opt#"+region));
|
||||
return (GameMode) options.get("region_opt#"+region);
|
||||
}
|
||||
|
||||
public void setOptionalRegionGameMode(GameMode gm) {
|
||||
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
|
||||
setOptionalRegionGameMode(region, gm);
|
||||
}
|
||||
public void setOptionalRegionGameMode(String region, GameMode gm) {
|
||||
if (!plugin.config.getRegionRememberOptional())
|
||||
return;
|
||||
options.remove("region_opt#"+region);
|
||||
Core.debug(getName()+": set optional region game mode: "+region+" - " + gm);
|
||||
Players.getOptions().setOptionalRegionGameMode(getName(), region, gm);
|
||||
}
|
||||
|
||||
public void setInPermanentGameMode(GameMode temp) {
|
||||
Core.debug(getName()+": set permanent game mode: " + temp);
|
||||
if (temp != null) {
|
||||
if (temp.equals(plugin.com.getDefaultGameMode(getPlayer().getWorld()))) {
|
||||
temp = null;
|
||||
} else {
|
||||
storeActiveRegionGameMode(null);
|
||||
}
|
||||
}
|
||||
_permanent_gamemode = temp;
|
||||
}
|
||||
public boolean isInPermanentGameMode() {
|
||||
return isInPermanentGameMode(getPlayer().getGameMode());
|
||||
}
|
||||
public boolean isInPermanentGameMode(GameMode temp) {
|
||||
Core.debug(getName()+": get permanent game mode: " + _permanent_gamemode);
|
||||
return temp.equals(_permanent_gamemode);
|
||||
}
|
||||
|
||||
public boolean onSetGameMode(GameMode gm) {
|
||||
Core.debug(getName() + " going into " + gm);
|
||||
if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines
|
||||
if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
|
||||
if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) {
|
||||
getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
|
||||
Core.debug("... denied");
|
||||
return false;
|
||||
} else {
|
||||
setOptionalRegionGameMode(gm);
|
||||
}
|
||||
} else {
|
||||
// we are changing to the mode the region defines, thats not permanent
|
||||
setOptionalRegionGameMode(null);
|
||||
setInPermanentGameMode(null);
|
||||
}
|
||||
} else {
|
||||
setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature 1: Separated Inventories / Storage
|
||||
*/
|
||||
if (plugin.config.getStoreEnabled()) {
|
||||
if (hasPermission(Perms.KEEPINVENTORY))
|
||||
return true;
|
||||
getPlayer().closeInventory();
|
||||
|
||||
GameMode cgm = getPlayer().getGameMode();
|
||||
if (gm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
||||
gm = GameMode.SURVIVAL;
|
||||
if (cgm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
||||
cgm = GameMode.SURVIVAL;
|
||||
|
||||
if (gm != cgm) {
|
||||
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) {
|
||||
getInv().save(cgm);
|
||||
}
|
||||
if (gm == GameMode.CREATIVE) {
|
||||
if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) {
|
||||
getInv().load(GameMode.CREATIVE);
|
||||
} else {
|
||||
getInv().clear();
|
||||
}
|
||||
setCreativeArmor();
|
||||
} else if (gm == GameMode.SURVIVAL) {
|
||||
if (getInv().isStored(GameMode.SURVIVAL))
|
||||
getInv().load(GameMode.SURVIVAL);
|
||||
} else if (gm == GameMode.ADVENTURE) {
|
||||
if (getInv().isStored(GameMode.ADVENTURE))
|
||||
getInv().load(GameMode.ADVENTURE);
|
||||
else
|
||||
getInv().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onRevive() {
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
setCreativeArmor();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreativeArmor() {
|
||||
Map<String, MaterialData> armor = plugin.config.getCreativeArmor();
|
||||
if (armor != null) {
|
||||
ItemStack[] is = new ItemStack[4];
|
||||
if (armor.containsKey("feet"))
|
||||
is[0] = armor.get("feet").toItemStack(1);
|
||||
if (armor.containsKey("legs"))
|
||||
is[1] = armor.get("legs").toItemStack(1);
|
||||
if (armor.containsKey("chest"))
|
||||
is[2] = armor.get("chest").toItemStack(1);
|
||||
if (armor.containsKey("head"))
|
||||
is[3] = armor.get("head").toItemStack(1);
|
||||
getPlayer().getInventory().setArmorContents(is);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDropItem(PlayerDropItemEvent event) {
|
||||
Core.debug(getName() + " ("+getPlayer().getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType());
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (hasPermission(NoLimitPerms.DROP))
|
||||
return;
|
||||
Core.debug("removed");
|
||||
if (plugin.config.getRemoveDrop())
|
||||
event.getItemDrop().remove();
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
public void onPickupItem(PlayerPickupItemEvent event) {
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (hasPermission(NoLimitPerms.PICKUP))
|
||||
return;
|
||||
if (plugin.config.getBlockPickupInCreative()) {
|
||||
event.setCancelled(true);
|
||||
} else if(plugin.config.getRemovePickup()) {
|
||||
event.getItem().remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDie(EntityDeathEvent event) {
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!hasPermission(NoLimitPerms.DROP)) {
|
||||
event.getDrops().clear();
|
||||
//getInv().storeTemp();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* removed, because much to insecure. also we can save memory with out this
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission(NoLimitPerms.DROP)) {
|
||||
getInv().restoreTemp();
|
||||
}
|
||||
}
|
||||
getInv().clearTemp();
|
||||
}*/
|
||||
|
||||
public void onDamage(Entity from, EntityDamageByEntityEvent event) { // receives damage
|
||||
if (from instanceof Player) {
|
||||
// its PVP
|
||||
Player attacker = (Player) from;
|
||||
if (attacker.getGameMode() == GameMode.CREATIVE) {
|
||||
if (!Players.get(attacker).hasPermission(NoLimitPerms.PVP)) {
|
||||
event.setCancelled(true);
|
||||
return; // skip next check
|
||||
}
|
||||
}
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!hasPermission(NoLimitPerms.PVP)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage
|
||||
if (event.getEntity() instanceof Creature) {
|
||||
if (getPlayer().getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
||||
if (!hasPermission(NoLimitPerms.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* don't let the player be target by creatures he can't kill
|
||||
*/
|
||||
public void onTarget(EntityTargetEvent event) {
|
||||
if (event.getEntity() instanceof Creature) {
|
||||
if (((Player) event.getTarget()).getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
||||
if (!hasPermission(NoLimitPerms.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onChestAccess(PlayerInteractEvent event) {
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (hasPermission(NoLimitPerms.CHEST))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
|
||||
if (getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (hasPermission(NoLimitPerms.CHEST))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
public void onBenchAccess(PlayerInteractEvent event) {
|
||||
if (!plugin.config.getBenchBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (hasPermission(NoLimitPerms.CHEST))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
public void onSignAccess(PlayerInteractEvent event) {
|
||||
if (!plugin.config.getSignBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (hasPermission(NoLimitPerms.SIGN))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.sign"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
public void onButtonAccess(PlayerInteractEvent event) {
|
||||
if (!plugin.config.getButtonBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
if (event.getClickedBlock().getState() instanceof Lever) {
|
||||
if (hasPermission(NoLimitPerms.LEVER))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.lever"));
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
if (hasPermission(NoLimitPerms.BUTTON))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.button"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkSwitchFlight(PlayerMoveEvent event) {
|
||||
if (event != null && getPlayer().getGameMode() == GameMode.CREATIVE && getFloatingHeight(event.getTo()) > plugin.config.getMaximumFloatingHeight()) {
|
||||
// but not if he is too high
|
||||
this.sendTimeoutMessage(L("blocked.survival_flying"));
|
||||
|
||||
Location newloc = event.getTo().clone();
|
||||
newloc.setX(event.getFrom().getX());
|
||||
newloc.setY(event.getFrom().getY()); // well, otherwise flying high out of the region is possible
|
||||
newloc.setZ(event.getFrom().getZ());
|
||||
event.setTo(newloc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private boolean checkSwitchFlight(PlayerAreaEvent area_event) {
|
||||
if (area_event instanceof PlayerChangedAreaEvent) {
|
||||
if (!checkSwitchFlight(((PlayerChangedAreaEvent) area_event).getMoveEvent())) {
|
||||
((PlayerChangedAreaEvent) area_event).setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world".
|
||||
*/
|
||||
public void setRegionGameMode(GameMode region_gamemode, PlayerAreaEvent area_event) {
|
||||
Core.debug(getName()+": changed region: "+region_gamemode+": " + area_event);
|
||||
|
||||
PlayerMoveEvent event = null;
|
||||
if (area_event instanceof PlayerChangedAreaEvent)
|
||||
event = ((PlayerChangedAreaEvent) area_event).getMoveEvent();
|
||||
GameMode CURRENT_GAMEMODE = getPlayer().getGameMode();
|
||||
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event != null ? event.getTo().getWorld() : getPlayer().getWorld());
|
||||
|
||||
if (region_gamemode != null && CURRENT_GAMEMODE != region_gamemode && !this.isActiveRegionGameMode(region_gamemode)) {
|
||||
Core.debug(getName()+": entering creative area");
|
||||
// 1. the region allows "the other (temporary) gamemode"
|
||||
// 2. but the player is not in that mode
|
||||
// 3. and the player is not aware of that
|
||||
// result: change him to that mode
|
||||
|
||||
boolean isOptional = isOptionalRegionGameMode(area_event.getRegionHash(), CURRENT_GAMEMODE);
|
||||
|
||||
if (isOptional || checkSwitchFlight(area_event)) {
|
||||
storeActiveRegionGameMode(region_gamemode); // have to be set, before setGameMode
|
||||
|
||||
if (!isOptional) {
|
||||
getPlayer().setGameMode(region_gamemode);
|
||||
}
|
||||
}
|
||||
} else if (region_gamemode == null && getPlayer().getGameMode() != DEFAULT_GAMEMODE && !isInPermanentGameMode(CURRENT_GAMEMODE) && getActiveRegionGameMode() != null) {
|
||||
Core.debug(getName()+": leaving creative area");
|
||||
// 1. the region doesn't allow "the other gamemode"
|
||||
// 2. but the player is in that mode
|
||||
// 3. and the player isn't global (permanent) in that mode
|
||||
// 4. and the player isn't temporary in that mode (that means its maybe a world teleport, and the mode changes afterwards)
|
||||
// result: change him back to default mode
|
||||
if (checkSwitchFlight(area_event)) {
|
||||
storeActiveRegionGameMode(null);
|
||||
getPlayer().setGameMode(DEFAULT_GAMEMODE);
|
||||
}
|
||||
} else if (region_gamemode == null && this.isActiveRegionGameMode()) {
|
||||
Core.debug(getName()+": leaving creative area (while already in default gamemode)");
|
||||
// 1. the region doesn't allow "the other gamemode"
|
||||
// 2. but he thinks he is still allowed
|
||||
// 3. (because of else) we are not longer in that mode
|
||||
// result: advise him to not longer allowed to that region
|
||||
storeActiveRegionGameMode(null);
|
||||
}
|
||||
/** At the moment, in permanent game mode, it ignores all regions
|
||||
else if (this.isRegionGameMode()) {
|
||||
Core.debug(getName()+": entering creative area (while already in region gamemode)");
|
||||
// 1. the region allow "the other gamemode"
|
||||
// 2. (inherit) the player is already in that mode
|
||||
GameMode rgm = getOptionalRegionGameMode(area_event.getRegionHash());
|
||||
if (rgm != null && rgm != CURRENT_GAMEMODE) {
|
||||
Core.debug(getName()+": switching to optional remembered gamemode");
|
||||
// 3. but he remembered optional want the other gamemode in that region
|
||||
// * this inherits, that the option is allowed
|
||||
// result: change to the optional remembered game mode
|
||||
getPlayer().setGameMode(rgm);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private Map<String, Long> timeout_msgs = new HashMap<String, Long>();
|
||||
public void sendTimeoutMessage(String msg) {
|
||||
Iterator<Map.Entry<String, Long>> i = timeout_msgs.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
Map.Entry<String, Long> entry = i.next();
|
||||
if (entry.getValue() < (System.currentTimeMillis() - plugin.config.getRepeatingMessageTimeout())) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
if (!timeout_msgs.containsKey(msg)) {
|
||||
timeout_msgs.put(msg, System.currentTimeMillis());
|
||||
getPlayer().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public int getFloatingHeight() {
|
||||
return getFloatingHeight(getPlayer().getLocation());
|
||||
}
|
||||
public int getFloatingHeight(Location loc) {
|
||||
Block b = loc.getBlock();
|
||||
int steps = 0;
|
||||
while (b.getType() == Material.AIR) {
|
||||
steps++;
|
||||
b = b.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
public void goToFloor() {
|
||||
Block b = getPlayer().getLocation().getBlock();
|
||||
int steps = 0;
|
||||
while (b.getType() == Material.AIR) {
|
||||
steps++;
|
||||
b = b.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
if (steps > 2) {
|
||||
getPlayer().teleport(new Location(getPlayer().getWorld(),
|
||||
getPlayer().getLocation().getX(),
|
||||
b.getY()+1,
|
||||
getPlayer().getLocation().getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(IPermission permission) {
|
||||
return de.jaschastarke.bukkit.lib.permissions.PermissionManager.hasPermission(getPlayer(), permission);
|
||||
}
|
||||
|
||||
public boolean isGameModeAllowed(GameMode gm) {
|
||||
if (plugin.config.getRegionOptional() && isActiveRegionGameMode(gm)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.i18n;
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
|
||||
public class LimitedCreative extends Core {
|
||||
private i18n lang;
|
||||
@Override
|
||||
public void OnInitialize() {
|
||||
lang = new i18n("lang/messages");
|
||||
addModule(new ModInventories(this));
|
||||
addModule(new ModCreativeLimits(this));
|
||||
addModule(new ModRegions(this));
|
||||
addModule(new ModCmdBlocker(this));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String L(String msg, Object... objects) {
|
||||
return lang.trans(msg, objects);
|
||||
}
|
||||
public i18n getLocale() {
|
||||
return lang;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
|
||||
public class ModCmdBlocker extends CoreModule {
|
||||
|
||||
public ModCmdBlocker(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
public class ModCreativeLimits extends CoreModule {
|
||||
public ModCreativeLimits(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
protected FeatureBlockItemSpawn blockDrops = null;
|
||||
|
||||
@Override
|
||||
public void Initialize(ModuleEntry<IModule> entry) {
|
||||
super.Initialize(entry);
|
||||
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
||||
if (blockDrops == null)
|
||||
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.PlayerListener;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
public class ModInventories extends CoreModule {
|
||||
public ModInventories(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Initialize(ModuleEntry<IModule> entry) {
|
||||
super.Initialize(entry);
|
||||
listeners.registerEvents(new PlayerListener(this));
|
||||
}
|
||||
|
||||
public void onSetGameMode(Player player, GameMode gm) {
|
||||
//if (hasPermission(Perms.KEEPINVENTORY))
|
||||
// return true;
|
||||
player.closeInventory();
|
||||
|
||||
|
||||
/*
|
||||
GameMode cgm = player.getGameMode();
|
||||
if (gm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
||||
gm = GameMode.SURVIVAL;
|
||||
if (cgm == GameMode.ADVENTURE && !plugin.config.getAdventureInv())
|
||||
cgm = GameMode.SURVIVAL;
|
||||
|
||||
if (gm != cgm) {
|
||||
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative()) {
|
||||
getInv().save(cgm);
|
||||
}
|
||||
if (gm == GameMode.CREATIVE) {
|
||||
if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) {
|
||||
getInv().load(GameMode.CREATIVE);
|
||||
} else {
|
||||
getInv().clear();
|
||||
}
|
||||
setCreativeArmor();
|
||||
} else if (gm == GameMode.SURVIVAL) {
|
||||
if (getInv().isStored(GameMode.SURVIVAL))
|
||||
getInv().load(GameMode.SURVIVAL);
|
||||
} else if (gm == GameMode.ADVENTURE) {
|
||||
if (getInv().isStored(GameMode.ADVENTURE))
|
||||
getInv().load(GameMode.ADVENTURE);
|
||||
else
|
||||
getInv().clear();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
|
||||
public class ModRegions extends CoreModule {
|
||||
|
||||
public ModRegions(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.Singleton;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer;
|
||||
|
||||
@ArchiveDocComments
|
||||
public class Permissions extends SimplePermissionContainer implements Singleton {
|
||||
private static Permissions instance = new Permissions();
|
||||
public static Permissions getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows changing plugin configuration ingame via commands
|
||||
*/
|
||||
public static final IPermission CONFIG = new BasicPermission(instance, "config", PermissionDefault.OP);
|
||||
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return "limitedcreative";
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.minecraft.lib.annotations.PermissionDescripted;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
|
||||
@PermissionDescripted(PermissionDescripted.Type.STATIC_ATTRIBUTES)
|
||||
@ArchiveDocComments
|
||||
public enum Perms implements IPermission {
|
||||
|
||||
/**
|
||||
* Test123
|
||||
*/
|
||||
CONFIG("config", PermissionDefault.OP),
|
||||
|
||||
/**
|
||||
* Test456
|
||||
*/
|
||||
REGIONS("regions", PermissionDefault.OP),
|
||||
REGIONS_BYPASS("regions_bypass", PermissionDefault.FALSE),
|
||||
GM("switch_gamemode", PermissionDefault.OP),
|
||||
GM_BACKONLY("switch_gamemode.backonly", PermissionDefault.FALSE),
|
||||
GM_SURVIVAL("switch_gamemode.survival", PermissionDefault.FALSE),
|
||||
GM_CREATIVE("switch_gamemode.creative", PermissionDefault.FALSE),
|
||||
GM_ADVENTURE("switch_gamemode.adventure", PermissionDefault.FALSE),
|
||||
GM_OTHER("switch_gamemode.other", PermissionDefault.OP),
|
||||
KEEPINVENTORY("keepinventory", PermissionDefault.FALSE);
|
||||
|
||||
public static final IPermissionContainer Root = new IPermissionContainer() {
|
||||
@Override
|
||||
public IPermission[] getPermissions() {
|
||||
return Perms.values();
|
||||
}
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return "limitedcreative";
|
||||
}
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
private String perm;
|
||||
private PermissionDefault def;
|
||||
private Perms(String permission, PermissionDefault pdefault) {
|
||||
perm = permission;
|
||||
def = pdefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return Root;
|
||||
}
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return getParent().getFullString() + SEP + perm;
|
||||
}
|
||||
@Override
|
||||
public PermissionDefault getDefault() {
|
||||
return def;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.store.PlayerOptions;
|
||||
|
||||
public class Players {
|
||||
public static final long CLEANUP_TIMEOUT = 300000; // 300s = 5m
|
||||
private static Map<String, LCPlayer> players = new HashMap<String, LCPlayer>();
|
||||
private static PlayerOptions options = new PlayerOptions();
|
||||
|
||||
public static LCPlayer get(Player player) {
|
||||
Core.debug("player: " + player.getName() + " - " + ((Object)player).hashCode() + " - " + player.getEntityId() + " - " + player.getUniqueId());
|
||||
if (!players.containsKey(player.getName())) {
|
||||
LCPlayer p = new LCPlayer(player);
|
||||
players.put(player.getName(), p);
|
||||
return p;
|
||||
} else {
|
||||
LCPlayer p = players.get(player.getName());
|
||||
if (player != p.getPlayer())
|
||||
p.updatePlayer(player);
|
||||
//p.touch();
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public static LCPlayer get(String player) {
|
||||
if (players.containsKey(player)) {
|
||||
return players.get(player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void remove(String player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
/*public static void clear(String player) {
|
||||
if (players.containsKey(player)) {
|
||||
LCPlayer p = players.get(player);
|
||||
p.updatePlayer(null);
|
||||
p.touch(); // keep meta data alive till cleanup, but remove player bukkit assoc.
|
||||
}
|
||||
}*/
|
||||
|
||||
/*public static void cleanUp() {
|
||||
int count = players.size();
|
||||
Iterator<Map.Entry<String, LCPlayer>> i = players.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
Map.Entry<String, LCPlayer> entry = i.next();
|
||||
if (entry.getValue().isOutdated()) {
|
||||
Core.debug("removing "+entry.getValue().getName());
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
Core.debug("cleanup done: player count: "+count+" / "+players.size());
|
||||
}*/
|
||||
|
||||
public static PlayerOptions getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.cmdblock;
|
||||
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Perms;
|
||||
|
||||
public enum CmdBlockPerms implements IPermission {
|
||||
ALL("all", PermissionDefault.FALSE),;
|
||||
|
||||
public static final IPermissionContainer Parent = new IPermissionContainer() {
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return Perms.Root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPermission[] getPermissions() {
|
||||
return CmdBlockPerms.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return "cmdblock";
|
||||
}
|
||||
};
|
||||
|
||||
private String perm;
|
||||
private PermissionDefault def;
|
||||
private CmdBlockPerms(String permission, PermissionDefault pdefault) {
|
||||
perm = permission;
|
||||
def = pdefault;
|
||||
}
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return Parent;
|
||||
}
|
||||
@Override
|
||||
public PermissionDefault getDefault() {
|
||||
return def;
|
||||
}
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return getParent().getFullString() + SEP + perm;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.cmdblock;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
|
||||
public class CommandBlocker {
|
||||
private Core plugin;
|
||||
public CommandBlocker(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new Listener(), plugin);
|
||||
}
|
||||
|
||||
|
||||
class Listener implements org.bukkit.event.Listener {
|
||||
@EventHandler
|
||||
public void onPreCommand(PlayerCommandPreprocessEvent event) {
|
||||
String cmd = event.getMessage();
|
||||
if (cmd.startsWith("/")) { // just to be sure ;)
|
||||
cmd = cmd.substring(1);
|
||||
for (ICmdBlockEntry blockentry : plugin.config.getCommandBlockList()) {
|
||||
if (blockentry.test(cmd)) {
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!player.hasPermission(CmdBlockPerms.ALL)) {
|
||||
Core.debug("CmdBlock: "+event.getPlayer().getName()+": '/"+cmd+"' blocked by rule '"+blockentry.toString()+"'");
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("cmdblock.blocked"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.cmdblock;
|
||||
|
||||
public interface ICmdBlockEntry {
|
||||
public boolean test(String cmd);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.cmdblock;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexpBlockEntry implements ICmdBlockEntry {
|
||||
private Pattern rx;
|
||||
public RegexpBlockEntry(String regex) {
|
||||
rx = Pattern.compile(regex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(String cmd) {
|
||||
return rx.matcher(cmd).matches();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return rx.pattern();
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.cmdblock;
|
||||
|
||||
public class StringBlockEntry implements ICmdBlockEntry {
|
||||
private String str;
|
||||
public StringBlockEntry(String cmd) {
|
||||
str = cmd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(String cmd) {
|
||||
return cmd.startsWith(this.str);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return str;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.org.whoami.authme.cache.auth.PlayerCache;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
|
||||
public class AuthMeHooks {
|
||||
public AuthMeHooks(final LimitedCreative plugin) {
|
||||
Hooks.IsLoggedIn.register(new PlayerCheckHooker.Check() {
|
||||
@Override
|
||||
public boolean test(Player player) {
|
||||
boolean li = PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase());
|
||||
if (plugin.isDebug()) // not nessesary, but so no string concation without debug needed
|
||||
plugin.getLog().debug("AuthMe: "+player.getName()+": logged in: "+li);
|
||||
return li;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
import de.jaschastarke.hooking.BooleanHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
|
||||
public class MultiVerseHooks {
|
||||
public MultiVerseHooks(final LimitedCreative plugin) {
|
||||
Hooks.IsMultiVerse.register(new BooleanHooker.Check() {
|
||||
@Override
|
||||
public boolean test() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Hooks.DefaultWorldGameMode.register(new WorldTypeHooker.Check() {
|
||||
@Override
|
||||
public GameMode test(World world) {
|
||||
MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world);
|
||||
if (mvWorld == null)
|
||||
return null;
|
||||
GameMode gm = mvWorld.getGameMode();
|
||||
plugin.getLog().debug("Multiverse: "+world.getName()+": game mode: "+gm);
|
||||
return gm;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static MultiverseCore getMV() {
|
||||
return (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.hooking.AbstractHooker;
|
||||
|
||||
public class PlayerCheckHooker extends AbstractHooker<PlayerCheckHooker.Check> {
|
||||
public interface Check {
|
||||
boolean test(Player player);
|
||||
}
|
||||
|
||||
protected boolean def;
|
||||
public PlayerCheckHooker(boolean defaultValue) {
|
||||
def = defaultValue;
|
||||
}
|
||||
public boolean test(Player player) {
|
||||
for (Check c : hooks) {
|
||||
boolean ret = c.test(player);
|
||||
if (ret != def)
|
||||
return ret;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
|
||||
import de.jaschastarke.hooking.AbstractHooker;
|
||||
|
||||
public class WorldTypeHooker extends AbstractHooker<WorldTypeHooker.Check> {
|
||||
public interface Check {
|
||||
GameMode test(World world);
|
||||
}
|
||||
|
||||
public GameMode test(World world) {
|
||||
for (Check c : hooks) {
|
||||
return c.test(world);
|
||||
}
|
||||
return Bukkit.getServer().getDefaultGameMode();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
|
||||
public class xAuthHooks {
|
||||
public xAuthHooks(final LimitedCreative plugin) {
|
||||
Hooks.IsLoggedIn.register(new PlayerCheckHooker.Check() {
|
||||
@Override
|
||||
public boolean test(Player player) {
|
||||
xAuthPlayer xpl = getAuth().getPlayerManager().getPlayer(player);
|
||||
boolean li = true;
|
||||
if (!xpl.isAuthenticated())
|
||||
li = false;
|
||||
else if (xpl.isGuest())
|
||||
li = false;
|
||||
plugin.getLog().debug("xAuth: "+player.getName()+": logged in not guest: "+li);
|
||||
return li;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static xAuth getAuth() {
|
||||
return (xAuth) Bukkit.getServer().getPluginManager().getPlugin("xAuth");
|
||||
}
|
||||
}
|
|
@ -15,27 +15,21 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
/**
|
||||
* This Namespace may be used as a Standalone-Plugin just providing the WorldGuard-API
|
||||
* TODO: Not done yet
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Permissions;
|
||||
|
||||
@ArchiveDocComments
|
||||
public class InventoryPermissions extends SimplePermissionContainer {
|
||||
|
||||
/**
|
||||
* Allows bypassing the inventory separation
|
||||
*/
|
||||
@Deprecated // NOT READY YET
|
||||
public class API extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
throw new IllegalArgumentException("Not yet supported");
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.getInstance(), "keepinventory", PermissionDefault.FALSE);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private ModInventories mod;
|
||||
public PlayerListener(ModInventories mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
|
||||
* entity with e.g. a bucket)
|
||||
* @param event
|
||||
* @return The relevant "isCancelled"
|
||||
*/
|
||||
public static boolean isCancelled(PlayerInteractEvent event) {
|
||||
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
boolean isLoggedIn = Hooks.IsLoggedIn.test(event.getPlayer());
|
||||
if (mod.isDebug()) {
|
||||
mod.getLog().debug("onPlayerGameModeChange: "+event.getPlayer().getName());
|
||||
mod.getLog().debug("Current GameMode: "+event.getPlayer().getGameMode());
|
||||
mod.getLog().debug("New GameMode: "+event.getNewGameMode());
|
||||
mod.getLog().debug("isLoggedin: "+isLoggedIn);
|
||||
mod.getLog().debug("isCancelled: "+event.isCancelled());
|
||||
}
|
||||
if (!isLoggedIn)
|
||||
return;
|
||||
|
||||
mod.onSetGameMode(event.getPlayer(), event.getNewGameMode());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogout(PlayerQuitEvent event) {
|
||||
if (event.getPlayer() != null) {
|
||||
//mod.getInventories().remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,251 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.StorageMinecart;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.Button;
|
||||
import org.bukkit.material.Lever;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.BlackList;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
|
||||
|
||||
public class LimitListener implements Listener {
|
||||
private Core plugin;
|
||||
public LimitListener(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
Players.get(event.getPlayer()).onDropItem(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
Players.get(event.getPlayer()).onPickupItem(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!player.hasPermission(NoLimitPerms.USE)) {
|
||||
if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST) { // Workaround, Bukkit not recognize a Enderchest
|
||||
player.onChestAccess(event);
|
||||
} else if (block.getState() instanceof Sign) {
|
||||
player.onSignAccess(event);
|
||||
} else if (block.getState() instanceof Lever || block.getState() instanceof Button) {
|
||||
player.onButtonAccess(event);
|
||||
} else if (block.getType() == Material.WORKBENCH) {
|
||||
player.onBenchAccess(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!player.hasPermission(NoLimitPerms.USE)) {
|
||||
if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
// Temporary Solution: While dropping of Items is prevented we don't allow Interaction with ItemFrames, so no
|
||||
// Items can be "placed" anywhere.
|
||||
if (!player.hasPermission(NoLimitPerms.DROP)) {
|
||||
if (entity instanceof ItemFrame && plugin.config.getRemoveDrop()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.use"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof StorageMinecart) {
|
||||
player.onChestAccess(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent)
|
||||
onEntityDamageByEntity((EntityDamageByEntityEvent) event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Registering to that event works, but causes a SEVERE:
|
||||
* Plugin attempted to register delegated event class class org.bukkit.event.entity.EntityDamageByEntityEvent.
|
||||
* It should be using class org.bukkit.event.entity.EntityDamageEvent!
|
||||
*/
|
||||
protected void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
Entity source = event.getDamager();
|
||||
if (source instanceof Projectile)
|
||||
source = ((Projectile) source).getShooter();
|
||||
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Players.get((Player) event.getEntity()).onDamage(source, event);
|
||||
}
|
||||
if (!event.isCancelled() && source instanceof Player) {
|
||||
Players.get((Player) source).onDealDamage(event);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getTarget() instanceof Player) {
|
||||
Players.get((Player) event.getTarget()).onTarget(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
Players.get(player).onDie(event);
|
||||
}
|
||||
}
|
||||
/*@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Players.get(event.getPlayer()).onRespawn(event);
|
||||
}*/
|
||||
|
||||
|
||||
private void whenBlockBreak(Cancellable event, Block block, Player eventPlayer) {
|
||||
if (eventPlayer.getGameMode() == GameMode.CREATIVE) {
|
||||
LCPlayer player = Players.get(eventPlayer);
|
||||
if (!player.hasPermission(NoLimitPerms.BREAK)) {
|
||||
if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), block)) {
|
||||
event.setCancelled(true);
|
||||
eventPlayer.sendMessage(L("blocked.break"));
|
||||
}
|
||||
}
|
||||
|
||||
if (player.hasPermission(NoLimitPerms.DROP))
|
||||
return;
|
||||
// Prevent dropping of doors and beds when destroying the wrong part
|
||||
|
||||
// TODO: Fix, Remove, or make it god like, but this little thing is crap ;)
|
||||
Material mat = block.getType();
|
||||
switch (block.getType()) {
|
||||
case WOODEN_DOOR:
|
||||
mat = Material.WOOD_DOOR;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
|
||||
break;
|
||||
case IRON_DOOR_BLOCK:
|
||||
mat = Material.IRON_DOOR;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.DOWN).getLocation(), mat);
|
||||
break;
|
||||
case BED_BLOCK:
|
||||
mat = Material.BED;
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.NORTH).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.EAST).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.SOUTH).getLocation(), mat);
|
||||
plugin.spawnblock.block(block.getRelative(BlockFace.WEST).getLocation(), mat);
|
||||
break;
|
||||
default:
|
||||
plugin.spawnblock.block(block.getLocation(), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Doesn't make sense yet, as the block always will be Air. whenBlockBreak should be changed to use Material
|
||||
* instead. Maybe in the Feature.
|
||||
@EventHandler
|
||||
public void onHangingBreak(HangingBreakByEntityEvent event) {
|
||||
if (event.getRemover() instanceof Player) {
|
||||
Player eventPlayer = (Player) event.getRemover();
|
||||
whenBlockBreak(event, event.getEntity().getLocation().getBlock(), eventPlayer);
|
||||
}
|
||||
}*/
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
whenBlockBreak(event, event.getBlock(), event.getPlayer());
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
if (!player.hasPermission(NoLimitPerms.USE)) {
|
||||
if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(L("blocked.place"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Perms;
|
||||
|
||||
@ArchiveDocComments
|
||||
public enum NoLimitPerms implements IPermission {
|
||||
DROP("drop", PermissionDefault.FALSE),
|
||||
PICKUP("pickup", PermissionDefault.FALSE),
|
||||
CHEST("chest", PermissionDefault.FALSE),
|
||||
SIGN("sign", PermissionDefault.FALSE),
|
||||
BUTTON("button", PermissionDefault.FALSE),
|
||||
LEVER("lever", PermissionDefault.FALSE),
|
||||
PVP("pvp", PermissionDefault.FALSE),
|
||||
MOB_DAMAGE("mob_damage", PermissionDefault.FALSE),
|
||||
USE("use", PermissionDefault.FALSE),
|
||||
BREAK("break", PermissionDefault.FALSE);
|
||||
|
||||
public static final IPermissionContainer Parent = new IPermissionContainer() {
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return Perms.Root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPermission[] getPermissions() {
|
||||
return NoLimitPerms.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return "nolimit";
|
||||
}
|
||||
};
|
||||
|
||||
private String perm;
|
||||
private PermissionDefault def;
|
||||
private NoLimitPerms(String permission, PermissionDefault pdefault) {
|
||||
perm = permission;
|
||||
def = pdefault;
|
||||
}
|
||||
@Override
|
||||
public IAbstractPermission getParent() {
|
||||
return Parent;
|
||||
}
|
||||
@Override
|
||||
public PermissionDefault getDefault() {
|
||||
return def;
|
||||
}
|
||||
@Override
|
||||
public String getFullString() {
|
||||
return getParent().getFullString() + SEP + perm;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.listeners;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
|
||||
public class MainListener implements Listener {
|
||||
private Core plugin;
|
||||
public MainListener(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
|
||||
* entity with e.g. a bucket)
|
||||
* @param event
|
||||
* @return The relevant "isCancelled"
|
||||
*/
|
||||
public static boolean isCancelled(PlayerInteractEvent event) {
|
||||
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (Core.isDebug()) {
|
||||
Core.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
|
||||
Core.debug("Current GameMode: "+event.getPlayer().getGameMode());
|
||||
Core.debug("New GameMode: "+event.getNewGameMode());
|
||||
Core.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
|
||||
Core.debug("isCancelled: "+event.isCancelled());
|
||||
}
|
||||
if (!plugin.com.isLoggedIn(event.getPlayer()))
|
||||
return;
|
||||
|
||||
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Players.get(event.getPlayer()).onRevive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Also needed if WorldGuard-Feature is enabled, so can not moved to optional Listener "Limit".
|
||||
*/
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onLogout(PlayerQuitEvent event) {
|
||||
// what? i can't cancel a logout event? but how to chain the user to the server than? xD
|
||||
Players.remove(event.getPlayer().getName());
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
|
||||
public final class Flags {
|
||||
public static final StateFlag SPAWNDROPS = new StateFlag("spawndrops", true);
|
||||
public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode", RegionGroup.MEMBERS);
|
||||
|
||||
public static List<Flag<?>> getList() {
|
||||
return Arrays.asList(new Flag<?>[]{
|
||||
SPAWNDROPS,
|
||||
GAMEMODE,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
|
||||
/**
|
||||
* Well, that was an interesting idea, but it doesn't work.
|
||||
*/
|
||||
public class GameModeFlag extends Flag<GameMode> {
|
||||
public GameModeFlag(String name, RegionGroup defaultGroup) {
|
||||
super(name, defaultGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode parseInput(WorldGuardPlugin plugin, CommandSender sender, String input) throws InvalidFlagFormat {
|
||||
input = input.trim();
|
||||
if (input.equalsIgnoreCase("creative")) {
|
||||
return GameMode.CREATIVE;
|
||||
} else if (input.equalsIgnoreCase("survival")) {
|
||||
return GameMode.SURVIVAL;
|
||||
} else if (input.equalsIgnoreCase("adventure")) {
|
||||
return GameMode.ADVENTURE;
|
||||
} else if (input.equalsIgnoreCase("none")) {
|
||||
return null;
|
||||
} else {
|
||||
throw new InvalidFlagFormat("Expected survival/creative/none but got '" + input + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode unmarshal(Object o) {
|
||||
GameMode gm = null;
|
||||
if (o != null) {
|
||||
gm = GameMode.valueOf((String) o);
|
||||
}
|
||||
return gm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(GameMode o) {
|
||||
return o == null ? null : o.name();
|
||||
}
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Utils;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.CRegionManager;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerUpdateAreaEvent;
|
||||
|
||||
public class RegionListener implements Listener {
|
||||
private static Core plugin = WorldGuardIntegration.plugin;
|
||||
private CRegionManager rm;
|
||||
public RegionListener(WorldGuardIntegration wgi) {
|
||||
rm = wgi.getRegionManager();
|
||||
}
|
||||
|
||||
private ApplicableRegions regionSet(Location loc) {
|
||||
return rm.getRegionSet(loc);
|
||||
}
|
||||
private ApplicableRegions regionSet(Block block) {
|
||||
return rm.getRegionSet(block);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
whenBlockBreak(event, event.getBlock(), event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHangingBreak(HangingBreakByEntityEvent event) {
|
||||
if (event.getRemover() instanceof Player) {
|
||||
Player eventPlayer = (Player) event.getRemover();
|
||||
whenBlockBreak(event, event.getEntity().getLocation().getBlock(), eventPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private void whenBlockBreak(Cancellable event, Block block, Player eventPlayer) {
|
||||
LCPlayer player = Players.get(eventPlayer);
|
||||
boolean diffrent_region = rm.isDiffrentRegion(eventPlayer, block.getLocation());
|
||||
|
||||
if (player.isActiveRegionGameMode() && diffrent_region) {
|
||||
// do not break outside of "gamemod-change-region" when in the region
|
||||
if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE, eventPlayer) != player.getActiveRegionGameMode()) {
|
||||
eventPlayer.sendMessage(L("blocked.outside_break"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not break inside of "survial-region in creative world" when outside
|
||||
if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE) != null) {
|
||||
eventPlayer.sendMessage(L("blocked.inside_break"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
// prevent any drops for survival players in creative regions
|
||||
if (eventPlayer.getGameMode() != GameMode.CREATIVE && rm.getRegionSet(block).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
plugin.spawnblock.block(block, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
LCPlayer player = Players.get(event.getPlayer());
|
||||
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
|
||||
|
||||
if (player.isActiveRegionGameMode() && diffrent_region) {
|
||||
// do not build outside of "gamemod-change-region" when in the region
|
||||
if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != player.getActiveRegionGameMode()) {
|
||||
event.getPlayer().sendMessage(L("blocked.outside_place"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not build inside of "survial-region in creative world" when outside
|
||||
if (rm.getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null) {
|
||||
event.getPlayer().sendMessage(L("blocked.inside_place"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedArea(PlayerNewLocationAreaEvent event) {
|
||||
Players.get(event.getPlayer()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSetArea(PlayerSetAreaEvent event) {
|
||||
Players.get(event.getPlayer()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerUpdateArea(PlayerUpdateAreaEvent event) {
|
||||
Players.get(event.getPlayer()).setRegionGameMode(event.getRegionSet().getFlag(Flags.GAMEMODE, event.getPlayer()), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
Block source = event.getBlock().getRelative(event.getDirection());
|
||||
Core.debug("PistonExtend "+source.getType()+" "+event.getDirection());
|
||||
if (source.getType() != Material.AIR) {
|
||||
if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
Block dest = source.getRelative(event.getDirection(), i);
|
||||
Core.debug("dest "+i+": "+dest.getType());
|
||||
if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) {
|
||||
plugin.getLog().warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Utils.toString(source.getLocation())));
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
} else if (dest.getType() == Material.AIR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
Block source = event.getBlock().getRelative(event.getDirection(), 2);
|
||||
Block dest = source.getRelative(event.getDirection().getOppositeFace());
|
||||
Core.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
|
||||
if (event.isSticky() && source.getType() != Material.AIR) {
|
||||
Core.debug("dest "+dest.getType());
|
||||
if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) {
|
||||
plugin.getLog().warning(L("blocked.piston", source.getType().toString(), Utils.toString(source.getLocation())));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (regionSet(dest).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
// source isn't creative
|
||||
plugin.getLog().warning(L("blocked.piston_in", source.getType().toString(), Utils.toString(source.getLocation())));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (!regionSet(event.getLocation()).allows(Flags.SPAWNDROPS))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.worldguard.CRegionManager;
|
||||
import de.jaschastarke.minecraft.worldguard.Integration;
|
||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||
|
||||
public class WorldGuardIntegration implements Integration {
|
||||
public static Core plugin;
|
||||
public static WorldGuardPlugin wg;
|
||||
|
||||
public WorldGuardIntegration(Core plugin) {
|
||||
WorldGuardIntegration.plugin = plugin;
|
||||
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
|
||||
/*
|
||||
* This should be only done by the "API"-Plugin itself (when its done). You don't need to that again if you
|
||||
* like to interact with LimitedCreative's WorldGuard-Integration
|
||||
*/
|
||||
new Interface(plugin);
|
||||
|
||||
/*
|
||||
* You only need to do this one, to make your Flags available.
|
||||
*/
|
||||
Interface.getInstance().register(this);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin);
|
||||
}
|
||||
|
||||
public CRegionManager getRegionManager() {
|
||||
return Interface.getInstance().getRegionManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flag<?>> getFlags() {
|
||||
return Flags.getList();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
Interface.unload();
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class Fallback {
|
||||
|
||||
public static void loadVersion1(PlayerInventory inv, ConfigurationSection sect) {
|
||||
new Armor(inv).restore(sect.getConfigurationSection("armor"));
|
||||
new Items(inv).restore(sect.getConfigurationSection("inv"));
|
||||
}
|
||||
|
||||
public static interface Storeable {
|
||||
public void store(ConfigurationSection section);
|
||||
public void restore(ConfigurationSection section);
|
||||
}
|
||||
|
||||
public static class Items implements Storeable {
|
||||
private PlayerInventory inv;
|
||||
public Items(PlayerInventory pi) {
|
||||
inv = pi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(ConfigurationSection section) {
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0)
|
||||
sectionSetItem(section, String.valueOf(i), inv.getItem(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(ConfigurationSection section) {
|
||||
inv.clear();
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (section.contains(String.valueOf(i)))
|
||||
inv.setItem(i, sectionGetItem(section, String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
|
||||
if (!Core.plugin.config.getUnsafeStorage()) {
|
||||
section.set(path, item);
|
||||
} else { // unsafe enchants fallback
|
||||
Map<String, Object> serialize = item.serialize();
|
||||
if (serialize.containsKey("type") && serialize.get("type") instanceof Material)
|
||||
serialize.put("type", serialize.get("type").toString());
|
||||
section.createSection(path, serialize);
|
||||
};
|
||||
}
|
||||
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
|
||||
if (section.isItemStack(path)) {
|
||||
return section.getItemStack(path);
|
||||
} else {
|
||||
ConfigurationSection s = section.getConfigurationSection(path);
|
||||
Material type = Material.getMaterial(s.getString("type"));
|
||||
short damage = new Integer(s.getInt("damage", 0)).shortValue();
|
||||
int amount = s.getInt("amaount", 1);
|
||||
|
||||
ItemStack result = new ItemStack(type, amount, damage);
|
||||
Map<String, Object> item = section.getConfigurationSection(path).getValues(false);
|
||||
item.remove("enchantments");
|
||||
if (s.contains("enchantments")) {
|
||||
for (Map.Entry<String, Object> entry : s.getConfigurationSection("enchantments").getValues(false).entrySet()) {
|
||||
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
|
||||
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
|
||||
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
|
||||
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) {
|
||||
map.put(i, inv.getItem(i));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < inv.getArmorContents().length; i++) {
|
||||
map.put((i * -1) - 1, inv.getArmorContents()[i]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
public static void restoreInventory(PlayerInventory inv, Map<Integer, ItemStack> map) {
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (map.containsKey(i)) {
|
||||
inv.setItem(i, map.get(i));
|
||||
} else {
|
||||
inv.setItem(i, null);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < inv.getArmorContents().length; i++) {
|
||||
int _i = (i * -1) - 1;
|
||||
if (map.containsKey(_i)) {
|
||||
inv.getArmorContents()[i] = map.get(_i);
|
||||
} else {
|
||||
inv.getArmorContents()[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Armor implements Storeable {
|
||||
private PlayerInventory inv;
|
||||
public Armor(PlayerInventory pi) {
|
||||
inv = pi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(ConfigurationSection section) {
|
||||
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "helmet", inv.getHelmet());
|
||||
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "chestplate", inv.getChestplate());
|
||||
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "leggins", inv.getLeggings());
|
||||
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "boots", inv.getBoots());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(ConfigurationSection section) {
|
||||
if (section.contains("helmet"))
|
||||
inv.setHelmet(Items.sectionGetItem(section, "helmet"));
|
||||
else
|
||||
inv.setHelmet(null);
|
||||
|
||||
if (section.contains("chestplate"))
|
||||
inv.setChestplate(Items.sectionGetItem(section, "chestplate"));
|
||||
else
|
||||
inv.setChestplate(null);
|
||||
|
||||
if (section.contains("leggins"))
|
||||
inv.setLeggings(Items.sectionGetItem(section, "leggins"));
|
||||
else
|
||||
inv.setLeggings(null);
|
||||
|
||||
if (section.contains("boots"))
|
||||
inv.setBoots(Items.sectionGetItem(section, "boots"));
|
||||
else
|
||||
inv.setBoots(null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory;
|
||||
|
||||
abstract public class InvConfStorage extends PlayerInventoryStorage {
|
||||
private static final int ARMOR_SIZE = 4;
|
||||
|
||||
public void store(Inventory pinv, ConfigurationSection sect) {
|
||||
PlayerInventory inv = pinv.getPlayer().getInventory();
|
||||
sect.set("version", 2);
|
||||
if (Core.plugin.config.getUnsafeStorage())
|
||||
sect.set("unsafe", true);
|
||||
storeItems(sect.createSection("armor"), inv.getArmorContents());
|
||||
storeItems(sect.createSection("inv"), inv.getContents());
|
||||
}
|
||||
|
||||
public void load(Inventory pinv, ConfigurationSection sect) {
|
||||
PlayerInventory inv = pinv.getPlayer().getInventory();
|
||||
|
||||
if (!sect.contains("version")) {
|
||||
Fallback.loadVersion1(inv, sect);
|
||||
} else {
|
||||
inv.setArmorContents(restoreItems(sect.getConfigurationSection("armor"), ARMOR_SIZE));
|
||||
inv.setContents(restoreItems(sect.getConfigurationSection("inv"), inv.getSize()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void storeItems(ConfigurationSection sect, ItemStack[] items) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
ItemStack is = items[i];
|
||||
if (is != null && is.getType() != Material.AIR) {
|
||||
sect.set(String.valueOf(i), serialize(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
protected ItemStack[] restoreItems(ConfigurationSection sect, int size) {
|
||||
ItemStack[] items = new ItemStack[size];
|
||||
if (sect != null) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (sect.contains(String.valueOf(i))) {
|
||||
if (sect.isItemStack(String.valueOf(i))) {
|
||||
items[i] = sect.getItemStack(String.valueOf(i));
|
||||
} else {
|
||||
items[i] = deserializeItemStack(sect.get(String.valueOf(i)));
|
||||
}
|
||||
} else {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
protected Object serialize(ItemStack is) {
|
||||
if (Core.plugin.config.getUnsafeStorage())
|
||||
return is.serialize();
|
||||
return is;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ItemStack deserializeItemStack(Object is) {
|
||||
if (is instanceof ConfigurationSection) {
|
||||
ConfigurationSection sect = (ConfigurationSection) is;
|
||||
Material type = Material.getMaterial(sect.getString("type"));
|
||||
short damage = new Integer(sect.getInt("damage", 0)).shortValue();
|
||||
int amount = sect.getInt("amount", 1);
|
||||
|
||||
ItemStack result = new ItemStack(type, amount, damage);
|
||||
if (sect.contains("enchantments")) {
|
||||
for (Map.Entry<String, Object> entry : sect.getConfigurationSection("enchantments").getValues(false).entrySet()) {
|
||||
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
|
||||
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
|
||||
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else if (is instanceof Map) {
|
||||
return ItemStack.deserialize((Map<String, Object>) is);
|
||||
} else {
|
||||
Core.plugin.warn("Failed to restore Item: "+is.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
|
||||
|
||||
public class InvMemStorage extends InvConfStorage {
|
||||
private MemoryConfiguration storage = new MemoryConfiguration();
|
||||
|
||||
@Override
|
||||
public void store(Inventory pinv, Target target) {
|
||||
store(pinv, storage.createSection(pinv.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Inventory pinv, Target target) {
|
||||
load(pinv, storage.getConfigurationSection(pinv.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Inventory pinv, Target target) {
|
||||
storage.set(pinv.getPlayer().getName(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Inventory pinv, Target target) {
|
||||
return storage.contains(pinv.getPlayer().getName());
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
|
||||
|
||||
public class InvYamlStorage extends InvConfStorage {
|
||||
private static final String SUFFIX = ".yml";
|
||||
|
||||
private File dir;
|
||||
public InvYamlStorage(File file) {
|
||||
dir = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Inventory pinv, Target target) {
|
||||
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Inventory pinv, Target target) {
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
yml.options().header("DO NOT MODIFY THIS FILE");
|
||||
store(pinv, yml);
|
||||
try {
|
||||
yml.save(getFile(pinv, target));
|
||||
} catch (IOException e) {
|
||||
Core.plugin.warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Inventory pinv, Target target) {
|
||||
getFile(pinv, target).delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Inventory pinv, Target target) {
|
||||
return getFile(pinv, target).exists();
|
||||
}
|
||||
|
||||
protected File getFile(Inventory pinv, Target target) {
|
||||
if (target != default_target) {
|
||||
return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX);
|
||||
} else {
|
||||
return new File(dir, pinv.getPlayer().getName() + SUFFIX);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
|
||||
|
||||
public abstract class PlayerInventoryStorage {
|
||||
protected Target default_target = Target.SURVIVAL;
|
||||
final public void store(Inventory pinv) {
|
||||
store(pinv, default_target);
|
||||
}
|
||||
final public void load(Inventory pinv) {
|
||||
load(pinv, default_target);
|
||||
}
|
||||
final public void remove(Inventory pinv) {
|
||||
remove(pinv, default_target);
|
||||
}
|
||||
final public boolean contains(Inventory pinv) {
|
||||
return contains(pinv, default_target);
|
||||
}
|
||||
abstract public void store(Inventory pinv, Target target);
|
||||
abstract public void load(Inventory pinv, Target target);
|
||||
abstract public void remove(Inventory pinv, Target target);
|
||||
abstract public boolean contains(Inventory pinv, Target target);
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.store;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
|
||||
public class PlayerOptions {
|
||||
private File _store_file = new File(Core.plugin.getDataFolder(), "players.yml");
|
||||
private YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
|
||||
|
||||
{
|
||||
store.options().header("DO NOT MODIFY THIS FILE");
|
||||
}
|
||||
|
||||
public void setRegionGameMode(String player, GameMode gm) {
|
||||
if (gm == null) {
|
||||
store.set(player + ".region_gamemode", null);
|
||||
cleanUp(player);
|
||||
} else {
|
||||
store.set(player + ".region_gamemode", gm.name());
|
||||
}
|
||||
save();
|
||||
}
|
||||
public GameMode getRegionGameMode(String player) {
|
||||
if (store.contains(player + ".region_gamemode")) {
|
||||
return GameMode.valueOf(store.getString(player + ".region_gamemode"));
|
||||
} else if (store.contains(player + ".region_creative")) { // compatibility fallback
|
||||
return store.getBoolean(player + ".region_creative") ? GameMode.CREATIVE : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameMode getOptionalRegionGameMode(String player, String region) {
|
||||
if (store.contains(player+".region")) {
|
||||
ConfigurationSection sect = store.getConfigurationSection(player+".region");
|
||||
if (sect.contains(region)) {
|
||||
return GameMode.valueOf(sect.getString(region));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void setOptionalRegionGameMode(String player, String region, GameMode gm) {
|
||||
ConfigurationSection sect = store.contains(player+".region") ? store.getConfigurationSection(player+".region") : store.createSection(player+".region");
|
||||
String mode = gm == null ? null : gm.name();
|
||||
sect.set(region, mode);
|
||||
if (sect.getKeys(true).size() == 0) {
|
||||
store.set(sect.getCurrentPath(), null);
|
||||
cleanUp(player);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
protected void cleanUp(String player) {
|
||||
if (store.contains(player) && store.getConfigurationSection(player).getValues(true).size() == 0) {
|
||||
store.set(player, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void save() {
|
||||
try {
|
||||
store.save(_store_file);
|
||||
} catch (IOException e) {
|
||||
Core.plugin.getLog().severe("Failed to save players.yml");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.utils;
|
||||
|
||||
public interface IPermission {
|
||||
public static final String SEP = ".";
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.utils;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.minecraft.worldedit.PermissionsBridge;
|
||||
|
||||
public class Permissions {
|
||||
protected JavaPlugin plugin = null;
|
||||
protected PermissionsBridge pif = null;
|
||||
|
||||
public Permissions(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
if (Core.plugin.config.getWEPIFEnabled()) {
|
||||
// because worldedit may be not loaded as plugin, just as library, we check that way
|
||||
Class.forName("com.sk89q.wepif.PermissionsResolverManager", false, plugin.getClass().getClassLoader());
|
||||
pif = new PermissionsBridge(plugin);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {}
|
||||
}
|
||||
|
||||
public boolean hasPermission(Player player, String permission) {
|
||||
boolean ret = false;
|
||||
if (pif != null) {
|
||||
ret = pif.hasPermission(player, permission);
|
||||
} else {
|
||||
// bukkit permission fallback
|
||||
ret = player.hasPermission(permission);
|
||||
}
|
||||
debug(player, permission, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender player, IPermission permission) {
|
||||
return hasPermission(player, permission.toString());
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender, String permission) {
|
||||
if (sender instanceof Player) {
|
||||
return hasPermission((Player) sender, permission);
|
||||
} else {
|
||||
debug(sender, permission, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void debug(CommandSender player, String permission, boolean result) {
|
||||
if (plugin instanceof Core && ((Core) plugin).config.getDebug())
|
||||
Core.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldedit;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.wepif.PermissionsResolverManager;
|
||||
|
||||
public class PermissionsBridge {
|
||||
protected com.sk89q.wepif.PermissionsResolverManager pif;
|
||||
public PermissionsBridge(JavaPlugin plugin) {
|
||||
PermissionsResolverManager.initialize(plugin);
|
||||
pif = PermissionsResolverManager.getInstance();
|
||||
}
|
||||
public boolean hasPermission(OfflinePlayer sender, String permission) {
|
||||
return pif.hasPermission(sender, permission);
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||
|
||||
public class ApplicableRegions {
|
||||
private ApplicableRegionSet regions;
|
||||
private CRegionManager.CWorld mgr;
|
||||
|
||||
public ApplicableRegions(ApplicableRegionSet regions, CRegionManager.CWorld rm) {
|
||||
this.regions = regions;
|
||||
this.mgr = rm;
|
||||
}
|
||||
|
||||
|
||||
public boolean allows(StateFlag flag) {
|
||||
extendRegionFlags();
|
||||
boolean r = regions.allows(flag);
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean allows(StateFlag flag, Player player) {
|
||||
extendRegionFlags();
|
||||
boolean r = regions.allows(flag, WorldGuardIntegration.wg.wrapPlayer(player));
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T extends Flag<V>, V> V getFlag(T flag) {
|
||||
extendRegionFlags();
|
||||
V r = regions.getFlag(flag);
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T extends Flag<V>, V> V getFlag(T flag, Player player) {
|
||||
extendRegionFlags();
|
||||
V r = regions.getFlag(flag, WorldGuardIntegration.wg.wrapPlayer(player));
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Flag<V>, V> void extendRegionFlags() {
|
||||
for (ProtectedRegion pr : regions) {
|
||||
for (FlagValue data : mgr.region(pr).getFlags()) {
|
||||
T flag = (T) data.getFlag();
|
||||
V value = (V) data.getValue();
|
||||
pr.setFlag(flag, value);
|
||||
}
|
||||
}
|
||||
if (mgr.getGlobalRegion() != null) {
|
||||
for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) {
|
||||
T flag = (T) data.getFlag();
|
||||
V value = (V) data.getValue();
|
||||
mgr.getGlobalRegion().setFlag(flag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Flag<V>, V> void contractRegionFlags() {
|
||||
for (ProtectedRegion pr : regions) {
|
||||
for (FlagValue data : mgr.region(pr).getFlags()) {
|
||||
T flag = (T) data.getFlag();
|
||||
pr.setFlag(flag, null);
|
||||
}
|
||||
}
|
||||
if (mgr.getGlobalRegion() != null) {
|
||||
for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) {
|
||||
T flag = (T) data.getFlag();
|
||||
mgr.getGlobalRegion().setFlag(flag, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import static de.jaschastarke.minecraft.limitedcreative.Core.L;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import de.jaschastarke.utils.StringUtil;
|
||||
|
||||
public class CCommand implements CommandExecutor {
|
||||
public enum Action {
|
||||
FLAG,
|
||||
INFO
|
||||
}
|
||||
|
||||
private CRegionManager rm;
|
||||
private JavaPlugin plugin;
|
||||
private WorldGuardPlugin wg;
|
||||
|
||||
public CCommand(JavaPlugin plugin, CRegionManager mgr, WorldGuardPlugin wg) {
|
||||
this.plugin = plugin;
|
||||
this.rm = mgr;
|
||||
this.wg = wg;
|
||||
}
|
||||
public CCommand(JavaPlugin plugin, CRegionManager mgr) {
|
||||
this.plugin = plugin;
|
||||
this.rm = mgr;
|
||||
this.wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
if (!wg.hasPermission(sender, "limitedcreative.regions")) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("exception.command.lackingpermission"));
|
||||
return true;
|
||||
}
|
||||
Player player = sender instanceof Player ? (Player) sender : null;
|
||||
World world = null;
|
||||
Action act;
|
||||
String rid;
|
||||
try {
|
||||
act = Action.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
String[] wr = args[1].split("#");
|
||||
if (wr.length == 2) {
|
||||
world = plugin.getServer().getWorld(wr[0]);
|
||||
rid = wr[1];
|
||||
} else {
|
||||
rid = args[1];
|
||||
if (player != null) {
|
||||
world = player.getWorld();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.world_not_found"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RegionManager mgr = wg.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(rid);
|
||||
if (region == null) {
|
||||
if (rid.equalsIgnoreCase("__global__")) {
|
||||
region = new GlobalProtectedRegion(rid);
|
||||
mgr.addRegion(region);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.region_not_found"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
CRegion reg = rm.world(world).region(region);
|
||||
|
||||
try {
|
||||
switch (act) {
|
||||
case INFO:
|
||||
onInfo(sender, player, reg);
|
||||
return true;
|
||||
case FLAG:
|
||||
onFlag(sender, player, reg, args);
|
||||
return true;
|
||||
}
|
||||
} catch (CommandException ex) { // worldedit command exception!
|
||||
sender.sendMessage(ChatColor.DARK_RED + ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onInfo(CommandSender sender, Player player, CRegion region) throws CommandPermissionsException {
|
||||
/* not optimal yet
|
||||
if (player != null) {
|
||||
if (region.getProtectedRegion().isOwner(wg.wrapPlayer(player))) {
|
||||
hasPermission(sender, Perms.INFO_OWN);
|
||||
} else if (region.getProtectedRegion().isMember(wg.wrapPlayer(player))) {
|
||||
hasPermission(sender, Perms.INFO_MEMBER);
|
||||
} else {
|
||||
hasPermission(sender, Perms.INFO);
|
||||
}
|
||||
} else {
|
||||
hasPermission(sender, Perms.INFO);
|
||||
}*/
|
||||
|
||||
/*
|
||||
* WorldEdits intercepting Servers privates commandMap via Reflections realy sucks!
|
||||
* Just because they are to lazy to add all the lines commands to plugin.yml
|
||||
*/
|
||||
Bukkit.getServer().dispatchCommand(sender, "region info "+region.getWorld().getName()+ " "+region.getProtectedRegion().getId());
|
||||
|
||||
StringBuilder list = new StringBuilder();
|
||||
for (FlagValue data : region.getFlags()) {
|
||||
if (list.length() > 0)
|
||||
list.append(", ");
|
||||
list.append(data.getFlag().getName());
|
||||
list.append(": ");
|
||||
list.append(data.getValue().toString());
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + L("command.worldguard.additional_flags") + ": " + list.toString());
|
||||
}
|
||||
private void onFlag(CommandSender sender, Player player, CRegion region, String[] args) {
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.no_flag_given"));
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.available_flags") + ": " + FlagList.getStringListAvailableFlags(sender));
|
||||
return;
|
||||
}
|
||||
String flagName = args[2];
|
||||
String value = null;
|
||||
|
||||
Flag<?> flag = FlagList.getFlag(flagName);
|
||||
|
||||
if (args.length > 3 && args[3].equalsIgnoreCase("-g")) {
|
||||
flag = flag.getRegionGroupFlag();
|
||||
if (args.length > 4)
|
||||
value = StringUtil.join(args, 4);
|
||||
} else {
|
||||
if (args.length > 3)
|
||||
value = StringUtil.join(args, 3);
|
||||
}
|
||||
|
||||
if (flag == null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.unknown_flag") + ": " + flagName);
|
||||
sender.sendMessage(ChatColor.DARK_RED + L("command.worldguard.available_flags") + ": " + FlagList.getStringListAvailableFlags(sender));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (value != null) {
|
||||
region.setFlag(flag, flag.parseInput(wg, sender, value));
|
||||
} else {
|
||||
region.setFlag(flag, null);
|
||||
}
|
||||
} catch (InvalidFlagFormat e) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
CPlayer.updateAll();
|
||||
sender.sendMessage(L("command.worldguard.flag_set", flag.getName()));
|
||||
}
|
||||
|
||||
/*private boolean hasPermission(CommandSender sender, IPermission permission) throws CommandPermissionsException {
|
||||
wg.checkPermission(sender, permission.toString());
|
||||
return true;
|
||||
}*/
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent;
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerSetAreaEvent;
|
||||
|
||||
public class CListener implements Listener {
|
||||
private Interface com;
|
||||
public CListener(Interface com) {
|
||||
this.com = com;
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST) // run very late, because the event may be cancelled
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|
||||
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
||||
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()
|
||||
|| !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // he really moved, and not just looked around
|
||||
|
||||
String current_hash = CPlayer.get(event.getPlayer()).getHash();
|
||||
if (current_hash == null) {
|
||||
String new_hash = com.getRegionManager().getRegionsHash(event.getTo());
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerSetAreaEvent(event.getPlayer(), new_hash, event.getTo()));
|
||||
CPlayer.get(event.getPlayer()).setHash(new_hash);
|
||||
} else if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) {
|
||||
String new_hash = com.getRegionManager().getRegionsHash(event.getTo());
|
||||
PlayerChangedAreaEvent areaevent = new PlayerChangedAreaEvent(event, current_hash, new_hash);
|
||||
Bukkit.getServer().getPluginManager().callEvent(areaevent);
|
||||
if (!areaevent.isCancelled())
|
||||
CPlayer.get(event.getPlayer()).setHash(new_hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST) // run very late, because the event may be cancelled
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
onPlayerMove(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
String new_hash = com.getRegionManager().getRegionsHash(event.getRespawnLocation());
|
||||
PlayerNewLocationAreaEvent areaevent = new PlayerNewLocationAreaEvent(event.getPlayer(), event.getRespawnLocation(), new_hash);
|
||||
Bukkit.getServer().getPluginManager().callEvent(areaevent);
|
||||
CPlayer.get(event.getPlayer()).setHash(new_hash);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerJoinEvent event) {
|
||||
String new_hash = com.getRegionManager().getRegionsHash(event.getPlayer().getLocation());
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerSetAreaEvent(event.getPlayer(), new_hash));
|
||||
CPlayer.get(event.getPlayer()).setHash(new_hash);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogout(PlayerQuitEvent event) {
|
||||
CPlayer.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerComamnd(PlayerCommandPreprocessEvent event) {
|
||||
String[] cmd = event.getMessage().split(" ");
|
||||
if (cmd.length >= 2) {
|
||||
if (cmd[0].replaceAll("/", "").equalsIgnoreCase("region")) {
|
||||
if (cmd[1].equalsIgnoreCase("addowner") || cmd[1].equalsIgnoreCase("addmember") ||
|
||||
cmd[1].equalsIgnoreCase("removeowner") || cmd[1].equalsIgnoreCase("remowner") ||
|
||||
cmd[1].equalsIgnoreCase("removemember") || cmd[1].equalsIgnoreCase("remmember") ||
|
||||
cmd[1].equalsIgnoreCase("removemem") || cmd[1].equalsIgnoreCase("remmem")) {
|
||||
CPlayer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.events.PlayerUpdateAreaEvent;
|
||||
|
||||
public class CPlayer {
|
||||
private static Map<String, CPlayer> players = new HashMap<String, CPlayer>();
|
||||
|
||||
public static CPlayer get(Player p) {
|
||||
if (!players.containsKey(p.getName())) {
|
||||
CPlayer pl = new CPlayer();
|
||||
players.put(p.getName(), pl);
|
||||
return pl;
|
||||
} else {
|
||||
return players.get(p.getName());
|
||||
}
|
||||
}
|
||||
public static void remove(Player p) {
|
||||
players.remove(p.getName());
|
||||
}
|
||||
|
||||
private String hash = null;
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
public static void clear() {
|
||||
players.clear();
|
||||
}
|
||||
|
||||
public static void updateAll() {
|
||||
for (Map.Entry<String, CPlayer> entry : players.entrySet()) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerUpdateAreaEvent(entry.getKey(), entry.getValue().getHash()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.CRegionManager.CWorld;
|
||||
|
||||
public class CRegion {
|
||||
private ProtectedRegion region;
|
||||
private CWorld mgr;
|
||||
private List<FlagValue> flags = null;
|
||||
|
||||
protected CRegion(CWorld w, ProtectedRegion reg) {
|
||||
mgr = w;
|
||||
region = reg;
|
||||
}
|
||||
|
||||
public void removeFlag(Flag<?> flag) {
|
||||
if (flags != null) {
|
||||
Iterator<FlagValue> i = flags.iterator();
|
||||
while (i.hasNext()) {
|
||||
if (i.next().getFlag() == flag)
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
mgr.storeFlag(this, flag, null);
|
||||
}
|
||||
|
||||
public void setFlag(Flag<?> flag, Object value) {
|
||||
if (value == null) {
|
||||
removeFlag(flag);
|
||||
} else {
|
||||
if (flags != null)
|
||||
flags.add(new FlagValue(flag, value));
|
||||
mgr.storeFlag(this, flag, value);
|
||||
}
|
||||
}
|
||||
public ProtectedRegion getProtectedRegion() {
|
||||
return region;
|
||||
}
|
||||
public World getWorld() {
|
||||
return mgr.getWorld();
|
||||
}
|
||||
public List<FlagValue> getFlags() {
|
||||
if (flags == null) {
|
||||
flags = mgr.getFlags(this);
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||
import de.jaschastarke.utils.StringUtil;
|
||||
|
||||
public class CRegionManager {
|
||||
protected YamlConfiguration c;
|
||||
protected File file;
|
||||
private Map<World, CWorld> worlds = new HashMap<World, CWorld>();
|
||||
public CRegionManager(File f) {
|
||||
file = f;
|
||||
c = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
|
||||
public CWorld world(World w) {
|
||||
if (worlds.containsKey(w)) {
|
||||
return worlds.get(w);
|
||||
} else {
|
||||
CWorld r = new CWorld(w);
|
||||
worlds.put(w, r);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
public class CWorld {
|
||||
private World world;
|
||||
private ConfigurationSection wc = null;
|
||||
public CWorld(World w) {
|
||||
world = w;
|
||||
}
|
||||
public CRegionManager getManager() {
|
||||
return CRegionManager.this;
|
||||
}
|
||||
private Map<ProtectedRegion, CRegion> regions = new HashMap<ProtectedRegion, CRegion>();
|
||||
public CRegion region(ProtectedRegion pr) {
|
||||
if (regions.containsKey(pr)) {
|
||||
return regions.get(pr);
|
||||
} else {
|
||||
CRegion r = new CRegion(this, pr);
|
||||
regions.put(pr, r);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
public ProtectedRegion getGlobalRegion() {
|
||||
return getWGManager(world).getRegion("__global__");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> void storeFlag(CRegion region, Flag<V> flag, Object value) {
|
||||
if (wc == null) {
|
||||
if (c.contains(world.getName().toLowerCase()))
|
||||
wc = c.getConfigurationSection(world.getName().toLowerCase());
|
||||
else
|
||||
wc = c.createSection(world.getName().toLowerCase());
|
||||
}
|
||||
|
||||
ConfigurationSection rs;
|
||||
if (wc.contains(region.getProtectedRegion().getId()))
|
||||
rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
|
||||
else
|
||||
rs = wc.createSection(region.getProtectedRegion().getId());
|
||||
|
||||
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
|
||||
|
||||
fs.set(flag.getName(), flag.marshal((V) value));
|
||||
|
||||
try {
|
||||
c.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public List<FlagValue> getFlags(CRegion region) {
|
||||
List<FlagValue> list = new ArrayList<FlagValue>();
|
||||
|
||||
if (c.contains(world.getName().toLowerCase())) {
|
||||
ConfigurationSection wc = c.getConfigurationSection(world.getName().toLowerCase());
|
||||
if (wc.contains(region.getProtectedRegion().getId())) {
|
||||
ConfigurationSection rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
|
||||
if (rs.contains("flags")) {
|
||||
ConfigurationSection fs = rs.getConfigurationSection("flags");
|
||||
for (Map.Entry<String, Object> data : fs.getValues(false).entrySet()) {
|
||||
Flag<?> flag = null;
|
||||
if (data.getKey().endsWith("-group")) {
|
||||
flag = FlagList.getFlag(data.getKey().substring(0, data.getKey().length() - 6));
|
||||
if (flag != null)
|
||||
flag = flag.getRegionGroupFlag();
|
||||
} else {
|
||||
flag = FlagList.getFlag(data.getKey());
|
||||
}
|
||||
if (flag != null) { // the flag doesn't exists anymore. just ignore it without error
|
||||
Object value = flag.unmarshal(data.getValue());
|
||||
list.add(new FlagValue(flag, value));
|
||||
} else {
|
||||
Core.debug("Couldn't load unknown Flag: "+data.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalRegionManager getWGGlobalManager() {
|
||||
return Interface.getInstance().getWorldGuard().getGlobalRegionManager();
|
||||
}
|
||||
public RegionManager getWGManager(World world) {
|
||||
return Interface.getInstance().getWorldGuard().getRegionManager(world);
|
||||
}
|
||||
|
||||
public String getRegionsHash(Location loc) {
|
||||
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
|
||||
List<String> idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc));
|
||||
if (idlist.size() > 0) {
|
||||
hash.append("#");
|
||||
String[] ids = idlist.toArray(new String[idlist.size()]);
|
||||
if (ids.length > 1) {
|
||||
Arrays.sort(ids);
|
||||
}
|
||||
hash.append(StringUtil.join(ids, ","));
|
||||
}
|
||||
return hash.toString();
|
||||
}
|
||||
|
||||
public ApplicableRegions getRegionSet(Location loc) {
|
||||
return new ApplicableRegions(getWGManager(loc.getWorld()).getApplicableRegions(loc), this.world(loc.getWorld()));
|
||||
}
|
||||
|
||||
public ApplicableRegions getRegionSet(Block block) {
|
||||
return getRegionSet(block.getLocation());
|
||||
}
|
||||
|
||||
public boolean isDiffrentRegion(Player player, Location loc) {
|
||||
return !getRegionsHash(loc).equals(CPlayer.get(player).getHash());
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
public class FlagList {
|
||||
protected static List<Flag<?>> list = new ArrayList<Flag<?>>();
|
||||
|
||||
public static List<Flag<?>> getFlags() {
|
||||
return list;
|
||||
}
|
||||
public static void addFlag(Flag<?> flag) {
|
||||
list.add(flag);
|
||||
}
|
||||
public static void addFlags(Collection<Flag<?>> flags) {
|
||||
list.addAll(flags);
|
||||
}
|
||||
public static Flag<?> getFlag(String flag) {
|
||||
for (Flag <?> f : list) {
|
||||
if (f.getName().replace("-", "").equalsIgnoreCase(flag.replace("-", ""))) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static List<Flag<?>> getAvailableFlags(CommandSender sender) {
|
||||
List<Flag<?>> result = new ArrayList<Flag<?>>();
|
||||
for (Flag <?> f : list) {
|
||||
if (!(f instanceof IRestrictedFlag) || ((IRestrictedFlag) f).isAllowed(sender)) {
|
||||
result.add(f);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String getStringListAvailableFlags(CommandSender sender) {
|
||||
String result = "";
|
||||
for (Flag <?> f : getAvailableFlags(sender)) {
|
||||
if (result.length() > 0)
|
||||
result += ", ";
|
||||
result += f.getName();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
public class FlagValue {
|
||||
private Flag<?> flag;
|
||||
private Object value;
|
||||
public FlagValue(Flag<?> flag, Object value) {
|
||||
this.flag = flag;
|
||||
this.value = value;
|
||||
}
|
||||
public Flag<?> getFlag() {
|
||||
return flag;
|
||||
}
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface IRestrictedFlag {
|
||||
public boolean isAllowed(CommandSender sender);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
public interface Integration {
|
||||
public List<Flag<?>> getFlags();
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
public class Interface {
|
||||
//private JavaPlugin plugin;
|
||||
private CRegionManager mgr;
|
||||
private WorldGuardPlugin wg;
|
||||
private static Interface _instance = null;
|
||||
|
||||
public Interface(JavaPlugin plugin) {
|
||||
if (_instance != null)
|
||||
throw new RuntimeException("The Interface is Singleton!");
|
||||
//this.plugin = plugin;
|
||||
_instance = this;
|
||||
|
||||
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
|
||||
|
||||
mgr = new CRegionManager(new File(plugin.getDataFolder(), "regions.yml"));
|
||||
plugin.getCommand("/region").setExecutor(new CCommand(plugin, mgr, wg));
|
||||
plugin.getServer().getPluginManager().registerEvents(new CListener(this), plugin);
|
||||
}
|
||||
public static Interface getInstance() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void register(Integration integration) {
|
||||
FlagList.addFlags(integration.getFlags());
|
||||
}
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
return wg;
|
||||
}
|
||||
public CRegionManager getRegionManager() {
|
||||
return mgr;
|
||||
}
|
||||
public static void unload() {
|
||||
_instance = null;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard;
|
||||
|
||||
import de.jaschastarke.minecraft.utils.IPermission;
|
||||
|
||||
@Deprecated // NOT USED YET
|
||||
public enum Perms implements IPermission {
|
||||
INFO("info"),
|
||||
INFO_OWN("info.own"),
|
||||
INFO_MEMBER("info.member");
|
||||
|
||||
private static final String NS = "worldguard.region";
|
||||
|
||||
private String perm;
|
||||
private Perms(String permission) {
|
||||
perm = permission;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return NS + SEP + perm;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
|
||||
public abstract class PlayerAreaEvent extends Event {
|
||||
abstract public String getRegionHash();
|
||||
abstract public ApplicableRegions getRegionSet();
|
||||
abstract public Player getPlayer();
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"["+getRegionHash()+"]";
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||
|
||||
public class PlayerChangedAreaEvent extends PlayerNewLocationAreaEvent implements Cancellable {
|
||||
private PlayerMoveEvent event;
|
||||
private String _previous_hash;
|
||||
private boolean _cancelled = false;
|
||||
|
||||
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) {
|
||||
super(moveevent.getPlayer(), moveevent.getTo());
|
||||
event = moveevent;
|
||||
}
|
||||
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent, String previous_hash, String new_hash) {
|
||||
super(moveevent.getPlayer(), moveevent.getTo(), new_hash);
|
||||
event = moveevent;
|
||||
_previous_hash = previous_hash;
|
||||
}
|
||||
|
||||
public boolean isTeleport() {
|
||||
return event instanceof PlayerTeleportEvent;
|
||||
}
|
||||
|
||||
public ApplicableRegions getPreviousRegionSet() {
|
||||
return Interface.getInstance().getRegionManager().getRegionSet(event.getFrom());
|
||||
}
|
||||
|
||||
public String getPreviousRegionHash() {
|
||||
if (_previous_hash == null)
|
||||
_previous_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getFrom());
|
||||
return _previous_hash;
|
||||
}
|
||||
|
||||
public PlayerMoveEvent getMoveEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"["+getPreviousRegionHash()+" -> "+getRegionHash()+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return _cancelled;
|
||||
}
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
_cancelled = b;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||
|
||||
public class PlayerNewLocationAreaEvent extends PlayerAreaEvent {
|
||||
private Location location;
|
||||
private Player player;
|
||||
private String _hash;
|
||||
|
||||
public PlayerNewLocationAreaEvent(Player player, Location new_location) {
|
||||
this.player = player;
|
||||
location = new_location;
|
||||
}
|
||||
public PlayerNewLocationAreaEvent(Player player, Location new_location, String new_hash) {
|
||||
this(player, new_location);
|
||||
_hash = new_hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegionHash() {
|
||||
if (_hash == null)
|
||||
_hash = Interface.getInstance().getRegionManager().getRegionsHash(location);
|
||||
return _hash;
|
||||
}
|
||||
@Override
|
||||
public ApplicableRegions getRegionSet() {
|
||||
return Interface.getInstance().getRegionManager().getRegionSet(location);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"["+getRegionHash()+"]";
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||
|
||||
public class PlayerSetAreaEvent extends PlayerAreaEvent {
|
||||
private Player player;
|
||||
private String hash;
|
||||
private Location loc;
|
||||
|
||||
public PlayerSetAreaEvent(Player player, String hash) {
|
||||
this.player = player;
|
||||
this.hash = hash;
|
||||
}
|
||||
public PlayerSetAreaEvent(Player player, String hash, Location location) {
|
||||
this.player = player;
|
||||
this.hash = hash;
|
||||
this.loc = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegionHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicableRegions getRegionSet() {
|
||||
return Interface.getInstance().getRegionManager().getRegionSet(loc != null ? loc : player.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2012 jascha@ja-s.de
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.worldguard.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||
|
||||
public class PlayerUpdateAreaEvent extends PlayerAreaEvent {
|
||||
private String player;
|
||||
private String hash;
|
||||
|
||||
public PlayerUpdateAreaEvent(String player, String hash) {
|
||||
this.player = player;
|
||||
this.hash = hash;
|
||||
}
|
||||
@Override
|
||||
public String getRegionHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicableRegions getRegionSet() {
|
||||
return Interface.getInstance().getRegionManager().getRegionSet(getPlayer().getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getServer().getPlayerExact(player);
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue