v0.6:
- invalid enchants allowed (by config) - optional switch to survival in creative regions - fixed initial config create (ticket #6) - added teleport listener (ticket 3) - misc bugfixes/improvements
This commit is contained in:
parent
2c9e4b80a3
commit
85602d4922
11 changed files with 280 additions and 75 deletions
37
config.yml
37
config.yml
|
@ -17,6 +17,14 @@ store:
|
||||||
# default: true
|
# default: true
|
||||||
creative: true
|
creative: true
|
||||||
|
|
||||||
|
# UnsafeStore (for storing invalid enchants)
|
||||||
|
# By default the new and upgrade-safe storage method for items is used. This method doesn't allow the use
|
||||||
|
# of "invalid" enchants, like given by different plugins. Enable it, to allow invalid enchants (not recommended).
|
||||||
|
# This option can only changed by reloading the plugin (not via ingame commands).
|
||||||
|
# default: false
|
||||||
|
unsafe: false
|
||||||
|
|
||||||
|
|
||||||
# InventoryFolder
|
# InventoryFolder
|
||||||
# The folder inside the datadir-folder (plugin/LimitedCreative) where the inventories are saved to.
|
# The folder inside the datadir-folder (plugin/LimitedCreative) where the inventories are saved to.
|
||||||
# By default the inventories are saved to "plugin/LimitedCreative/inventories".
|
# By default the inventories are saved to "plugin/LimitedCreative/inventories".
|
||||||
|
@ -42,6 +50,25 @@ limit:
|
||||||
# default: true
|
# default: true
|
||||||
sign: true
|
sign: true
|
||||||
|
|
||||||
|
# UseBlackList
|
||||||
|
# Prevents using or placing of the given blocks in creative mode (and only in creative).
|
||||||
|
# You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
|
||||||
|
# or the id of the block/item (better use the id, if you're not sure).
|
||||||
|
# To prevent Lava you need to add "LAVA_BUCKET", because lava-blocks aren't "placed", therefore Lava-Buckets are
|
||||||
|
# "used".
|
||||||
|
# This option can only changed by reloading the plugin (not via ingame commands).
|
||||||
|
# default: []
|
||||||
|
use: []
|
||||||
|
|
||||||
|
# BreakBlackList
|
||||||
|
# Prevents destroying of the given blocks in creative mode (and only in creative).
|
||||||
|
# You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
|
||||||
|
# or the id of the block/item (better use the id, if you're not sure).
|
||||||
|
# This option can only changed by reloading the plugin (not via ingame commands).
|
||||||
|
# default: [bedrock]
|
||||||
|
break:
|
||||||
|
- bedrock
|
||||||
|
|
||||||
region:
|
region:
|
||||||
# RegionsEnabled
|
# RegionsEnabled
|
||||||
# Enables the Feature for "creative-regions". This Feature is automatically disabled, if the required plugin
|
# Enables the Feature for "creative-regions". This Feature is automatically disabled, if the required plugin
|
||||||
|
@ -50,12 +77,18 @@ region:
|
||||||
# default: true
|
# default: true
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
# RegionOptional
|
||||||
|
# Allows Players to use /lc creative|survival to switch between GameModes in creative-regions, even if they
|
||||||
|
# have no global permission to those commands
|
||||||
|
# default: true
|
||||||
|
optional: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
# PermissionsEnabled
|
# PermissionsEnabled
|
||||||
# When enabled, the Permissions will allow selected users to ignore limitations like PvP, Chest-Block, etc.
|
# When enabled, the Permissions will allow selected users to ignore limitations like PvP, Chest-Block, etc.
|
||||||
# When not enabled, all users are treated equally.
|
# When not enabled, all users are treated equally.
|
||||||
# Note: The Permission needed for commands, are not affected by this option. So you still need the defined
|
# Note: Not all Permission, are affected by this option. So you still need the defined permissions or op, to use
|
||||||
# permissions or op, to use commands, even if this options is disabled!
|
# commands, even if this options is disabled!
|
||||||
# default: false
|
# default: false
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ command:
|
||||||
overview: storecreative|blockpickup|blocksign|permissions|perm_keepinventory
|
overview: storecreative|blockpickup|blocksign|permissions|perm_keepinventory
|
||||||
gamemode:
|
gamemode:
|
||||||
changed: "{0}'s game mode has been changed"
|
changed: "{0}'s game mode has been changed"
|
||||||
|
no_change: Already in that game mode.
|
||||||
option:
|
option:
|
||||||
done: Option changed.
|
done: Option changed.
|
||||||
worldguard:
|
worldguard:
|
||||||
|
@ -28,8 +29,14 @@ exception:
|
||||||
invalidoption: Unknown option
|
invalidoption: Unknown option
|
||||||
config:
|
config:
|
||||||
savefail: Failed to write modified configuration to disk
|
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:
|
||||||
|
no_survival: You can not be survival in an creative area
|
||||||
blocked:
|
blocked:
|
||||||
chest: Access to chests is not allowed in creative mode
|
chest: Access to chests is not allowed in creative mode
|
||||||
sign: To interact with signs is not allowed in creative mode
|
sign: To interact with signs is not allowed in creative mode
|
||||||
survival_flying: You should stay on ground, when leaving a creative-area
|
survival_flying: You should stay on ground, when leaving a creative-area
|
||||||
outside_creative: You can not place blocks outside of the creative-area
|
outside_creative: You can not place blocks outside of the creative-area
|
||||||
|
outside_creative_break: You can not destroy blocks outside of the creative-area
|
|
@ -1,7 +1,8 @@
|
||||||
name: LimitedCreative
|
name: LimitedCreative
|
||||||
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
||||||
version: 0.5.1-alpha
|
version: 0.6-beta
|
||||||
softdepend: [WorldGuard]
|
softdepend: [WorldGuard]
|
||||||
|
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
||||||
commands:
|
commands:
|
||||||
limitedcreative:
|
limitedcreative:
|
||||||
description: Main LimitedCreative-Controlling-Commands
|
description: Main LimitedCreative-Controlling-Commands
|
||||||
|
@ -45,3 +46,9 @@ permissions:
|
||||||
limitedcreative.nolimit.pvp:
|
limitedcreative.nolimit.pvp:
|
||||||
description: Allows bypassing the "no pvp"-limitation
|
description: Allows bypassing the "no pvp"-limitation
|
||||||
default: false
|
default: false
|
||||||
|
limitedcreative.nolimit.use:
|
||||||
|
description: Allows bypassing the "block place/item use"-limitation
|
||||||
|
default: false
|
||||||
|
limitedcreative.nolimit.break:
|
||||||
|
description: Allows bypassing the "block break"-limitation
|
||||||
|
default: false
|
|
@ -81,20 +81,18 @@ public class Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
String c = label;
|
String c = label;
|
||||||
String message = "";
|
StringBuilder message = new StringBuilder();
|
||||||
if (sender.hasPermission("limitedcreative.switch_gamemode") || sender.hasPermission("limitedcreative.switch_gamemode.backonly"))
|
message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n");
|
||||||
message += "/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n";
|
message.append("/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n");
|
||||||
if (sender.hasPermission("limitedcreative.switch_gamemode"))
|
|
||||||
message += "/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n";
|
|
||||||
if (sender.hasPermission("limitedcreative.config"))
|
if (sender.hasPermission("limitedcreative.config"))
|
||||||
message += "/"+c+" e[nable] "+L("command.config.overview")+"\n";
|
message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n");
|
||||||
if (sender.hasPermission("limitedcreative.config"))
|
if (sender.hasPermission("limitedcreative.config"))
|
||||||
message += "/"+c+" d[isable] "+L("command.config.overview")+"\n";
|
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
|
||||||
if (sender.hasPermission("limitedcreative.config"))
|
if (sender.hasPermission("limitedcreative.regions"))
|
||||||
message += "/"+c+" r[egion] "+L("command.worldguard.alias")+"\n";
|
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
|
||||||
if (message.length() > 0) {
|
if (message.length() > 0) {
|
||||||
sender.sendMessage("Usage:");
|
sender.sendMessage("Usage:");
|
||||||
for (String m : message.split("\n")) {
|
for (String m : message.toString().split("\n")) {
|
||||||
sender.sendMessage(m);
|
sender.sendMessage(m);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -156,24 +154,21 @@ public class Commands {
|
||||||
else if (sender instanceof Player)
|
else if (sender instanceof Player)
|
||||||
target = (Player) sender;
|
target = (Player) sender;
|
||||||
|
|
||||||
if (sender instanceof Player && !sender.isOp()) {
|
|
||||||
if (!sender.hasPermission("limitedcreative.switch_gamemode")) {
|
|
||||||
if (gm != GameMode.SURVIVAL || !sender.hasPermission("limitedcreative.switch_gamemode.backonly")) {
|
|
||||||
throw new LackingPermissionException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) {
|
|
||||||
throw new LackingPermissionException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
throw new InvalidCommandException("exception.command.playernotfound");
|
throw new InvalidCommandException("exception.command.playernotfound");
|
||||||
}
|
} else if (sender instanceof Player && sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) {
|
||||||
if (target.getGameMode() != gm) {
|
throw new LackingPermissionException();
|
||||||
target.setGameMode(gm);
|
} else if (target.getGameMode() != gm) {
|
||||||
if (target != sender) {
|
if (sender == target) {
|
||||||
sender.sendMessage(L("commands.gamemode.changed", target.getName()));
|
LCPlayer.get(target).changeGameMode(gm);
|
||||||
|
} else {
|
||||||
|
target.setGameMode(gm);
|
||||||
}
|
}
|
||||||
|
if (target != sender) {
|
||||||
|
sender.sendMessage(L("command.gamemode.changed", target.getName()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(L("command.gamemode.no_change"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,14 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import static de.jaschastarke.minecraft.utils.Util.copyFile;
|
import static de.jaschastarke.minecraft.utils.Util.copyFile;
|
||||||
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
private FileConfiguration c;
|
private FileConfiguration c;
|
||||||
|
@ -52,6 +56,9 @@ public class Configuration {
|
||||||
public boolean getStoreCreative() {
|
public boolean getStoreCreative() {
|
||||||
return c.getBoolean("store.creative", true);
|
return c.getBoolean("store.creative", true);
|
||||||
}
|
}
|
||||||
|
public boolean getUnsafeStorage() {
|
||||||
|
return c.getBoolean("store.unsafe", false);
|
||||||
|
}
|
||||||
public String getInventoryFolder() {
|
public String getInventoryFolder() {
|
||||||
return c.getString("store.folder", "inventories");
|
return c.getString("store.folder", "inventories");
|
||||||
}
|
}
|
||||||
|
@ -67,6 +74,9 @@ public class Configuration {
|
||||||
public boolean getPermissionToKeepInventory() {
|
public boolean getPermissionToKeepInventory() {
|
||||||
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false);
|
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false);
|
||||||
}
|
}
|
||||||
|
public boolean getRegionOptional() {
|
||||||
|
return c.getBoolean("region.optional", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStoreCreative(boolean value) {
|
public void setStoreCreative(boolean value) {
|
||||||
|
@ -96,17 +106,49 @@ public class Configuration {
|
||||||
c.set("permissions.keepinventory", value);
|
c.set("permissions.keepinventory", value);
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reload() {
|
protected void reload() {
|
||||||
|
_block_break = null;
|
||||||
|
_block_use = null;
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
c = plugin.getConfig();
|
c = plugin.getConfig();
|
||||||
}
|
}
|
||||||
protected void save() {
|
protected void save() {
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
/*try {
|
|
||||||
c.save(file);
|
|
||||||
} catch (IOException e) {
|
|
||||||
plugin.logger.severe(L("exception.config.savefail"));
|
|
||||||
e.printStackTrace();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Material> _block_break = null;
|
||||||
|
private List<Material> _block_use = null;
|
||||||
|
|
||||||
|
public List<Material> getBlockedBreaks() {
|
||||||
|
if (_block_break == null)
|
||||||
|
_block_break = parseMaterialList(c.getStringList("limit.break"));
|
||||||
|
return _block_break;
|
||||||
|
}
|
||||||
|
public List<Material> getBlockedUse() {
|
||||||
|
if (_block_use == null)
|
||||||
|
_block_use = parseMaterialList(c.getStringList("limit.use"));
|
||||||
|
return _block_use;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Material> parseMaterialList(List<String> s) {
|
||||||
|
List<Material> list = new ArrayList<Material>();
|
||||||
|
if (s != null) {
|
||||||
|
for (String m : s) {
|
||||||
|
Material e = null;
|
||||||
|
try {
|
||||||
|
e = Material.getMaterial(Integer.parseInt(m));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
e = Material.matchMaterial(m);
|
||||||
|
}
|
||||||
|
if (e == null) {
|
||||||
|
plugin.logger.warning("["+plugin.getDescription().getName()+"] "+L("exception.config.material_not_found", m));
|
||||||
|
} else {
|
||||||
|
list.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package de.jaschastarke.minecraft.limitedcreative;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -28,6 +29,7 @@ import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Armor;
|
import de.jaschastarke.minecraft.limitedcreative.serialize.Armor;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
||||||
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class Inventory {
|
public class Inventory {
|
||||||
protected Player player;
|
protected Player player;
|
||||||
|
@ -45,7 +47,15 @@ public class Inventory {
|
||||||
|
|
||||||
public void load(GameMode gm) {
|
public void load(GameMode gm) {
|
||||||
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
|
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
|
||||||
restoreInventory(inv, f);
|
try {
|
||||||
|
restoreInventory(inv, f);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void load() {
|
public void load() {
|
||||||
load(player.getGameMode());
|
load(player.getGameMode());
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -41,6 +42,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
||||||
|
|
||||||
public class LCPlayer {
|
public class LCPlayer {
|
||||||
|
@ -52,14 +54,14 @@ public class LCPlayer {
|
||||||
private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
|
private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
|
||||||
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
|
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
|
||||||
|
|
||||||
private boolean isPermanentCreative = false;
|
private boolean _isPermanentCreative = false;
|
||||||
private boolean _isRegionCreative = false;
|
private boolean _isRegionCreative = false;
|
||||||
|
|
||||||
private LCPlayer(Player pplayer) {
|
private LCPlayer(Player pplayer) {
|
||||||
player = pplayer;
|
player = pplayer;
|
||||||
_isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE;
|
_isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE;
|
||||||
if (player.getGameMode() == GameMode.CREATIVE && !this.getRegionCreative())
|
if (player.getGameMode() == GameMode.CREATIVE && !this.isRegionCreative())
|
||||||
isPermanentCreative = true;
|
setPermanentCreative(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getRaw() {
|
public Player getRaw() {
|
||||||
|
@ -76,9 +78,18 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getRegionCreative() {
|
public boolean isRegionCreative() {
|
||||||
return _isRegionCreative;
|
return _isRegionCreative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeGameMode(GameMode gm) throws LackingPermissionException {
|
||||||
|
if (!isRegionCreative() && !getRaw().hasPermission("limitedcreative.switch_gamemode")) {
|
||||||
|
if (gm != GameMode.SURVIVAL || !getRaw().hasPermission("limitedcreative.switch_gamemode.backonly")) {
|
||||||
|
throw new Commands.LackingPermissionException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getRaw().setGameMode(gm);
|
||||||
|
}
|
||||||
public void setRegionCreative(boolean b) {
|
public void setRegionCreative(boolean b) {
|
||||||
if (b) {
|
if (b) {
|
||||||
store.set(player.getName()+".region_creative", true);
|
store.set(player.getName()+".region_creative", true);
|
||||||
|
@ -93,13 +104,21 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
_isRegionCreative = b;
|
_isRegionCreative = b;
|
||||||
}
|
}
|
||||||
|
public boolean isPermanentCreative() {
|
||||||
|
return _isPermanentCreative;
|
||||||
|
}
|
||||||
|
public void setPermanentCreative(boolean b) {
|
||||||
|
_isPermanentCreative = b;
|
||||||
|
if (b)
|
||||||
|
setRegionCreative(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void onSetCreative() {
|
public boolean onSetCreative() {
|
||||||
if (!this.getRegionCreative())
|
if (!this.isRegionCreative())
|
||||||
isPermanentCreative = true;
|
setPermanentCreative(true);
|
||||||
if (plugin.config.getStoreEnabled()) {
|
if (plugin.config.getStoreEnabled()) {
|
||||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||||
return;
|
return true;
|
||||||
Inventory inv = new Inventory(player);
|
Inventory inv = new Inventory(player);
|
||||||
inv.save();
|
inv.save();
|
||||||
if (plugin.config.getStoreCreative() && inv.isStored(GameMode.CREATIVE)) {
|
if (plugin.config.getStoreCreative() && inv.isStored(GameMode.CREATIVE)) {
|
||||||
|
@ -108,13 +127,19 @@ public class LCPlayer {
|
||||||
inv.clear();
|
inv.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public void onSetSurvival() {
|
public boolean onSetSurvival() {
|
||||||
isPermanentCreative = false;
|
if (isRegionCreative()) {
|
||||||
setRegionCreative(false);
|
if (!plugin.config.getRegionOptional()) {
|
||||||
|
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setPermanentCreative(false);
|
||||||
if (plugin.config.getStoreEnabled()) {
|
if (plugin.config.getStoreEnabled()) {
|
||||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||||
return;
|
return true;
|
||||||
Inventory inv = new Inventory(player);
|
Inventory inv = new Inventory(player);
|
||||||
if (plugin.config.getStoreCreative()) {
|
if (plugin.config.getStoreCreative()) {
|
||||||
inv.save();
|
inv.save();
|
||||||
|
@ -122,6 +147,7 @@ public class LCPlayer {
|
||||||
if (inv.isStored(GameMode.SURVIVAL))
|
if (inv.isStored(GameMode.SURVIVAL))
|
||||||
inv.load(GameMode.SURVIVAL);
|
inv.load(GameMode.SURVIVAL);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public void onDropItem(PlayerDropItemEvent event) {
|
public void onDropItem(PlayerDropItemEvent event) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||||
|
@ -201,19 +227,27 @@ public class LCPlayer {
|
||||||
private long lastFloatingTimeWarning = 0;
|
private long lastFloatingTimeWarning = 0;
|
||||||
|
|
||||||
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
|
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
|
||||||
if (rcreative && player.getGameMode() == GameMode.SURVIVAL) {
|
if (rcreative && player.getGameMode() == GameMode.SURVIVAL && !isRegionCreative()) {
|
||||||
setRegionCreative(true); // have to be set, before setGameMode
|
setRegionCreative(true); // have to be set, before setGameMode
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
} else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative) {
|
} else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative()) {
|
||||||
if (getFloatingHeight() > 3) {
|
if (getFloatingHeight() > 3) {
|
||||||
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
|
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
|
||||||
player.sendMessage(L("blocked.survival_flying"));
|
player.sendMessage(L("blocked.survival_flying"));
|
||||||
lastFloatingTimeWarning = System.currentTimeMillis();
|
lastFloatingTimeWarning = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
event.setTo(event.getFrom());
|
|
||||||
|
Location newloc = event.getTo().clone();
|
||||||
|
newloc.setX(event.getFrom().getX());
|
||||||
|
//newloc.setY(event.getFrom().getY());
|
||||||
|
newloc.setZ(event.getFrom().getZ());
|
||||||
|
event.setTo(newloc);
|
||||||
} else {
|
} else {
|
||||||
|
setRegionCreative(false);
|
||||||
player.setGameMode(GameMode.SURVIVAL); // also unsets isRegionCreative;
|
player.setGameMode(GameMode.SURVIVAL); // also unsets isRegionCreative;
|
||||||
}
|
}
|
||||||
|
} else if (!rcreative && isRegionCreative()) {
|
||||||
|
setRegionCreative(false); // we have left, while in optional survival
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
@ -54,9 +55,11 @@ public final class Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||||
if (event.getNewGameMode() == GameMode.CREATIVE) {
|
if (event.getNewGameMode() == GameMode.CREATIVE) {
|
||||||
LCPlayer.get(event.getPlayer()).onSetCreative();
|
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
|
||||||
|
event.setCancelled(true);
|
||||||
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
|
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
|
||||||
LCPlayer.get(event.getPlayer()).onSetSurvival();
|
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +82,18 @@ public final class Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (event.isCancelled() || event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
if (isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
|
||||||
|
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setUseItemInHand(Event.Result.DENY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
|
@ -91,12 +105,28 @@ public final class Listener {
|
||||||
LCPlayer.get(event.getPlayer()).onSignAccess(event);
|
LCPlayer.get(event.getPlayer()).onSignAccess(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
if (event.isCancelled() || event.getPlayer().getGameMode() == GameMode.SURVIVAL)
|
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
|
||||||
|
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
|
|
||||||
if (entity instanceof StorageMinecart) {
|
if (entity instanceof StorageMinecart) {
|
||||||
|
@ -145,8 +175,10 @@ public final class Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
|
if (plugin.config.getLimitEnabled() || plugin.worldguard != null) {
|
||||||
|
pm.registerEvent(Event.Type.ITEM_SPAWN, this, Priority.Normal, plugin);
|
||||||
|
}
|
||||||
if (plugin.config.getLimitEnabled()) {
|
if (plugin.config.getLimitEnabled()) {
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.ITEM_SPAWN, this, Priority.Normal, plugin);
|
|
||||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin);
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin);
|
||||||
pm.registerEvent(Event.Type.ENTITY_DEATH, this, Priority.Low, plugin);
|
pm.registerEvent(Event.Type.ENTITY_DEATH, this, Priority.Low, plugin);
|
||||||
}
|
}
|
||||||
|
@ -159,9 +191,15 @@ public final class Listener {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
// Prevent dropping of doors and beds when destroying the wrong part
|
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.break")) {
|
||||||
|
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
|
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
|
||||||
return;
|
return;
|
||||||
|
// Prevent dropping of doors and beds when destroying the wrong part
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Material mat = block.getType();
|
Material mat = block.getType();
|
||||||
switch (event.getBlock().getType()) {
|
switch (event.getBlock().getType()) {
|
||||||
|
@ -185,9 +223,22 @@ public final class Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
if (event.isCancelled())
|
||||||
|
return;
|
||||||
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
|
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
|
||||||
|
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private void register() {
|
private void register() {
|
||||||
if (plugin.config.getLimitEnabled()) {
|
if (plugin.config.getLimitEnabled()) {
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
|
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
|
||||||
|
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@ import org.bukkit.GameMode;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockDispenseEvent;
|
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
@ -89,9 +89,10 @@ public class WorldGuardIntegration {
|
||||||
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
|
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
|
||||||
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
|
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
|
||||||
|
|
||||||
boolean creative_region = set.allows(CREATIVE);
|
if (player.isRegionCreative() && !set.allows(CREATIVE, player)) {
|
||||||
plugin.logger.info("in creative region: "+Boolean.toString(creative_region)+" - "+event.getBlock().getLocation());
|
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
|
||||||
if (creative_region && player.getRaw().getGameMode() != GameMode.CREATIVE) {
|
event.setCancelled(true);
|
||||||
|
} else if (set.allows(CREATIVE) && player.getRaw().getGameMode() != GameMode.CREATIVE) {
|
||||||
plugin.spawnblock.block(event.getBlock(), player);
|
plugin.spawnblock.block(event.getBlock(), player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,7 @@ public class WorldGuardIntegration {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
LCPlayer player = LCPlayer.get(event.getPlayer());
|
||||||
if (player.getRegionCreative()) {
|
if (player.isRegionCreative()) {
|
||||||
// do not build outside of creative regions, when in the region
|
// do not build outside of creative regions, when in the region
|
||||||
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
|
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
|
||||||
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
|
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
|
||||||
|
@ -113,15 +114,9 @@ public class WorldGuardIntegration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockDispense(BlockDispenseEvent event) {
|
|
||||||
plugin.logger.info("Block dispense: "+event.getBlock().getType()+" - "+event.getItem().getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DISPENSE, this, Priority.Normal, plugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class WGIPlayerListen extends PlayerListener {
|
public class WGIPlayerListen extends PlayerListener {
|
||||||
|
@ -142,8 +137,26 @@ public class WorldGuardIntegration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
|
if (event.isCancelled())
|
||||||
|
return;
|
||||||
|
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|
||||||
|
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
||||||
|
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
|
||||||
|
|
||||||
|
LCPlayer player = LCPlayer.get(event.getPlayer());
|
||||||
|
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
|
||||||
|
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
|
||||||
|
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
|
||||||
|
|
||||||
|
player.setRegionCreativeAllowed(set.allows(CREATIVE, player), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Normal, plugin);
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Normal, plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_TELEPORT, this, Priority.Normal, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ public class Items implements Storeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
|
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
|
||||||
if (!LimitedCreativeCore.serializeFallBack) {
|
if (!LimitedCreativeCore.serializeFallBack && !LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
|
||||||
section.set(path, item);
|
section.set(path, item);
|
||||||
} else { // compatibility fallback
|
} else { // compatibility fallback
|
||||||
Map<String, Object> serialize = item.serialize();
|
Map<String, Object> serialize = item.serialize();
|
||||||
|
@ -63,14 +64,24 @@ public class Items implements Storeable {
|
||||||
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
|
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
|
||||||
if (section.isItemStack(path)) {
|
if (section.isItemStack(path)) {
|
||||||
return section.getItemStack(path);
|
return section.getItemStack(path);
|
||||||
} else { // compatibility fallback
|
} else {
|
||||||
ConfigurationSection s = section.getConfigurationSection(path);
|
ConfigurationSection s = section.getConfigurationSection(path);
|
||||||
Map<String, Object> serialize = s.getValues(false);
|
Map<String, Object> serialize = s.getValues(false);
|
||||||
if (s.contains("enchantments"))
|
serialize.remove("enchantments");
|
||||||
serialize.put("enchantments", s.getConfigurationSection("enchantments").getValues(false));
|
|
||||||
if (s.contains("damage") && LimitedCreativeCore.serializeFallBack)
|
if (s.contains("damage") && LimitedCreativeCore.serializeFallBack)
|
||||||
serialize.put("damage", new Integer(s.getInt("damage")).shortValue());
|
serialize.put("damage", new Integer(s.getInt("damage")).shortValue());
|
||||||
return ItemStack.deserialize(serialize);
|
ItemStack result = ItemStack.deserialize(serialize);
|
||||||
|
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) {
|
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
|
||||||
|
|
|
@ -42,6 +42,8 @@ final public class Util {
|
||||||
|
|
||||||
public static void copyFile(InputStream is, File to) {
|
public static void copyFile(InputStream is, File to) {
|
||||||
try {
|
try {
|
||||||
|
if (to.getParentFile() != null && !to.getParentFile().exists())
|
||||||
|
to.getParentFile().mkdirs();
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
os = new FileOutputStream(to);
|
os = new FileOutputStream(to);
|
||||||
byte[] buffer = new byte[512];
|
byte[] buffer = new byte[512];
|
||||||
|
|
Loading…
Reference in a new issue